Skip to content

Keep API responses out of the service worker cache and Sentry - #3863

Closed
innolope-dev wants to merge 4 commits into
devfrom
innolope/sw-no-api-cache
Closed

innolope-dev wants to merge 4 commits into
devfrom
innolope/sw-no-api-cache

Conversation

@innolope-dev

Copy link
Copy Markdown
Collaborator

Keeps personal data out of the browser: API responses no longer land in the service worker's caches, and profile and identity saves are redacted from Sentry.

Why

GET /users/kyc/questions pre-fills saved answers, and /users/me returns profile data. serwist's default cross-origin rule cached every cross-origin GET for an hour (NetworkFirst, ignoring no-store), in a cache that sign-out didn't clear. On a shared computer, the next person could read the previous user's address or tax number from the browser's storage. Found in the KYC rework consistency review (finding #6).

What changes

  • Service worker (src/app/sw.ts, src/app/sw-api-privacy.ts)
    • Every fetch or XHR to another origin is now network-only; images, fonts and scripts from other origins keep their caches.
    • The rule matches on the request's destination, not on the API URL. The worker bundle has never had a process polyfill, so reading an env var there could throw at load.
    • On activation, the worker deletes serwist's cross-origin cache, where older workers kept API responses.
  • Sign-out purges the cross-origin cache along with the other user-data caches (src/constants/cache.consts.ts).
  • Sentry: request bodies of /update-user, /users/identity and /users/residence-change/start are dropped. Nationality, citizenship, birth place, street, town and phone keys are scrubbed (src/utils/sentry.utils.ts).

Tests

  • New: src/app/__tests__/sw-api-privacy.test.ts.
  • Extended: src/context/__tests__/authContext-logout.test.tsx, src/utils/__tests__/sentry.utils.test.ts.
  • All three suites pass locally (94 tests).

The app calls the API origin directly, so serwist's default cross-origin
rule stored every API GET (/users/me, the KYC questions with the saved
tax number and address, the KYC details and plan) in the "cross-origin"
cache for an hour, ignoring no-store, and kept it past sign-out. Only
Sumsub may hold personal data; the device must not.

- Every request to the configured API base URL is now NetworkOnly, ahead
  of the default rules. The base URL moves to an import-free module so
  the worker can read it without bundling general.consts.
- On activation the worker deletes API entries an older worker stored.
- Sign-out also purges the "cross-origin" cache.
Failed calls attach their request and response bodies to Sentry. The
key scrubber missed the bare keys the profile and KYC answers use
(phone, street, town, nationality, citizenship, countryOfBirth,
cityOfBirth), and the profile and identity endpoints were not redacted
wholesale. Add the keys, and redact /update-user, /users/identity (and
its children, which include restart) and /users/residence-change/start
entirely.
The worker bundle has never carried a process polyfill, so reading
PEANUT_API_URL there could throw at load and leave the app without a
worker. Every fetch or XHR to another origin is an API call; keep those
out of the cache and leave images, fonts and scripts to the default
rules. On activation, drop serwist's cross-origin cache, where older
workers kept API responses.
@vercel

vercel Bot commented Oct 27, 2026 •

Copy link
Copy Markdown

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

Project Deployment Actions Updated
peanut-wallet Ready Ready Preview Oct 27, 2026 9:01pm UTC

Request Review

@coderabbitai

coderabbitai Bot commented Oct 27, 2026

Copy link
Copy Markdown
Contributor

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

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
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

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.

@github-actions

Copy link
Copy Markdown
Contributor

Code-analysis diff

Painscore total: 10579.15 → 10581.49 (+2.34)
Findings: 0 net (+11 new, -11 resolved)

🆕 New findings (11)

  • high hotspot — src/utils/sentry.utils.ts — 65 commits, +1362/-427 lines since 6 months ago
  • medium high-mdd — src/utils/sentry.utils.ts:708 — fetchWithSentry: MDD 94.9 (uses across many lines from declarations)
  • medium high-dlt — src/utils/sentry.utils.ts:708 — fetchWithSentry: DLT 41 (calls 41 distinct functions — high context load)
  • medium high-mdd — src/utils/sentry.utils.ts:576 — reportNonOkResponse: MDD 30.9 (uses across many lines from declarations)
  • medium complexity — src/app/sw.ts — CC 15, MI 63.28, SLOC 69
  • medium complexity — src/app/payment-network-sw-privacy.ts — CC 14, MI 62.23, SLOC 53
  • medium complexity — src/constants/cache.consts.ts — CC 1, MI 61.91, SLOC 11
  • low high-dlt — src/utils/sentry.utils.ts:576 — reportNonOkResponse: DLT 23 (calls 23 distinct functions — high context load)
  • low high-dlt — src/utils/sentry.utils.ts:814 — attemptFetch: DLT 17 (calls 17 distinct functions — high context load)
  • low high-mdd — src/utils/sentry.utils.ts:814 — attemptFetch: MDD 13.1 (uses across many lines from declarations)
  • low missing-return-type — src/utils/sentry.utils.ts:484 — sanitizeUrl: exported fn missing return type annotation

✅ Resolved (11)

  • src/utils/sentry.utils.ts — 64 commits, +1351/-427 lines since 6 months ago
  • src/utils/sentry.utils.ts:697 — fetchWithSentry: MDD 94.9 (uses across many lines from declarations)
  • src/utils/sentry.utils.ts:697 — fetchWithSentry: DLT 41 (calls 41 distinct functions — high context load)
  • src/utils/sentry.utils.ts:565 — reportNonOkResponse: MDD 30.9 (uses across many lines from declarations)
  • src/app/sw.ts — CC 15, MI 64.02, SLOC 65
  • src/app/payment-network-sw-privacy.ts — CC 13, MI 60.83, SLOC 50
  • src/constants/cache.consts.ts — CC 1, MI 63.08, SLOC 10
  • src/utils/sentry.utils.ts:565 — reportNonOkResponse: DLT 23 (calls 23 distinct functions — high context load)
  • src/utils/sentry.utils.ts:803 — attemptFetch: DLT 17 (calls 17 distinct functions — high context load)
  • src/utils/sentry.utils.ts:803 — attemptFetch: MDD 13.1 (uses across many lines from declarations)
  • src/utils/sentry.utils.ts:473 — sanitizeUrl: exported fn missing return type annotation

📈 Painscore deltas (top movers)

File Before After Δ
src/app/sw-api-privacy.ts 0.0 1.6 +1.6

@chip-peanut-bot chip-peanut-bot Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Chip review — no blocking findings — this is not an approval

No findings in the service-worker cache and Sentry privacy changes.

Checked clean

  • Cross-origin fetch/XHR route precedes Serwist default caching; same-origin and asset routes retain their intended handling.
  • Serwist 9.5.0 uses the literal cross-origin name for this explicitly named cache, so activation and logout target the existing cache.
  • Sentry endpoint-wide redaction and recursive key scrubbing cover the changed profile and identity paths.
  • CI checks at this head were still in progress when reviewed; completed relevant checks had no failures.

Security review by moonshotai/kimi-k3: 0 finding(s), marked with the model name. It reads the diff only and answers only security, privacy and money, so treat its findings as advice.

Third opinion by claude-opus: 0 finding(s), marked with the model name. It answers only product truth, missing tests and the cross-repo contract, so treat its findings as advice.

Exact head: 622d1c1d96ac · Context: repo · Took 5m

@github-actions

Copy link
Copy Markdown
Contributor

🧪 UI test report — ✅ all green

Suites

  • ✅ unit: 14039 ran, 0 failed, 0 skipped, 5.4m

📊 Coverage (unit)

metric %
statements 85.8%
branches 77.4%
functions 80.8%
lines 87.1%
⏱ 10 slowest test cases
time test
🐢 9.0s src/app/(mobile-ui)/qr-pay/__tests__/qr-pay-states.test.tsx › Network failure keeps loading while retries remain, then shows the generic error
🐢 7.1s scripts/__tests__/indexable-urls.test.ts › excludes missing locale files, drafts, redirects, and retired pages from crawl and submission lists
🐢 6.5s scripts/__tests__/signup-attribution-paths.test.ts › includes newly published articles and locale fallbacks without editing the manifest
4.3s src/components/Card/share-asset/__tests__/shareAssetLayout.test.ts › never places two stickers in heavy overlap (broad seed sweep)
4.3s scripts/__tests__/indexable-urls.test.ts › gives crawls and IndexNow exactly the canonical inventory
4.2s scripts/__tests__/indexable-urls.test.ts › rejects explicit submissions outside the inventory and deduplicates canonical paths
4.0s src/features/setup/__tests__/useSignupPasskey.test.tsx › opens the help drawer for NotReadableError and retries from it with one more ceremony
4.0s src/app/(mobile-ui)/qr-pay/__tests__/qr-pay-states.test.tsx › MANTECA_MERCHANT_RECENT_REFUND fails fast with copy that names the real cause
4.0s src/app/(mobile-ui)/qr-pay/__tests__/qr-pay-states.test.tsx › MANTECA_USER_NOT_PROVISIONED fails fast with copy that names the real cause
4.0s src/app/(mobile-ui)/qr-pay/__tests__/qr-pay-states.test.tsx › MANTECA_MERCHANT_VOLUME_NEAR_CAP fails fast with copy that names the real cause
📍 Inline annotations are in the **Unit test report** check above. Coverage artifact: `coverage-unit`. Generated by `.github/workflows/tests.yml`.

@innolope-dev

Copy link
Copy Markdown
Collaborator Author

Folded into the KYC rework PR #3620 (commits faf2ef5, 3554e79, 4cefb40).

This branch was successfully deployed

1 active deployment
Preview — 622d1c1d Deployed Oct 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.

1 participant