Skip to content

feat(cloudflare): Auto-instrument the worker entry with withSentry#22433

Draft
JPeer264 wants to merge 1 commit into
jp/cloudflare-auto-instrument-test-runnerfrom
jp/cloudflare-auto-instrument-withsentry
Draft

feat(cloudflare): Auto-instrument the worker entry with withSentry#22433
JPeer264 wants to merge 1 commit into
jp/cloudflare-auto-instrument-test-runnerfrom
jp/cloudflare-auto-instrument-withsentry

Conversation

@JPeer264

Copy link
Copy Markdown
Member

Add sentryCloudflareAutoInstrumentPlugin and fold it into @sentry/cloudflare/vite, so a worker needs no manual Sentry.withSentry wrapping. Using the wrangler config and options module from the previous commit, the plugin rewrites the worker entry's default export to withSentry(<options>, <handler>). Matched by wrangler's main, so it applies in both vite build and vite dev. It is also safe to assume that we only need to touch the main entrypoint, as there all the exports are listed for the actual deployments.

  • Add magic-string as a dependency; the transform uses it to rewrite the worker entry source while preserving source maps.
  • Add a vite-autoinstrument/default-export integration suite: a plain unwrapped worker whose default export is wrapped at build time via the runner's Vite path.

@JPeer264 JPeer264 self-assigned this Jul 21, 2026
@JPeer264
JPeer264 force-pushed the jp/cloudflare-auto-instrument-withsentry branch from e26a607 to e43f7dc Compare July 21, 2026 13:33
Comment thread yarn.lock
source-map-js "^1.2.1"

vite@7.3.2:
vite@7.3.2, "vite@^5.0.0 || ^6.0.0 || ^7.0.0-0":

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

High severity vulnerability may affect your project—review required:
Line 30340 lists a dependency (vite) with a known High severity vulnerability.

ℹ️ Why this matters

Affected versions of vite and vite-plus are vulnerable to Exposure of Sensitive Information to an Unauthorized Actor / Improper Limitation of a Pathname to a Restricted Directory ('Path Traversal'). Vite's server.fs.deny blocklist—which protects sensitive files such as .env and certificate files from being served—can be bypassed on Windows using alternate path representations (NTFS Alternate Data Stream syntax like /.env::$DATA?raw, or 8.3 short filenames), allowing an attacker to read otherwise-denied files when the dev server is exposed to the network.

References: GHSA, CVE

To resolve this comment:
Check if you expose the Vite dev server or vite-plus to the network by configuring a non-loopback address using the --host CLI flag on Windows.

  • If you're affected, upgrade this dependency to at least version 7.3.5 at yarn.lock.
  • If you're not affected, comment /fp we don't use this [condition]
💬 Ignore this finding

To ignore this, reply with:

  • /fp <comment> for false positive
  • /ar <comment> for acceptable risk
  • /other <comment> for all other reasons

You can view more details on this finding in the Semgrep AppSec Platform here.

Add `sentryCloudflareAutoInstrumentPlugin` and fold it into
`@sentry/cloudflare/vite`, so a worker needs no manual `Sentry.withSentry`
wrapping. Using the wrangler config and options module from the previous commit,
the plugin rewrites the worker entry's default export to
`withSentry(<options>, <handler>)` — matched by wrangler's `main`, so it applies
in both `vite build` and `vite dev`.

- Add `magic-string` as a dependency; the transform uses it to rewrite the
  worker entry source while preserving source maps.
- Add a `vite-autoinstrument/default-export` integration suite: a plain
  unwrapped worker whose default export is wrapped at build time via the runner's
  Vite path.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
@JPeer264
JPeer264 force-pushed the jp/cloudflare-auto-instrument-test-runner branch from fee009a to 61ecd75 Compare July 21, 2026 15:25
@JPeer264
JPeer264 force-pushed the jp/cloudflare-auto-instrument-withsentry branch from e43f7dc to f03fae8 Compare July 21, 2026 15:25
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