Andrey Sitnik, Evil Martians

Privacy-first architecture

Why and how to care about the privacy of your users?

@sitnikcode

“Let’s focus on tech,
  not politics!”

@sitnikcode

Hackers, 1993

Section 1: Software industry and principles

@sitnikcode

Hackers, 1993

Open Source is political

@sitnikcode

The word “free” in [free software] does not refer to price;
it refers to freedom. […]

The freedom to change a program, so that
you can control it instead of it controlling you.

 

 What is the Free Software Foundation? 1986

Cryptography is political

@sitnikcode

The decisions we make about communication security today will determine the kind of society we live in tomorrow

 

 Whitfield Diffied, 1993
co-creator of public key cryptography

Hacking is political

@sitnikcode

Mistrust authority—promote decentralization

 

 Hacker ethic by Steven Levy, 1984

Software development always
has been about principles and politics

@sitnikcode

Always Has Been meme, unknown author

Lack of principles is new

@sitnikcode

1990s

2010s

Hackers, 1993

Silicon Valley, 2014

Section 2: Why I should care?

@sitnikcode

Hackers, 1993

Reason 1: You will live in the world you created

@sitnikcode

“Just because you do not take an interest in politics
doesn’t mean politics won’t take an interest in you.”

 Write code!

Russian meme from anonymous author

@sitnikcode

Reason 2: Principles create meaning for life

Work just for money

Making the revolution for fun

DALL-E and Hackers, 1993

But there are many revolutions to make

@sitnikcode

Adventure Time

Section 3: Why is privacy important?

@sitnikcode

Hackers, 1993

Mistake 1: Is it just for Google for better ads?

@sitnikcode

😃

Mistake 1: Is it just for Google for better ads?

@sitnikcode

FAKE

Blue Coders

Analytics

Data brokers

Fact 1: It is for data brokers for resell

@sitnikcode

🕵️

Ads

Free
Analytics

Data brokers

Shady clients

Case: X-Mode data broker, 2020

@sitnikcode

“Over 100 apps that sold location data
to sketchy data broker X-Mode”

Quran app, Muslim dating app, Craigslist app, an app for following storms, and a level app that can be used to help install shelves

“X‑Mode had supplied location data to U.S. military contractors

@sitnikcode

Mistake 2: This company doesn’t sell data

We respect your privacy

AFP

Mistake 2: This company doesn’t sell data

FAKE

@sitnikcode

Fact 2: If data is stored it can be leaked

@sitnikcode

Case: Yandex Food Delivery data breach, 2022

@sitnikcode

Was leaked all deliveries 2021-2022:


— First & last name

Phone number

— Food delivery address

— Deliver time

Even public easy-to-use map app,
everyone can find your deliveries

@sitnikcode

Mistake 3: My email is not sensitive data

Windows 11 install wizard

@sitnikcode

Fact 3: Big data connects different leaks

Quran app

Muslim

Locations

Social app

Locations

E-mail

Old breach

E-mail

Full name

Google Analytics tracks >52.6% websites

@sitnikcode

a.com

b.com

c.com

d.com

e.com

f.com

g.com

See click

Referer

Only c.com is invisible for GA

Track connected to your Google account

@sitnikcode

Mistake 4: I have nothing to hide

Dolores Umbridge from Harry Potter

If you have nothing to hide

You have nothing to fear

@sitnikcode

Fact 4: Somebody else has something to hide

“… find personal details identifying critics of the Saudi monarchy who had been posting under anonymous Twitter handles”

“[Saudi Prince], who owns
>5% of Twitter

@sitnikcode

Fact 4: and to fear

54-year-old teacher, Mohammad bin Nasser al-Ghamdi, received
a death sentence for tweeting mild criticism of the authorities
to his 10 followers on Twitter.”

@sitnikcode

In the Netherlands too

“After Russia invaded Ukraine in February 2022, authorities began using facial recognition to prevent people from protesting in the first place”

VisionLabs’ algorithm has been used in Moscow’s facial recognition system”

VisionLabs Global HQ: Johan Cruijff Boulevard 65, Amsterdam

@sitnikcode

And against EU citizens too

Proton Mail Discloses User Data
Leading to Arrest in Spain

The requests were made under the guise of anti-terrorism laws,
despite the primary activities of the
Democratic Tsunami
[Catalan independence organization]

involving protests and roadblocks

EP

What can we do?

The web became an awful place

@sitnikcode

The New York Times

Isn’t this a frontend conference?

@sitnikcode

We made the web an awful place

@sitnikcode

The New York Times

Step 1: Remove GDPR popup

@sitnikcode

Hackers, 1993

But we need popups for GDPR, right?

@sitnikcode

Fireplugins

There is no “popup” in GDPR law

@sitnikcode

Why we added GDPR popups

@sitnikcode

Punish them with popups until they agree to give us personal data

Don’t

Track

Users

Don’t

Track

Users

Don’t track users

Friends s10, e13

Consent popup is just dark design pattern

@sitnikcode

😈  Popup blocks content
 

😈  UI is unclear
 

😈  The biggest button is Allow

Yes

Yes, but on red

We care about your privacy. Can we spy on you?

The real “We care about privacy” way

@sitnikcode

😻  GDPR compatible analytics
 

😻  No popup


😻  You ask users when you need data
        (for instance, in Sign Up form)

Analytics without popup

@sitnikcode

✅  Page view, browsers, countries
✅  Traffic sources
✅  Track website events
✅  Track campaigns from click to conversion (?utm)
⛔  Can’t connect events with session/user ID
⛔  Can’t collect social network ID for ads (Remarketing)

Plausible

There are many Cookieless Tracking tools

@sitnikcode

But marketing manager is demanding GA

@sitnikcode

DALL-E

You can’t trust data only from opt-in users

@sitnikcode

All users

Your data

Yes on GDPR popup

No on GDPR popup

32—64% of users press Yes
on GDPR banners, Statista

Popup only for EU is not an option

@sitnikcode

GDPR-like laws:

🇧🇷 Brazil: Lei Geral de Proteçao de Dados
🇨🇦 Canada: Digital Charter Implementation Act
🇨🇱 Chile: Ley 19,628
🇪🇬 Egypt: Law No. 151
🇮🇳 India: Personal Data Protection Bill
🇿🇦 South Africa: Protection of Personal Information Act
🇺🇸 USA, CA: California Consumer Privacy Act

It is time to change the industry

@sitnikcode

Hackers, 1993

Remember how we killed IE together

@sitnikcode

Ex-YouTube developer reveals how they ‘conspired to kill IE6’

Step 2: Reduce privacy data processors

@sitnikcode

Hackers, 1993

Not only you have access to private data

@sitnikcode

We Care About Your Privacy

We and our 618 partners store and/or access information on a device, such as unique IDs in cookies to process personal data. You may accept or manage your choices by clicking below or at any time in the privacy policy page. These choices will be signaled to our partners and will not affect browsing data.

Less services = less risks

@sitnikcode

🧐

Hosting

🧐

CDN

🧐

Ads

🤤

Public JS CDN

🥸

JS script from CDN

🧐

Third-party database

→ Leak

→ Sell data

How to reduce number of services?

@sitnikcode

✅  No public CDN for libs (also better performance)

✅  No public CDN for fonts (also better performance)

✅  Self-hosted tools (like analytics)

✅  Combine CDN and cloud

Step 3: Local-First

@sitnikcode

Hackers, 1993

Advanced

Advanced step: only for new projects

@sitnikcode

Hackers, 1993

@sitnikcode

Software before

Local-Only

Svg Vector Icons : http://www.onlinewebfonts.com/icon

Then iPhone was released

@sitnikcode

Apple

@sitnikcode

And now everything is in the cloud

Server-First

Svg Vector Icons : http://www.onlinewebfonts.com/icon

Local-Only

Svg Vector Icons : http://www.onlinewebfonts.com/icon

@sitnikcode

Server-First

Svg Vector Icons : http://www.onlinewebfonts.com/icon

Local-Only

Local-First

Svg Vector Icons : http://www.onlinewebfonts.com/icon
Svg Vector Icons : http://www.onlinewebfonts.com/icon

Local-First as a third way

Rich client keeps data and processing locally,
the server is just for sync

Svg Vector Icons : http://www.onlinewebfonts.com/icon

The idea was presented by Ink & Switch

@sitnikcode

Seven ideas:

  1. No spinners (local data fast to change)
  2. Sync between devices
  3. Offline-first
  4. Conflict-free collaboration
  5. App will work when company closes
  6. Privacy by default
  7. User owns data

Notion vs Obsidian

@sitnikcode

Notion
Server-First

Obsidian
Local-First

🗒️

Local files
notes/Shopping.md
notes/Ideas.md

Obsidian Sync & Publish

💻

📱

💻

🗒️

📱

🗒️

GitHub repo

Any Cloud Sync

Local-First isn’t on-off switch, but a spectrum

@sitnikcode

Partial DB replica
on the client

P2P
End-to-end encryption
No server

Step 1: Storage

@sitnikcode

All client’s data stores locally

More data on the client (20-500 MB)

We need proper client-side database:

— Good performance

— Rich query language

Client-side databases

@sitnikcode

SQLite WASM

PGlite (PostgreSQL in WASM)

Under Construction

import { SQLocal } from 'sqlocal'

const { sql } = new SQLocal('database.sqlite3')
const data = await sql`SELECT * FROM posts`
import { PGlite } from "@electric-sql/pglite"

const db = new PGlite()
await db.query("select * from posts;")

Persistence DB storage for SQLite

@sitnikcode

  1. OPFS (Origin Private File System)
  2. IndexedDB

Firefox uses SQLite for
IndexedDB & OPFS metadata

Why not IndexedDB?

@sitnikcode

  1. SQLite works on ReactNative and desktop
  2. IndexedDB query API is limited
  3. Performance

Step 2: Add log and separate read and write

@sitnikcode

Log

SQLite

Reactive store

Updates

Initialization

UI

We need to sync server and browser tabs

@sitnikcode

Log

SQLite

Step 3: 2 passwords for end-to-end encryption

@sitnikcode

1st password to auth on the server

2nd password for end-to-end encryption

Unexpected benefits of Local-First

Benefit 1: Very simple server

@sitnikcode

Sync changes
Auth
Check access for collaboration

All business logic

All data management

Benefit 2: No server in prototype stage

@sitnikcode

project/
  client/

Benefit 3: Cheap scale

@sitnikcode

Server-first:

Local-first:

Benefit 4: No private data → no problem

@sitnikcode

DALL-E

Benefit 5: Developer productivity

@sitnikcode

useEffect(() => {
  setLoading(true)
  fetch('/posts')
    .then(response => response.json())
    .then(data => {
      setData(data)
      setLoading(false)
    })
    .catch(e => {
      setError(true)
      setLoading(false)
    })
}, [])

if (loading) return <div>Loading…</div>
if (error) return <div>Error</div>

<ul>
  {data.map(post => <li>{post.title}</li>)}
</ul>
const data = use(posts)
<ul>
  {data.map(post => <li>{post.title}</li>)}
</ul>

State management
Networking code

Cache

Network errors

Optimistic UI

Sync Engine

Benefit 6: Local data = 0 latency

@sitnikcode

There are frameworks for LoFi

@sitnikcode

Evolu

ElectricSQL

RxDB

Hard part 1: Frameworks are not 100% ready

@sitnikcode

While none of these projects currently claim “production level stability” for persistence, the current support could already
be sufficient for some projects

 

 The Current State of SQLite Persistence on the Web

Hard part 2: Client’s database migrations

@sitnikcode

const migrations = {
  1: action => {
    if (action.type === 'posts/created') {
      return { type: 'news/created', news: action.post }
    }
  }
}

Hard part 3: E2EE password recovery

@sitnikcode

With great privacy comes great responsibility

Spider-Man

Again: Local-First is a spectrum

@sitnikcode

Partial DB replica
on the client

P2P
End-to-end encryption
No server

Local-First Startups: Linear

@sitnikcode

With great privacy comes great responsibility

Linear website

Local-First Startups: Linear

@sitnikcode

With great privacy comes great responsibility

Why does Linear feel so fast?
Local first optimistic updates

 

 Jori Lallo at devtools.fm

Local-First Startups: Pitch

@sitnikcode

Pitch.com

1.7 million teams
using app

Local-First Startups: Goodnotes

@sitnikcode

goodnotes.com

>24 million
monthly users

Step 4: Privacy from non-US perspective

@sitnikcode

Hackers, 1993

Advanced

Advanced step: for big & popular projects

@sitnikcode

Hackers, 1993

Different privacy risks

@sitnikcode

🕵️  Government’s Secret Service
🪤  Surveillance for regime critics
📶  Internet provider
☁️  Data brokers
🏬  International companies collecting data
👮  Phone check by the local police officer
⛪  Local community with ethical standards
👪  Family members

US media focus mostly on

@sitnikcode

🕵️  Government’s Secret Service
      Surveillance for regime critics
      Internet provider
☁️  Data brokers
🏬  International companies collecting data
      Phone check by the local police officer
      Local community with ethical standards
      Family members

WhiteEmperor420 on Reddit

Different risks need opposite solutions

@sitnikcode

RSS Reader privacy risks

🇺🇸 US: local-first
don’t trust cloud

🇷🇺 Russia: US cloud proxy
to hide you from Internet provider

🤫

🏯

🏥

🕌

☁️

🤫

🏯

🏥

🕌

☁️

🔒

🕵️

📶

🕵️

🔓

Chat check by local police check in 🇷🇺 🇧🇾

@sitnikcode

“Unlock your phone and show Telegram”

Andrey Lukovsky

“I have rights”

1234

🧑‍⚖️

🧑‍🦽

Navalny

Following

Telegram fork by Belarusian Cyber-Partisans

@sitnikcode

1234

Navalny

Following

1984

You can have 2 PINs

CSS hacks

GitHub trends

Following

CSS hacks

GitHub trends

Summary

@sitnikcode

Hackers, 1993

For next working day

@sitnikcode

❤️  Find your principles
❤️  Remove GDPR popup by using cookieless analytics
❤️  Reduce services with access to private data
🌟  Think of Local-First in next project
🤔  Think of other privacy risks if you make a social tool

Thanks

Privacy-first architecture (Short)

By Andrey Sitnik

Privacy-first architecture (Short)

  • 1,817