Skip to content

security(fix): PR-audit remediations — GHA input hardening, analytics URL guard, GPC/DNT opt-out, CodeRabbit coverage - #352

Merged
Ducksss merged 2 commits into
devfrom
claude/pr-audit-fixes
Jul 27, 2026
Merged

Ducksss merged 2 commits into
devfrom
claude/pr-audit-fixes

Conversation

@Ducksss

@Ducksss Ducksss commented Jul 27, 2026

Copy link
Copy Markdown
Owner

Remediations from a full-backlog PR lifecycle audit (263 PRs triaged, 33 deep-verified against the live tree).

Why this matters most

Only 14 of 263 PRs ever received a substantive AI review. CodeRabbit auto-reviews the default branch only, and almost all work lands on dev, so dev-targeted PRs were skipped with a notice that reads like a finished review. .coderabbit.yaml now lists dev as a base branch.

Changes

  • GHA script injection — visual-baselines.yml spliced the spec dispatch input directly into three run: blocks on a job holding contents: write + pull-requests: write. Now passed via env:. Left unquoted at the call site on purpose: the filter may legitimately name several specs ("components-visual frontend").
  • Crash bug — trackPrimaryLinkClick parsed href with an unguarded new URL() inside a document-wide click listener. // and http:// throw, dropping the event and logging an uncaught error. Guarded.
  • Privacy signals — every event this repo emits is now skipped for visitors sending Global Privacy Control (binding under CCPA) or Do Not Track, and no pc_distinct_id is minted for them. The PostHog gate sits after the __posthogEvents push so the e2e harness still records intent.
  • Non-production capture — isAnalyticsHost() accepted localhost/127.0.0.1, so a maintainer running pnpm dev with a real key wrote synthetic traffic into the production dataset and leaked unreleased route paths. Production hostnames only.
  • Docs — the analytics contract described only PostHog while GA4 and Vercel also mount. Now documented.

Deliberately out of scope

This is not a full consent gate. The GA4 script still loads on first paint, so its own automatic collection and cookies are unaffected. The docs say so explicitly rather than implying the opt-out covers everything. Closing that gap means deferring third-party mounts until opt-in plus a privacy page — it re-baselines landing visual snapshots and must clear the axe gate, so it deserves its own scoped change.

Verification

lint clean · tsc exit 0 · 341 int tests passing · opt-out semantics unit-checked (doNotTrack: "0" and "unspecified" correctly do not opt out; Playwright's default state is unaffected, so existing e2e assertions hold).

Copilot AI review requested due to automatic review settings July 27, 2026 06:12

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

@vercel

vercel Bot commented Jul 27, 2026 •

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
payload-components Ready Ready Preview, Comment Jul 27, 2026 7:27am
payload-components-97bf Ready Ready Preview, Comment Jul 27, 2026 7:27am

@coderabbitai

coderabbitai Bot commented Jul 27, 2026 •

Copy link
Copy Markdown

Important

Review skipped

Auto reviews are disabled on base/target branches other than the default branch.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro Plus

Run ID: 49362a80-ddee-4003-af63-853824861137

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • 🔍 Trigger review
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch claude/pr-audit-fixes

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

Ducksss and others added 2 commits July 27, 2026 14:12
… parse

Findings from a full-backlog PR lifecycle audit (263 PRs triaged, 33
deep-verified against the live tree).

- visual-baselines.yml interpolated the `spec` workflow_dispatch input
  directly into three `run:` blocks on a job holding contents: write and
  pull-requests: write, so the input was spliced in as shell code before
  parsing. Pass it through `env:` instead, leaving the call site unquoted
  because the filter may legitimately name several specs
  (e.g. "components-visual frontend").

- trackPrimaryLinkClick parsed href with an unguarded `new URL()` inside a
  document-wide click listener. Hrefs such as "//" or "http://" throw, which
  dropped the event and logged an uncaught error on every such click. The
  file already wraps all three transport calls under "analytics must never
  block the user action"; this parse was the one unprotected step.

- The anonymous analytics contract described only the PostHog signals while
  AnalyticsShell also mounts GA4 (own cookies, own auto-pageviews) and Vercel
  Analytics. Document the full stack, and note that the contract spec pins
  PostHog payloads only and cannot catch an undisclosed provider.

Verified on the dev base: lint clean, tsc clean, 341 int tests passing.

Co-Authored-By: Claude Opus 5 <[email protected]>
…e CodeRabbit coverage

Follow-ups from the full-backlog PR audit.

Restore review coverage. CodeRabbit only auto-reviews the default branch, and
almost all work here lands on `dev`, so dev-targeted PRs were skipped with a
notice that reads like a finished review. Across 263 PRs only 14 ever received a
substantive AI review. Add .coderabbit.yaml listing `dev` as a base branch.

Honour explicit privacy signals. Every event this repo emits is now skipped when
the browser sends Global Privacy Control (legally binding under the CCPA) or Do
Not Track, and no pc_distinct_id is minted or stored for those visitors. The
PostHog gate is folded in after the __posthogEvents push so the e2e harness still
records intent; Playwright sets neither signal, so existing assertions are
unaffected.

Stop sending from non-production hosts. isAnalyticsHost() accepted localhost and
127.0.0.1, so a maintainer running `pnpm dev` with a real key wrote synthetic
traffic into the production dataset and leaked unreleased route paths to a third
party. Production hostnames only.

This is deliberately not a full consent gate: the GA4 script still loads on first
paint, so its own automatic collection and cookies are unchanged. The docs now
say so explicitly rather than implying the opt-out covers everything.

Verified: lint clean, tsc clean, 341 int tests passing.

Co-Authored-By: Claude Opus 5 <[email protected]>
@Ducksss
Ducksss force-pushed the claude/pr-audit-fixes branch from 792fb66 to 9a2b335 Compare July 27, 2026 07:14
@Ducksss
Ducksss merged commit 49738d7 into dev Jul 27, 2026
11 of 12 checks passed
@Ducksss
Ducksss deleted the claude/pr-audit-fixes branch July 27, 2026 07:27
Ducksss added a commit that referenced this pull request Jul 27, 2026
Closes the gap the PR audit left open: GA4, Vercel Analytics/Speed Insights and
PostHog all loaded on first paint, so an EU visitor had GA4 cookies set before
any interaction. Honouring GPC/DNT (shipped in #352) narrowed that but could not
close it, because GA4 was mounted regardless.

AnalyticsShell now renders nothing until consent is 'granted'. On a first visit
there is no GA4 script, no Vercel bundle, no PostHog beacon and no stored
identifier. State lives in src/lib/consent.ts under `pc_consent`; ConsentBanner
collects the choice and /privacy documents the stack and can withdraw it.

Three things worth calling out:

- A browser privacy signal is a decision, not a prompt. GPC (binding under the
  CCPA) or DNT resolves to 'denied' and the banner never renders.
- Withdrawal reloads. Unmounting AnalyticsShell does not unload a third party
  that is already running — gtag stays initialised on window and keeps
  collecting — so setConsent reloads on granted -> denied. It also clears
  pc_distinct_id, so opting out erases the identifier instead of freezing it.
  This was caught by the e2e spec, not by review.
- The banner is fixed-positioned, so it costs no layout shift on the landing
  page's LCP content.

Testing: specs that assert on analytics or capture visual baselines grant consent
up-front via tests/e2e/consent.ts, which keeps the banner out of every snapshot —
only the two landing baselines changed, and only because /privacy was added to
the footer. The axe suites deliberately run without consent, so the banner is
held to the same a11y bar as the rest of the site.

Verified: lint clean, tsc clean, 341 int tests, and e2e — consent 6/6, a11y
10/10, frontend 39/39, templates 60/60, templates-visual 62/62, components-visual
69/69, blog 5/5, geo 13/13. blog-index visual baselines fail identically on clean
origin/dev (stale darwin snapshots, unrelated to this change).

Co-Authored-By: Claude Opus 5 <[email protected]>
Ducksss added a commit that referenced this pull request Jul 27, 2026
Closes the gap the PR audit left open: GA4, Vercel Analytics/Speed Insights and
PostHog all loaded on first paint, so an EU visitor had GA4 cookies set before
any interaction. Honouring GPC/DNT (shipped in #352) narrowed that but could not
close it, because GA4 was mounted regardless.

AnalyticsShell now renders nothing until consent is 'granted'. On a first visit
there is no GA4 script, no Vercel bundle, no PostHog beacon and no stored
identifier. State lives in src/lib/consent.ts under `pc_consent`; ConsentBanner
collects the choice and /privacy documents the stack and can withdraw it.

Three things worth calling out:

- A browser privacy signal is a decision, not a prompt. GPC (binding under the
  CCPA) or DNT resolves to 'denied' and the banner never renders.
- Withdrawal reloads. Unmounting AnalyticsShell does not unload a third party
  that is already running — gtag stays initialised on window and keeps
  collecting — so setConsent reloads on granted -> denied. It also clears
  pc_distinct_id, so opting out erases the identifier instead of freezing it.
  This was caught by the e2e spec, not by review.
- The banner is fixed-positioned, so it costs no layout shift on the landing
  page's LCP content.

Testing: specs that assert on analytics or capture visual baselines grant consent
up-front via tests/e2e/consent.ts, which keeps the banner out of every snapshot —
only the two landing baselines changed, and only because /privacy was added to
the footer. The axe suites deliberately run without consent, so the banner is
held to the same a11y bar as the rest of the site.

Verified: lint clean, tsc clean, 341 int tests, and e2e — consent 6/6, a11y
10/10, frontend 39/39, templates 60/60, templates-visual 62/62, components-visual
69/69, blog 5/5, geo 13/13. blog-index visual baselines fail identically on clean
origin/dev (stale darwin snapshots, unrelated to this change).

Co-Authored-By: Claude Opus 5 <[email protected]>
Ducksss added a commit that referenced this pull request Jul 27, 2026
…#372)

* privacy(feat): gate all third-party analytics behind explicit consent

Closes the gap the PR audit left open: GA4, Vercel Analytics/Speed Insights and
PostHog all loaded on first paint, so an EU visitor had GA4 cookies set before
any interaction. Honouring GPC/DNT (shipped in #352) narrowed that but could not
close it, because GA4 was mounted regardless.

AnalyticsShell now renders nothing until consent is 'granted'. On a first visit
there is no GA4 script, no Vercel bundle, no PostHog beacon and no stored
identifier. State lives in src/lib/consent.ts under `pc_consent`; ConsentBanner
collects the choice and /privacy documents the stack and can withdraw it.

Three things worth calling out:

- A browser privacy signal is a decision, not a prompt. GPC (binding under the
  CCPA) or DNT resolves to 'denied' and the banner never renders.
- Withdrawal reloads. Unmounting AnalyticsShell does not unload a third party
  that is already running — gtag stays initialised on window and keeps
  collecting — so setConsent reloads on granted -> denied. It also clears
  pc_distinct_id, so opting out erases the identifier instead of freezing it.
  This was caught by the e2e spec, not by review.
- The banner is fixed-positioned, so it costs no layout shift on the landing
  page's LCP content.

Testing: specs that assert on analytics or capture visual baselines grant consent
up-front via tests/e2e/consent.ts, which keeps the banner out of every snapshot —
only the two landing baselines changed, and only because /privacy was added to
the footer. The axe suites deliberately run without consent, so the banner is
held to the same a11y bar as the rest of the site.

Verified: lint clean, tsc clean, 341 int tests, and e2e — consent 6/6, a11y
10/10, frontend 39/39, templates 60/60, templates-visual 62/62, components-visual
69/69, blog 5/5, geo 13/13. blog-index visual baselines fail identically on clean
origin/dev (stale darwin snapshots, unrelated to this change).

Co-Authored-By: Claude Opus 5 <[email protected]>

* test(chore): mint Linux visual baselines (frontend) (#373)

Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>

* privacy(fix): erase the identifier on a privacy signal and reload other tabs

Both found by CodeRabbit on #372 — the first substantive AI review this repo has
had on a dev-targeted PR since .coderabbit.yaml listed `dev` as a base branch.

resolveConsent() returned 'denied' for a GPC/DNT visitor without clearing a
pc_distinct_id that an earlier opt-in may have stored. It was never sent while
denied, but it survived to re-link the visitor to their previous identity if they
later opted back in. A signal is now treated exactly like an explicit
withdrawal.

subscribeToConsent() notified React on a cross-tab change but never reloaded.
That is the same defect the reload in setConsent exists to prevent, one tab over:
a tab that already mounted GA4 keeps gtag initialised on window and keeps
collecting, because unmounting AnalyticsShell cannot unload it. A withdrawal
elsewhere now tears this tab down too.

Both are covered by new specs that fail without the fix: a privacy signal
arriving after an opt-in must leave no identifier, and withdrawing in one tab
must strip the Google tag from a second tab that already had it.

Verified: lint clean, tsc clean, 341 int tests, consent e2e 8/8.

Co-Authored-By: Claude Opus 5 <[email protected]>

---------

Co-authored-by: Claude Opus 5 <[email protected]>
Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>

This branch was successfully deployed

2 active deployments
Preview – payload-components-97bf — 9a2b3359 Deployed Jul 27, 2026 by vercel[bot]
Preview – payload-components — 9a2b3359 Deployed Jul 27, 2026 by vercel[bot]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants