From 4fcc1cd5ed4a6ab866bb4a2d58a75811f421a981 Mon Sep 17 00:00:00 2001 From: victorcavero14 Date: Tue, 28 Jul 2026 09:56:49 +0200 Subject: [PATCH] fix(analytics): make product analytics opt-in and host-scoped The OpenPanel endpoint and client id were hardcoded in dashboard/index.html, so every clone, fork and self-hosted deployment inherited them and reported into the hosted instance's dashboard. src/lib/analytics.js already documents the intended behaviour ('analytics can never leak into the open-source experience'); this makes that true. - apiUrl and clientId now come from VITE_OPENPANEL_API_URL / VITE_OPENPANEL_CLIENT_ID, substituted by Vite at build time and unset by default, so npm run dev and a plain npm run build initialise nothing. - The third-party script is only fetched once analytics is actually enabled: a default build makes no external analytics request at all. - Reporting is additionally gated on a hostname allowlist, so a dist/ built with credentials stays inert if it is served anywhere else. Verified with a headless browser against real production builds: credentials + non-allowlisted host -> no requests credentials + allowlisted host -> initialises and reports no credentials + allowlisted host -> no requests Co-Authored-By: Claude Opus 5 --- .env.example | 7 +++++++ CLAUDE.md | 1 + dashboard/Dockerfile | 6 ++++++ dashboard/index.html | 47 ++++++++++++++++++++++++++++++++++---------- 4 files changed, 51 insertions(+), 10 deletions(-) diff --git a/.env.example b/.env.example index c3fe4e3..71506fd 100644 --- a/.env.example +++ b/.env.example @@ -41,3 +41,10 @@ AWS_S3_PUBLIC_BUCKET=your-public-bucket-name # Video encoder for all ffmpeg encodes: x264 (default) | nvenc | auto. # auto probes h264_nvenc once at startup and falls back to x264 if unusable. # FFMPEG_ENCODER=x264 + +# Product analytics (optional, off by default). Both are read by the dashboard +# at BUILD time. Leave them unset and the frontend initialises no analytics and +# loads no third-party script. Set them to your own OpenPanel instance — and add +# your hostname to ANALYTICS_HOSTS in dashboard/index.html — to collect your own. +# VITE_OPENPANEL_API_URL=https://api.openpanel.example.com +# VITE_OPENPANEL_CLIENT_ID=your_openpanel_client_id diff --git a/CLAUDE.md b/CLAUDE.md index 3b9abcc..32bb05f 100644 --- a/CLAUDE.md +++ b/CLAUDE.md @@ -112,6 +112,7 @@ Async job queue with semaphore-based concurrency control. Configure via `MAX_CON - `AWS_ACCESS_KEY_ID`, `AWS_SECRET_ACCESS_KEY`, `AWS_REGION`, `AWS_S3_BUCKET` - For S3 backup - `MAX_CONCURRENT_JOBS` - Concurrent processing limit (default: 5) - `VITE_API_URL` - Production API URL override +- `VITE_OPENPANEL_API_URL`, `VITE_OPENPANEL_CLIENT_ID` - Optional product analytics, read at **build** time. Unset (the default, including every self-hosted build) means no analytics is initialised and no third-party script is loaded. `dashboard/index.html` also gates reporting on an `ANALYTICS_HOSTS` allowlist, so a build carrying credentials stays inert on any other host. **Client-side (localStorage, encrypted):** - `GEMINI_API_KEY` - Google Gemini API key (required) diff --git a/dashboard/Dockerfile b/dashboard/Dockerfile index 123e6ec..2f683a0 100644 --- a/dashboard/Dockerfile +++ b/dashboard/Dockerfile @@ -21,6 +21,12 @@ COPY . . # (Coolify: add it as a build variable on the frontend service). Empty = same-origin. ARG VITE_API_URL="" ENV VITE_API_URL=$VITE_API_URL +# Optional product analytics (OpenPanel). Left empty, index.html initialises +# nothing and the build phones home to nobody — see the comment there. +ARG VITE_OPENPANEL_API_URL="" +ENV VITE_OPENPANEL_API_URL=$VITE_OPENPANEL_API_URL +ARG VITE_OPENPANEL_CLIENT_ID="" +ENV VITE_OPENPANEL_CLIENT_ID=$VITE_OPENPANEL_CLIENT_ID RUN npm run build # ---- static serving (nginx) ---- diff --git a/dashboard/index.html b/dashboard/index.html index 1b84083..2bcd6b7 100644 --- a/dashboard/index.html +++ b/dashboard/index.html @@ -250,19 +250,46 @@ } - - + -