
Development
How Instagram, Facebook, and X Keep Your Photos and Videos Safe (And How Any App Should Do It)
Every time you tap “post” on a photo or video, a surprising amount of machinery kicks into gear before that file ever reaches someone else’s screen. Most people never see it — but for anyone building a social app, it’s the single most important piece of engineering in the whole product. Get it wrong, and you’re not just shipping a buggy feature. You’re exposing users to malware, leaking their exact home address through a photo’s metadata, or — in the worst case — becoming an unwitting distribution channel for illegal content.
This post breaks down exactly how large platforms secure media uploads, what a smaller app should copy, and what Indian law specifically requires you to do.

Why Media Uploads Are the Riskiest Part of Any Social App
A photo or video isn’t just “data” — it’s a file with:
- Hidden metadata. Most phone cameras embed exact GPS coordinates, device model, and timestamp inside the file (EXIF data). Posting a photo without stripping this can silently reveal a user’s home, workplace, or daily routine.
- Executable risk. A file with a
.jpgextension isn’t guaranteed to be a JPEG. Malformed or disguised files can be used to attack image-processing libraries, storage servers, or other users who download them. - Legal exposure. Photos and videos are the primary vector for the content categories every country restricts: child sexual abuse material (CSAM), non-consensual intimate imagery, graphic violence, and content that infringes someone else’s copyright or privacy.
- Scale problems. A single popular post can be viewed thousands of times a minute. Serving media directly from your application server (instead of a CDN) turns a viral post into a denial-of-service event.
Because of this, no serious platform treats “upload a file” as a simple POST request handled synchronously by the app server. It’s a multi-stage pipeline.
How the Big Platforms Actually Do It
1. The app server never touches the raw file
Instagram, Facebook, and X all use direct-to-storage uploads. The client asks the backend for a short-lived, pre-signed upload URL (S3, GCS, or Cloudflare R2), and the file goes straight from the user’s device into object storage. The application server only ever handles metadata (file name, size, content type) — never the bytes themselves. This keeps your API servers from becoming a bottleneck and reduces the attack surface dramatically.
2. Nothing is public immediately
The freshly uploaded file lands in a private, quarantined bucket. It is not linked to any public feed, profile, or CDN URL yet. It only becomes visible after it clears the pipeline below.
3. Automated content and safety scanning
Before anything is shown to another user, platforms run the file through several automated checks, generally in this order:

Anything that’s clearly clean gets auto-approved. Anything the models are unsure about — not clearly safe, not clearly a violation — goes to a human moderation queue rather than being published or silently deleted.
4. Re-encoding, not pass-through
Platforms rarely serve the exact file the user uploaded. They re-encode it into standard formats and resolutions. This strips leftover metadata, normalizes the format (defeating disguised files), and lets them serve multiple sizes efficiently through a CDN.
5. Delivery through signed, expiring URLs — not permanent public links
Even “public” content is usually served via CDN URLs with short-lived signed tokens, so content that’s later taken down actually disappears, rather than continuing to be accessible to anyone who saved the old link.
6. Full audit trail
Every stage — upload, scan result, moderation decision, takedown — is logged. This isn’t optional polish; as you’ll see below, it’s a legal requirement in India (and most other jurisdictions), because regulators and courts can require you to produce this trail on demand.
A Secure Implementation Blueprint
If you’re building this yourself, here’s the concrete shape of it:
1. Upload flow
- Client requests a pre-signed, single-use, short-expiry upload URL from your backend (never a static credential).
- Enforce file size limits and allowed MIME types server-side, not just in the client.
- Validate file type using magic-byte / content sniffing — never trust the file extension or the
Content-Typeheader the client sends. - Rate-limit upload requests per user to prevent abuse (a common target for the
ThrottlerModule-style rate limiter in any Node.js backend).
2. Storage
- Upload lands in a private bucket/prefix, not directly reachable by URL.
- Enable server-side encryption at rest and TLS in transit (non-negotiable, and explicitly required under India’s data protection rules — more below).
3. Async processing pipeline (triggered by a storage event, e.g. S3 ObjectCreated)
- Malware/integrity scan.
- Strip EXIF/GPS metadata unconditionally, even for approved content.
- Perceptual-hash check against CSAM hash-sharing databases. This is a hard legal requirement for platforms above a certain user threshold in India, not just best practice (see below).
- ML moderation classifier for nudity, violence, and other policy categories, with a confidence threshold that routes uncertain cases to human review instead of auto-publishing or auto-deleting.
- Re-encode to your standard delivery formats/resolutions.
4. Publish
- Only after the pipeline clears does the media get attached to a public-facing record and pushed to the CDN.
- Serve through signed, time-limited URLs, especially for anything in a private profile, direct message, or age-gated content.
5. Takedown & retention
- When content is removed (by moderation or user request), delete the object but retain the hash, metadata, and removal reason for a defined retention window — this maps directly to a specific Indian regulatory obligation (below), not just “good practice.”
6. Observability
- Log every transition (uploaded → scanned → approved/flagged → published/removed) with timestamps and actor (system or moderator ID). This log is what you hand over during a legal inquiry or compliance audit.
The Indian Legal Framework You’re Actually Building Against
This is the part most tutorials skip, and it’s the part that matters most if you’re operating in India. Three separate legal regimes apply to media uploads on a social platform:
1. The constitutional backdrop
The Supreme Court’s 2017 ruling in Justice K.S. Puttaswamy v. Union of India established privacy as a fundamental right under Article 21 of the Constitution. This is the underlying reason metadata stripping, consent, and data minimization aren’t just nice-to-haves — they’re constitutionally grounded expectations, not merely product decisions. At the same time, content moderation of unlawful material (obscenity, content threatening public order) is a reasonable restriction on free speech permitted under Article 19(2), which is what gives platforms — and the government — legal footing to require takedowns.
2. The Information Technology Act, 2000
Several sections directly govern what you must detect and remove:
- Section 66E — punishes capturing or publishing images that violate someone’s privacy (e.g., without consent, in a private setting).
- Section 67 / 67A — criminalizes publishing or transmitting obscene material, and sexually explicit material, in electronic form.
- Sections 69 / 69A — empower the government to direct interception, monitoring, or blocking of content/information in the interest of sovereignty, security, or public order. Platforms must be able to comply with such orders.
3. The IT Rules, 2021 (Intermediary Guidelines and Digital Media Ethics Code)
This is the operational rulebook, and it maps almost one-to-one onto the pipeline described above:
- Rule 3 — general due diligence: publish clear terms of service, respond to takedown requests, and act on court/government orders within defined timelines.
- Rule 4(4) — platforms crossing the “significant social media intermediary” threshold (5 million+ registered Indian users) must deploy automated tools to proactively identify CSAM and previously-removed identical content, and display a notice when access to such content is disabled.
- Content retention — hash, metadata, and removal reason for taken-down content must be retained (commonly cited as a 180-day window) for law-enforcement purposes; the underlying content itself should not be retained beyond what’s necessary, and for CSAM specifically, platforms are expected to retain only the hash, not the file.
- Grievance mechanism — a resident Grievance Officer and a defined complaint-resolution timeline are mandatory once you cross the significant-intermediary threshold; smaller apps should still build a grievance/report-content flow from day one, since retrofitting it later is expensive.
If you’re below the 5-million-user threshold, the automated-CSAM-detection and resident-officer obligations don’t legally bind you yet — but building the scanning pipeline early is far cheaper than bolting it on after a legal notice.
4. POCSO Act, 2012
Separately from the IT Rules, the Protection of Children from Sexual Offences Act creates a mandatory reporting obligation: anyone (including a platform) who becomes aware of CSAM is legally required to report it, not just remove it quietly. Your moderation workflow needs an explicit escalation path to law enforcement for this category — auto-deletion alone doesn’t discharge the legal duty.
5. The Digital Personal Data Protection Act, 2023 and DPDP Rules, 2025
India’s dedicated data-protection law is now in force. The Act (with its implementing DPDP Rules, notified in November 2025) is being rolled out in phases through 2027, but its core obligations already apply to how you handle the personal data embedded in and around media uploads:
- Purpose limitation & data minimization — don’t collect or retain more than the upload flow needs (a direct argument for stripping EXIF/GPS data rather than “just in case” retention).
- Consent — location tagging, face-tagging, or any secondary use of uploaded media needs a clear, specific consent flow, not a buried clause in a terms-of-service document.
- Security safeguards — encryption, access control, and logging are explicitly expected security measures under the Act’s rules, matching the “storage + audit trail” parts of the pipeline above.
- Breach notification — a personal data breach (e.g., a leaked private-media bucket) must be reported to the Data Protection Board of India and to affected users without undue delay.
- Children’s data — verifiable parental consent requirements apply if your app allows users under 18, which affects sign-up flows and any location or media-sharing feature aimed at minors.
6. CERT-In directions
Separately from DPDP, India’s computer emergency response team (CERT-In) requires certain categories of cybersecurity incidents — including breaches of user data — to be reported within a fixed window of becoming aware of them. This is an operational SLA your incident-response plan needs to be built around, independent of the DPDP breach-notification duty.
Compliance Checklist

The Takeaway
Secure media handling isn’t a single “add a virus scanner” checkbox — it’s a pipeline: don’t trust the client, don’t publish anything until it’s been scanned, strip what you don’t need, encrypt what you keep, and log everything you do. The technical architecture and the legal obligations turn out to be almost the same list, which is a good sign — it means building this properly the first time isn’t wasted engineering effort layered on top of compliance. It is the compliance.
This post is a general engineering and policy overview and is not legal advice. If you’re building a platform that will operate in India, involve counsel familiar with the IT Rules, DPDP Act, and POCSO before finalizing your moderation and data-retention policies.

