Skip to content

Every analytics tool wants a subscription. And your data. I built Twiligent instead. YouTube stats. Instagram stats. One dashboard. Runs locally on your machine.

fix(security): stop other sites from framing the app and the site

spacesdriveba643a33fddf
diff --git a/docs/architecture/cloudflare/PAGES.md b/docs/architecture/cloudflare/PAGES.md
index 3e8c1f0..a2dc6fc 100644
--- a/docs/architecture/cloudflare/PAGES.md
+++ b/docs/architecture/cloudflare/PAGES.md
@@ -41,6 +41,20 @@ frontend/public/_redirects
If this file is missing, direct URL navigation (e.g., visiting `/settings`) will return a 404.
+## Response Headers
+
+`frontend/public/_headers` and `site/public/_headers` give every page of the app and the site the same headers, which Pages reads from the build output:
+
+| Header | Value | Why |
+|---|---|---|
+| `X-Frame-Options` | `DENY` | No other site may frame the pages, so a hidden frame cannot trick a person into clicking (clickjacking) |
+| `Content-Security-Policy` | `frame-ancestors 'none'` | The same rule for browsers that read CSP; nothing else is restricted, so scripts, fonts and images load as before |
+| `X-Content-Type-Options` | `nosniff` | Browsers use the declared content type instead of guessing |
+| `Referrer-Policy` | `strict-origin-when-cross-origin` | Other sites see only the origin, never a page address |
+| `Permissions-Policy` | `camera=(), microphone=(), geolocation=()` | Neither app uses these, so no embedded script may ask for them |
+
+The Worker sets its own stricter headers on API responses (`backend/middleware/securityHeaders.ts`).
+
## Environment Variables
The frontend accesses environment variables at **build time** via Vite's `VITE_` prefix convention:
diff --git a/docs/architecture/site/SITE.md b/docs/architecture/site/SITE.md
index 544b319..3a07597 100644
--- a/docs/architecture/site/SITE.md
+++ b/docs/architecture/site/SITE.md
@@ -198,7 +198,7 @@ The product previews are React components drawn with the site's tokens, never sc
| Secrets | None in the build; the workflow needs only `CLOUDFLARE_API_TOKEN` and `CLOUDFLARE_ACCOUNT_ID` |
| Workflow | `.github/workflows/deploy-site.yml`, on pushes to `main` that touch `site/**`, `tsconfig.base.json`, the root `package.json` or `package-lock.json`, or the workflow itself |
-`site/public/_redirects` sends the app's old paths on this domain (`/login`, `/accounts`, `/settings`, `/videos`, `/shorts`, `/tracked-content`, `/channel/*`, `/instagram/*` and others) to the same path on `https://app.twiligent.ujjwal.fyi` with a 301; `/upload` and `/publish` go to the app's `/publish`, and `/reels` and `/instagram` to its `/instagram`. The old pages of the platform removed in v2.0.0 (ADR-049) go to the app's Overview, and its old tracked posts path to Tracked content. It also rewrites `/docs` and `/docs/*` to `/` with a 200 (see Routing). In the other direction, the app's `/docs/*` route sends old docs links to the same page here. See `docs/architecture/cloudflare/PAGES.md`, `docs/architecture/cloudflare/CI_CD.md` and `docs/workflows/DEPLOYMENT.md`.
+`site/public/_redirects` sends the app's old paths on this domain (`/login`, `/accounts`, `/settings`, `/videos`, `/shorts`, `/tracked-content`, `/channel/*`, `/instagram/*` and others) to the same path on `https://app.twiligent.ujjwal.fyi` with a 301; `/upload` and `/publish` go to the app's `/publish`, and `/reels` and `/instagram` to its `/instagram`. The old pages of the platform removed in v2.0.0 (ADR-049) go to the app's Overview, and its old tracked posts path to Tracked content. It also rewrites `/docs` and `/docs/*` to `/` with a 200 (see Routing). In the other direction, the app's `/docs/*` route sends old docs links to the same page here. `site/public/_headers` stops other sites from framing the pages and sets the other response headers listed in `PAGES.md` (Response Headers). See `docs/architecture/cloudflare/PAGES.md`, `docs/architecture/cloudflare/CI_CD.md` and `docs/workflows/DEPLOYMENT.md`.
## TypeScript and Lint
diff --git a/frontend/public/_headers b/frontend/public/_headers
new file mode 100644
index 0000000..c3f80fa
--- /dev/null
+++ b/frontend/public/_headers
@@ -0,0 +1,8 @@
+# Cloudflare Pages response headers: no other site may frame these pages (clickjacking), and browsers must not
+# guess content types or send full addresses to other sites
+/*
+ X-Frame-Options: DENY
+ Content-Security-Policy: frame-ancestors 'none'
+ X-Content-Type-Options: nosniff
+ Referrer-Policy: strict-origin-when-cross-origin
+ Permissions-Policy: camera=(), microphone=(), geolocation=()
diff --git a/site/public/_headers b/site/public/_headers
new file mode 100644
index 0000000..c3f80fa
--- /dev/null
+++ b/site/public/_headers
@@ -0,0 +1,8 @@
+# Cloudflare Pages response headers: no other site may frame these pages (clickjacking), and browsers must not
+# guess content types or send full addresses to other sites
+/*
+ X-Frame-Options: DENY
+ Content-Security-Policy: frame-ancestors 'none'
+ X-Content-Type-Options: nosniff
+ Referrer-Policy: strict-origin-when-cross-origin
+ Permissions-Policy: camera=(), microphone=(), geolocation=()