Skip to content

chore(build): upload sentry source maps from the pages build - #145

Merged
Ardnived merged 8 commits into
mainfrom
chore/sentry-sourcemaps
Aug 11, 2026
Merged

Ardnived merged 8 commits into
mainfrom
chore/sentry-sourcemaps

Conversation

@Ardnived

@Ardnived Ardnived commented Aug 11, 2026 •

Copy link
Copy Markdown
Contributor

Closes #130

#108 wired Sentry, so crashes arrive — but every production frame pointed into a minified chunk. The ticket's own verification found the cause: vite.config.ts set no build.sourcemap at all, so Vite's default applied and the build emitted no maps whatsoever. This is not "maps that weren't uploaded".

What changed

Maps are now emitted as 'hidden', uploaded by @sentry/vite-plugin, and deleted before the output is deployed. They must never ship: public/_headers serves /assets/* with Access-Control-Allow-Origin: * and max-age=31536000, immutable, so a shipped .map is a CORS-open, year-cached copy of this repo's source, content-hashed and therefore unrecallable. (embed.js.map is the one exception — dist root, outside that rule — which changes how long the mistake lasts, not whether it is one.)

Both the plugin and build.sourcemap are gated on SENTRY_AUTH_TOKEN, so a build that cannot upload does not write maps at all.

pnpm assert:maps is the guarantee rather than the intention, following assert:css. It fails on a surviving .map, on any sourceMappingURL (the check that matters most — sourcemap: 'inline' embeds every source in the JS and emits no .map file), and on the auth token's value appearing anywhere in the output. It runs on both deploy targets.

The release / debug-ID tension #108 flagged

release: undefined stays. #108 pinned it because the SDK's default reads the host page's window.SENTRY_RELEASE; symbolication uses debug IDs, which need no release; and #143 settled that this repo deploys evergreen with a version that is "a marker, not a contract", so many builds share 0.9.0 while each has its own debug IDs.

Verified against the installed plugin rather than recalled: release.inject defaults to true and would write window.SENTRY_RELEASE onto the host page — #108's hazard in reverse — and create: false alone still ran sentry-cli releases finalize <sha>, whose failure would have been reported as "source-map upload failed". All four release actions are now off.

Review round — both passes landed after the first push; 2 High, 3 Medium, 5 Low + 3 security Mediums, all fixed

Neither review found a way for a map to actually ship, and both confirmed the core claim under test. What they found was worse in a quieter way: guards that were wrong about their own scope.

# Finding Fix
H2 The half-config throw ran at config evaluation, so it fired for every Vite command. vite dev and vite preview both died with "failed to load config" — a contributor with an ambient SENTRY_AUTH_TOKEN from another project could not start the dev server. Config is now a function of { command }; the throw is build-only. Verified dev starts, preview starts, half-configured build still fails loudly.
H1 + sec-M1 The gate's docblock claimed "both Cloudflare Pages builds gate on it". sahajatlas-design builds pnpm ladle:build, which never runs pnpm build — and it contradicted this branch's own runbook. Made true rather than deleted: the output dir is an argument and ladle:build passes ../build (146 files scanned). Latent today, but Ladle imports the real src/ tree.
M1 The errorHandler comment named the wrong hazard. handleRecoverableError never rethrows when a handler is set, so passing one also downgrades a failed deletion to "log and exit 0, maps on disk" — the one path a map could ship, and the real justification for assert:maps. Conversely the gate can not backstop a failed upload, since deletion runs in finally regardless. Comment corrected in both directions; log line no longer says "the deploy is unaffected".
M2 Refusing release.inject for writing a host global while silently accepting two of our own (_sentryDebugIds, _sentryDebugIdIdentifier). Plus: the 2.1 KiB under-measurement was reported without its ratchet hazard. Both globals documented with why they're accepted (additive, stack-keyed, unread at runtime; no option separates debug-ID upload from injection). CLAUDE.md now warns that lowering BUDGET_KIB to within 2.1 KiB of the CI number makes production fail a gate CI cannot reproduce.
M3 The beforeSend docblock still opened "An allowlist, not a blocklist" above four delete calls. My first pass annotated the discrepancy and left it — a noticed false claim is still the one a reader acts on, and that delete-list is the only reason debug_meta survives. Rewritten to describe reality, naming a true allowlist as the stronger form and why it isn't a drive-by here. Spec typed to Event['debug_meta'] so a rename fails typecheck (the real functions aren't public API — @sentry/core exports only ././server/./browser).
L5 Every CI step ran the uncredentialed path, so Cloudflare was the first machine ever to execute the credentialed chain. New offline dry-run job: dummy token, closed port. Nothing leaves the runner; emission, the non-fatal handler, deletion and the gate are all proven.
sec-M2 .env.sentry-build-plugin — which the plugin reads and Object.assigns over process.env, and where Sentry's wizard writes the token — did not match *.local. Added to .gitignore.
sec-M3 The runbook said the token needs no release scope. Wrong, and silently so: the upload is sourcemaps upload -p <project> --release <sha> even with all four release actions off. An under-scoped token 403s → swallowed → green deploy, minified forever. Now names project:releases + org:read and says to read the first credentialed build log. Confirmed in a real build log.
L1, L2, L3, L4, sec-L* "Last:" described array position (the plugin is enforce: 'pre'); /assets/* doesn't cover embed.js.map; the absolute delete-glob is exposed to glob metacharacters in the checkout path; the sourceMappingURL failure text gave the wrong instruction for a dependency embedding the literal. Comments corrected; L4's message names both causes. L3 left unescaped deliberately — it fails as "deletes nothing", which assert:maps turns red.

Verification

Build plumbing, so verified by building and inspecting output. End-to-end symbolication is NOT verified — that needs a real DSN and token.

Check Result
lint / typecheck / test:run ✓ 1000 tests / 83 files
build + size, no token ✓ 370.0 / 371.8 KiB — identical to main. BUDGET_KIB unchanged at 395
Credentialed build (closed port) ✓ maps emitted, upload fails loudly, maps deleted, dist/ clean
ladle:build with all three set ✓ no maps, nothing uploaded, token absent — and now gated
dev / preview with ambient token ✓ both start (H2 regression test)
audit:check ✓ 0 advisories

The gate is not vacuous — against a dist/ left holding maps it named all 24 and exited 1. sourcemap: 'hidden' costs zero; the whole +2.1 KiB is debug-ID injection, on credentialed builds only. Token containment: absent from dist/, as are the org/project slugs — and now enforced by the gate rather than by a one-off grep.

Not done here — merging this does NOT complete the ticket

Dashboard actions only; until they're done the build behaves exactly as before. Runbook in .claude/docs/environment.md.

  • Provision the Sentry project and set VITE_SENTRY_DSN — the precondition; maps with no events are inert. Not currently set.
  • Create an auth token with project:releases + org:read (see sec-M3 above — the "no release scope" shortcut is wrong).
  • Add SENTRY_AUTH_TOKEN, SENTRY_ORG, SENTRY_PROJECT to sahajatlas — production certainly, preview recommended. All three or none.
  • Do not add them to sahajatlas-design.
  • Check the first credentialed build log for a 403 — a swallowed upload failure looks exactly like success from the outside.
  • From feat(widget): wire sentry into the error-reporting seam #108, unchanged: enable "Prevent Storing of IP Addresses" and set a short retention.

Implementation report: .claude/reports/130-sentry-sourcemaps.md.

Ardnived and others added 3 commits August 11, 2026 09:55
`vite.config.ts` set no `build.sourcemap`, so the default (`false`) applied and
the build emitted no maps at all — every production frame from #108's telemetry
pointed into a minified chunk. This is not "maps that weren't uploaded".

Maps are now emitted as `'hidden'` (written, but no `sourceMappingURL` comment
advertises them), uploaded by `@sentry/vite-plugin`, and deleted before the
output is deployed. They must never reach `dist/`: `public/_headers` serves
`/assets/*` CORS-open with a one-year immutable cache, so a shipped `.map` is an
irrevocable publication of this repo's source from a host page we don't own.

Both halves are gated on `SENTRY_AUTH_TOKEN`, the plugin AND `build.sourcemap`,
so a build that cannot upload does not write maps at all. Local builds, CI, forks
and `pnpm ladle:build` (which uses its own vite config) are byte-identical to
before — measured: 370.0/371.8 KiB on both graphs, unchanged.

`pnpm assert:maps` is the guarantee rather than the intention, per the
`assert:css` precedent. It fails on a surviving `.map` AND on any
`sourceMappingURL`, because `sourcemap: 'inline'` would embed every original
source in the shipped JS while emitting no `.map` file for the first check to
find. Verified against a real dist: it catches all 24 maps and exits 1.

Two plugin defaults are overridden because they reach out of the widget.
`release.inject` would write `window.SENTRY_RELEASE` onto the HOST page — the
exact hazard #108 refused in the other direction — and `telemetry` posts build
data from inside the deploy's critical path. `create`/`finalize`/`setCommits` are
all off too: `create: false` alone still ran `sentry-cli releases finalize`,
which needs scope we don't want to grant and whose failure would be reported as
a failed map upload.

An upload failure is loud but non-fatal. This widget deploys evergreen, and a
bug fix should not be blocked by a telemetry outage — availability may degrade
the diagnostics, never the safety, which is why `assert:maps` still fails the
build if the maps are the thing left behind.

Refs #130

Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
Symbolication needs a release OR a debug ID to match a frame to a map. `release`
stays `undefined` — #108 pinned it because the SDK's default reads the HOST
page's `window.SENTRY_RELEASE`, and #143 settled that this repo's version is "a
marker, not a contract" for an evergreen deploy, so it is the wrong identity
anyway. Debug IDs are per-build and need no release, which keeps that hazard
shut; `vite.config.ts` blocks the plugin from injecting the global in reverse.

That makes `debug_meta` load-bearing, and it sits one deletion away from gone.
`prepareEvent` fills it from the injected debug IDs BEFORE `beforeSend` runs
(verified in @sentry/core 10.69.0: `applyDebugIds` then `applyDebugMeta`, then
`processBeforeSend`), and our hook survives only because it is a delete-list —
the docblock beside it says "allowlist", and making that literally true would
un-symbolicate every frame with the upload, the deletion gate and every other
check still green.

So it is a spec, not a comment. Mutation-tested: adding `delete event.debug_meta`
turns it red.

Refs #130

Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
The repo half and the dashboard half are documented separately on purpose, so
merging this cannot be mistaken for completing it — the same care #143 took with
its own unchecked list. Until the three variables are set on the `sahajatlas`
Pages project, the build behaves exactly as it did before.

environment.md gains the three build-time variables and the runbook: which Pages
project (not `sahajatlas-design`, which builds through .ladle/vite.config.ts and
cannot run the plugin — verified, not assumed), which environments, why all three
or none, and the one criterion the repo cannot check for itself.

CLAUDE.md records why the `_headers` rule it already documents is what makes a
shipped map irrecoverable, and the size gate's new blind spot: the plugin only
runs on a credentialed build, so CI measures ~2.1 KiB less than production ships.

Refs #130

Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
@cloudflare-workers-and-pages

cloudflare-workers-and-pages Bot commented Aug 11, 2026 •

Copy link
Copy Markdown

Deploying sahajatlas-design with  Cloudflare Pages  Cloudflare Pages

Latest commit: 93cb2e8
Status: ✅  Deploy successful!
Preview URL: https://f0320e27.sahajatlas-design.pages.dev
Branch Preview URL: https://chore-sentry-sourcemaps.sahajatlas-design.pages.dev

View logs

@cloudflare-workers-and-pages

cloudflare-workers-and-pages Bot commented Aug 11, 2026 •

Copy link
Copy Markdown

Deploying sahajatlas with  Cloudflare Pages  Cloudflare Pages

Latest commit: 93cb2e8
Status: ✅  Deploy successful!
Preview URL: https://3c26928c.sahajatlas.pages.dev
Branch Preview URL: https://chore-sentry-sourcemaps.sahajatlas.pages.dev

View logs

Ardnived and others added 5 commits August 11, 2026 10:27
H2, plus the vite.config comments review found asserting things the code does
not do.

**H2.** `vite.config.ts` is evaluated for EVERY Vite command, not just builds, so
the half-config throw fired on `vite dev` and `vite preview` too — both died with
"failed to load config". A contributor with an ambient SENTRY_AUTH_TOKEN from any
other Sentry-instrumented project could not start the dev server, and the error
talked about uploading source maps on a command that uploads nothing. The
justification for that throw — a deploy going green with every frame minified —
exists only for `command === 'build'`, so the config is now a function of
`{ command }`. Verified three ways: dev starts, preview starts, and a build with
a token but no org still fails loudly.

**M1.** The `errorHandler` comment named the wrong hazard and understated what
passing the handler disarms. `handleRecoverableError` only rethrows in the branch
where no handler was supplied, so supplying one also downgrades a failed
`deleteArtifacts()` — called with `throwByDefault: true` — from "fail the build"
to "log and exit 0, maps still on disk". THAT is the one path by which a map
could reach dist, and the real reason `assert:maps` exists. The converse is now
stated too: the gate cannot backstop a failed UPLOAD, because deletion runs in
`writeBundle`'s `finally` regardless.

**M2.** The docblock refused `release.inject` on the grounds that it writes a
host-page global while silently accepting two of our own. Debug-ID injection
writes `window._sentryDebugIds` and `_sentryDebugIdIdentifier` at module
evaluation. Recorded, with why they are accepted where SENTRY_RELEASE is not:
there is no option keeping debug-ID upload without injection, the map is additive
and stack-keyed so it cannot displace a host's entries, and nothing reads the
identifier at runtime.

**L1.** "Last:" described the array position, not the behaviour — the plugin
returns `enforce: 'pre'`, so Vite hoists it ahead of everything above regardless.
What makes it safe is the phase: it reads off disk in `writeBundle`.

**L2.** `/assets/*` is not the whole story — `embed.js.map` sits at the dist root,
outside that CORS+immutable rule. Still a disclosure, just a recallable one.

**L3.** Notes that the absolute delete glob is exposed to glob metacharacters in
the checkout path, and that `assert:maps` is the mitigation rather than escaping.

Refs #130

Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
H1 said the gate's docblock claimed "CI and both Cloudflare Pages builds gate on
it" when `sahajatlas-design` builds `pnpm ladle:build`, which never runs
`pnpm build`. The security review independently reached the same file from the
other direction: the gate is `dist`-only while `public/_headers` is copied into
BOTH outputs, so a map in `build/` would be served under the same CORS-open,
year-immutable rule.

So the claim is made TRUE rather than deleted. The output directory is now an
argument and `ladle:build` passes `../build` — 146 files scanned there. Latent
today (Ladle builds through `.ladle/vite.config.ts`, which loads neither our
`build.sourcemap` nor the plugin), but Ladle stories import the app's real `src/`
tree, so anyone adding `sourcemap: true` to debug a story would have shipped it
with no gate anywhere in the pipeline.

Also from the security review: `assert:maps` now greps every emitted file for the
value of SENTRY_AUTH_TOKEN when one is set. Vite cannot inline a variable without
a `VITE_` prefix so this should be unreachable, but "should be" is what this file
exists to replace, and it makes environment.md's claim that the output is grepped
a gate rather than a habit. Costs nothing uncredentialed; an empty-string token
(a declared-but-blank Cloudflare variable) is specced not to match every file.

L4: the sourceMappingURL failure text said `build.sourcemap` must change, which is
the wrong instruction when the cause is a dependency embedding the literal string
— ordinary content in stack-trace libraries. It now names both causes and says to
exempt the file by name rather than weaken the check.

Refs #130

Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
M3. The `beforeSend` docblock opened "An allowlist, not a blocklist — the event is
rebuilt from what we know we put on it" four lines above
`delete event.user / extra / contexts / breadcrumbs`. My previous commit annotated
the discrepancy and left it standing, which is not a fix: a false claim that has
been noticed is still the claim a future reader acts on. It also matters more than
usual here, because that delete-list IS the only reason `debug_meta` survives to
symbolicate anything.

Rewritten to say what the code does, name a true allowlist as the stronger form
still worth having, and say why it is not attempted here — enumerating the fields
an event legitimately needs is a change to the seam deserving its own ticket, not
a drive-by on a build-plumbing PR. Whoever does it is told to carry `debug_meta`
across.

The spec is strengthened the way review asked, as far as the SDK allows. Driving
the real `applyDebugIds`/`applyDebugMeta` is not possible without a deep import
into `build/esm/utils/` — `@sentry/core`'s exports map offers only `.`, `./server`
and `./browser` — which is the library-internals coupling the tests rule forbids.
So the fixture is typed as `NonNullable<Event['debug_meta']>` instead: a delete-
list returns any key you hand it, so an invented fixture would pass even for a
misspelled field, and binding it to the SDK's own type means a rename fails
typecheck.

Refs #130

Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
…oken file

Two findings that both amount to "the dangerous path is the untested one".

**L5.** Every CI step runs the UNcredentialed path, because CI has no token — so
the first machine ever to execute map emission, deletion and the gate together
was Cloudflare, on a production deploy. The new step builds with a dummy token
against a closed port: the upload fails immediately and nothing leaves the
runner, while everything around it is asserted — maps are emitted under a token,
`errorHandler` keeps the failure non-fatal, deletion still runs in `writeBundle`'s
`finally`, and `assert:maps` proves dist is clean. The token is a literal rather
than a secret so this keeps working on forked PRs.

**Security review, medium.** `.env.sentry-build-plugin` is where Sentry's own
wizard and docs write SENTRY_AUTH_TOKEN, and `@sentry/vite-plugin` reads it at
build time and Object.assign's it over `process.env`. It does not match `*.local`,
so the default filename for a real secret was tracked in a public repo. The
security-scan hook carries a SENTRY_AUTH_TOKEN pattern but only fires on
agent-run git commands, not a human's terminal.

Running that dry run locally also confirmed the runbook correction in the next
commit: the upload really is `sourcemaps upload -p <project> --release <sha>`,
release-scoped, even with all four release actions off.

Refs #130

Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
**Security review, medium — the runbook was wrong in a way that fails silently.**
It said the token "does not need release-write scope" because the plugin sets
`create`/`finalize`/`setCommits` to false. Those switch off the extra release
CALLS, but the upload command itself is still release-scoped — observed in a real
build log as `sourcemaps upload -p <project> --release <sha>`, because the plugin
infers a release name from git regardless. An under-scoped token 403s,
`errorHandler` logs it, the deploy goes green and production ships minified
forever: the exact state #130 exists to end, reached through its own runbook. Now
names `project:releases` + `org:read`, says to confirm against Sentry's docs, and
says to read the first credentialed build log rather than assume.

**M2, second half.** The ~2.1 KiB under-measurement was reported but its
consequence was not: CLAUDE.md treats the size budget as a ratchet to lower
whenever the payload shrinks, and lowering `BUDGET_KIB` to within 2.1 KiB of the
CI number would make the PRODUCTION build fail a gate CI cannot reproduce. Stated
as a constraint on that ratchet.

CLAUDE.md also gains the corrected errorHandler story (deletion, not upload, is
the path the gate closes) and the new offline dry-run step.

Refs #130

Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
@Ardnived
Ardnived merged commit 3609ea7 into main Aug 11, 2026
5 checks passed
@Ardnived
Ardnived deleted the chore/sentry-sourcemaps branch August 11, 2026 17:45
Ardnived added a commit that referenced this pull request Aug 11, 2026
Two conflicts, both from #146 editing the very sections this branch moved.

README.md — #146 enriched the inline sizing section with #107's
container-responsive behaviour; this branch had replaced that block with a
pointer to docs/embedding.md. Kept the pointer, and ported #146's new facts
INTO the guide's own "Sizing the element" section rather than dropping them:
map-less now adapts to the element rather than the viewport, touch
affordances deliberately follow the device instead, and map mode warns in
the console when it is given a slot it cannot use.

demo.html — #146 added the full-page-slot warning to the same comment where
this branch replaced the dead API key with a placeholder. Kept both: the
warning reads first, then the key instruction. The 1cf076ab literal stays
gone; SahajCloud answers 403 to it, so restoring it would put the harness
back to looking broken for a reason unrelated to the code under test.

Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
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.

chore(build): upload sentry source maps from the pages build

1 participant