Skip to content

fix(consent): drop oc_ storage-key branding and resolve aliased ConsentGate imports (#161) - #175

Merged
jamiedavenport merged 4 commits into
mainfrom
issue-161
Aug 2, 2026
Merged

fix(consent): drop oc_ storage-key branding and resolve aliased ConsentGate imports (#161)#175
jamiedavenport merged 4 commits into
mainfrom
issue-161

Conversation

@jamiedavenport

@jamiedavenport jamiedavenport commented Aug 2, 2026

Copy link
Copy Markdown
Owner

Summary

Closes the two 1.1.0 audit leftovers in #161. The consent storage adapters still defaulted to the pre-rebrand OpenCookies key oc_consent, and the Vite scanner only recognised a gate whose JSX element was literally named ConsentGate, so import { ConsentGate as Gate } silently defeated gating detection and reported correctly-gated code as ungated (a build failure under mode: "error"). Both adapters now default to ps_consent while still reading the old key, so no existing visitor is re-prompted, and the scanner resolves aliased and namespaced gate imports.

Changes

  • localStorageAdapter and cookieAdapter default to ps_consent (probe key __ps_probe__), with a read-only fallback to oc_consent that is skipped when you pass your own key/name. clear() is the deliberate exception and removes both keys, otherwise the fallback would resurrect a decision the visitor just withdrew; subscribe() watches both keys but ignores a stale legacy event once the canonical key holds a value.
  • Added cookieAdapter().getSetCookieHeaders(record) because the existing singular getSetCookieHeader returns one string and cannot expire two cookies, leaving oc_consent behind on an SSR clear. The singular form is unchanged for compatibility. Note cookieAdapter().name now returns ps_consent, so server code should read that property rather than hardcode the string.
  • The scanner threads the import map parser.ts already builds into isGated, so <Gate> and <PS.ConsentGate> resolving to a @policystack/* export now count as gates. Matching is purely additive: a bare <ConsentGate> with no import still gates, so local wrappers, barrel re-exports and auto-imports keep working and no previously-clean project starts failing.
  • Docs updated (core.md storage-key section, scanner.md gate contract) plus a minor changeset for @policystack/core and @policystack/vite. 16 new tests cover the migration reads, both clear() paths, cross-tab events on either key, and the alias/namespace/non-PolicyStack scanner cases.

Verification

vp test is at 1024 passing, up from a 1008 baseline. The 28 failures in solid/svelte are pre-existing and reproduce identically on a clean main. vp lint and check-types are clean across all 11 packages, and the scanner regression corpora (example-green, projects, real-world, plugin-fold) stay green.

Not done: the manual browser re-prompt check on apps/web. The migration paths are covered by unit tests instead, so a quick dogfood before merge would be worth it.

Vue/Svelte gates live in SFC template markup the scanner never parses, and Angular's ocConsent directive sits outside the include glob, so aliasing is only fixable for the JSX frameworks. Left as-is.

Summary by CodeRabbit

  • New Features

    • Consent storage now uses ps_consent by default.
    • Existing oc_consent data remains readable and is cleared during migration.
    • Added support for generating all required cookie-clearing headers.
    • Consent scanning now recognizes aliased and namespace-based ConsentGate imports.
  • Documentation

    • Documented storage-key defaults, migration behavior, custom keys, cookie clearing, and expanded gate detection.
  • Bug Fixes

    • Improved handling of empty or corrupt stored consent values and legacy storage events.

@vercel

vercel Bot commented Aug 2, 2026

Copy link
Copy Markdown

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

Project Deployment Actions Updated (UTC)
op-demo Ready Ready Preview Aug 2, 2026 2:08pm
openpolicy-sh Ready Ready Preview Aug 2, 2026 2:08pm
policystack Ready Ready Preview Aug 2, 2026 2:08pm

Request Review

@coderabbitai

coderabbitai Bot commented Aug 2, 2026

Copy link
Copy Markdown

Review Change Stack

Warning

Review limit reached

@jamiedavenport, you've reached your PR review limit, so we couldn't start this review.

Next review available in: 8 minutes

Enable usage-based reviews in Billing to review now. Otherwise, wait until the next included review is available.
You're only billed for reviews past your plan's rate limits ($0.25/file).

How can I continue?

After more reviews become available, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

To avoid repeated limits, reduce automatic review volume by pausing incremental auto-reviews earlier, using label-based review opt-in, excluding WIP or generated PR titles, or requesting reviews manually when the PR is ready. If your team needs uninterrupted high-volume reviews, an organization admin can enable usage-based reviews.

How do review limits work?

CodeRabbit enforces per-developer PR review limits for each organization. Most developers receive the normal plan review availability.

For paid Pro and Pro+ PR reviews, CodeRabbit uses adaptive limits for sustained high-volume activity. When a developer's recent PR review activity reaches the 95th percentile or higher among CodeRabbit users, additional reviews become available more gradually as earlier reviews age out of the rolling window.

Please refer docs for additional details.

Review details
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro Plus

Run ID: b9934db1-5d64-4eee-b89b-9b24584a1794

📥 Commits

Reviewing files that changed from the base of the PR and between 6429e5a and 1be1df8.

📒 Files selected for processing (2)
  • packages/core/src/consent/storage/local-storage.test.ts
  • packages/core/src/consent/storage/local-storage.ts
📝 Walkthrough

Walkthrough

The PR changes default consent storage from oc_consent to ps_consent with legacy reads and cleanup. It adds cookie clearing headers and updates tests and documentation. The Vite scanner now detects aliased and namespace-qualified PolicyStack ConsentGate imports.

Changes

Consent storage-key migration

Layer / File(s) Summary
Local-storage migration behavior
packages/core/src/consent/storage/local-storage.ts, packages/core/src/consent/storage/local-storage.test.ts, packages/react/src/consent.ssr.test.tsx
Local storage uses ps_consent by default, reads oc_consent when appropriate, clears both default keys, and handles related storage events. Tests and SSR fixtures cover the updated behavior.
Cookie migration and headers
packages/core/src/consent/storage/cookie.ts, packages/core/src/consent/storage/cookie.test.ts, apps/web/content/docs/consent/core.md
The cookie adapter reads legacy default cookies, writes ps_consent, exposes getSetCookieHeaders, and expires oc_consent during clearing. Tests and documentation cover default and custom names.

ConsentGate scanner detection

Layer / File(s) Summary
Import-aware gate detection
packages/vite/src/consent/ungated.ts, packages/vite/src/consent/visit.ts, packages/vite/src/consent/ungated.test.ts, apps/web/content/docs/consent/scanner.md, .changeset/ps-consent-storage-key.md
The scanner resolves direct, aliased, and namespace-qualified PolicyStack ConsentGate imports. Tests retain findings for unresolved and unrelated imports. Documentation and release notes describe the changes.

Estimated code review effort: 3 (Moderate) | ~25 minutes

Sequence Diagram(s)

sequenceDiagram
  participant Caller
  participant CookieAdapter
  participant BrowserOrCallback
  Caller->>CookieAdapter: getSetCookieHeaders(null)
  CookieAdapter->>CookieAdapter: create canonical and legacy expiration headers
  CookieAdapter->>BrowserOrCallback: emit all Set-Cookie headers
Loading
sequenceDiagram
  participant visit.report
  participant isGated
  participant ParsedImports
  visit.report->>isGated: pass JSX parents and parsed imports
  isGated->>ParsedImports: resolve ConsentGate bindings
  ParsedImports-->>isGated: return import metadata
  isGated-->>visit.report: classify the hit
Loading

Possibly related issues

  • Issue 161 — Covers the storage-key migration, legacy fallback, and aliased ConsentGate scanner detection implemented in this PR.
🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 14.29% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly summarizes both primary changes: the consent storage-key migration and aliased or namespaced ConsentGate import resolution.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches 💡 1
📝 Generate docstrings 💡
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch issue-161

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

@coderabbitai coderabbitai Bot 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.

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@packages/core/src/consent/storage/local-storage.ts`:
- Around line 45-63: Update readKey so an empty result from ls.getItem(name)
falls through to memory.get(name), while preserving the existing fallback when
getStorage() is unavailable or localStorage access throws. Ensure stored values
written to memory after writeRaw failure remain readable through read().
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro Plus

Run ID: e9a7271a-27da-4d5b-ae10-70986779fe12

📥 Commits

Reviewing files that changed from the base of the PR and between 74ab73b and 6429e5a.

📒 Files selected for processing (11)
  • .changeset/ps-consent-storage-key.md
  • apps/web/content/docs/consent/core.md
  • apps/web/content/docs/consent/scanner.md
  • packages/core/src/consent/storage/cookie.test.ts
  • packages/core/src/consent/storage/cookie.ts
  • packages/core/src/consent/storage/local-storage.test.ts
  • packages/core/src/consent/storage/local-storage.ts
  • packages/react/src/consent.ssr.test.tsx
  • packages/vite/src/consent/ungated.test.ts
  • packages/vite/src/consent/ungated.ts
  • packages/vite/src/consent/visit.ts

Comment thread packages/core/src/consent/storage/local-storage.ts
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.

1 participant