Skip to content

fix(core): Avoid stack overflow in FunctionToString on cyclic Proxy prototype chains - #26162

Merged
chargome merged 1 commit into
developfrom
fix-tostring-cyclic-proxy
Nov 6, 2026
Merged

chargome merged 1 commit into
developfrom
fix-tostring-cyclic-proxy

Conversation

@chargome

@chargome chargome commented Nov 6, 2026 •

Copy link
Copy Markdown
Member

Why: The patched toString looked up __sentry_original__ through the prototype chain. If that chain loops through a Proxy, the lookup overflows the stack, while native toString works fine. We now only read it when it's an own property, which is where markFunctionWrapped puts it.

The Hono proxies only exposed it through a get trap, so they now report it as an own property too.

Closes #25963

…rototype chains

The patched toString read __sentry_original__ through the prototype chain. When that chain
loops back through a Proxy, the lookup never ends and overflows the stack, while native
toString returns normally. Only unwrap when the original is an own property, which is how
markFunctionWrapped stores it, and fall back to native toString if the lookup throws.

The Hono proxies exposed __sentry_original__ only through a get trap, so they also report it
as an own property now to keep unwrapping.

Fixes #25963
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@chargome chargome self-assigned this Nov 6, 2026
@chargome

chargome commented Nov 6, 2026

Copy link
Copy Markdown
Member Author

bugbot run

@cursor cursor 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.

✅ Bugbot reviewed your changes and found no new issues!

Comment @cursor review or bugbot run to trigger another review on this PR

Reviewed by Cursor Bugbot for commit 3079ba0. Configure here.

@github-actions

github-actions Bot commented Nov 6, 2026

Copy link
Copy Markdown
Contributor

size-limit report 📦

Compared: 840f27e (PR test merge using develop at 4c9a4eb)

Against: 4c9a4eb (develop) · base run #65205

✅ Baseline matches: this diff contains only this PR's changes.

Path Size % Change Change
@sentry/browser 30.41 kB +0.04% +12 B 🔺
@sentry/browser - with treeshaking flags 28.55 kB +0.04% +10 B 🔺
@sentry/browser - with treeshaking flags tracing without tracing 28.44 kB +0.04% +11 B 🔺
@sentry/browser (incl. Tracing) 52.73 kB +0.02% +8 B 🔺
@sentry/browser (incl. Tracing + Span Streaming) 52.74 kB +0.02% +9 B 🔺
@sentry/browser (incl. Tracing, Profiling) 55.71 kB +0.02% +7 B 🔺
@sentry/browser (incl. Tracing, Replay) 93.05 kB +0.02% +13 B 🔺
@sentry/browser (incl. Tracing, Replay) - with treeshaking flags 81.64 kB +0.02% +11 B 🔺
@sentry/browser (incl. Tracing, Replay with Canvas) 97.79 kB +0.02% +14 B 🔺
@sentry/browser (incl. Tracing, Replay, Feedback) 110.78 kB +0.01% +10 B 🔺
@sentry/browser (incl. Feedback) 48 kB +0.04% +16 B 🔺
@sentry/browser (incl. sendFeedback) 35.52 kB +0.04% +12 B 🔺
@sentry/browser (incl. FeedbackAsync) 40.62 kB +0.05% +17 B 🔺
@sentry/browser (incl. Metrics) 31.45 kB +0.05% +13 B 🔺
@sentry/browser (incl. Logs) 31.74 kB +0.05% +15 B 🔺
@sentry/browser (incl. Metrics & Logs) 32.46 kB +0.05% +13 B 🔺
@sentry/react 32.29 kB +0.02% +5 B 🔺
@sentry/react (incl. Tracing) 55.12 kB +0.04% +21 B 🔺
@sentry/vue 38.68 kB +0.03% +11 B 🔺
@sentry/vue (incl. Tracing) 55.75 kB +0.02% +6 B 🔺
@sentry/svelte 30.44 kB +0.04% +12 B 🔺
@sentry/remix (Remix 3 client bundle) 57.84 kB +0.05% +24 B 🔺
CDN Bundle 32.21 kB +0.05% +13 B 🔺
CDN Bundle (incl. Tracing) 53.28 kB +0.05% +24 B 🔺
CDN Bundle (incl. Logs, Metrics) 34.48 kB +0.05% +15 B 🔺
CDN Bundle (incl. Tracing, Logs, Metrics) 55.22 kB +0.04% +19 B 🔺
CDN Bundle (incl. Replay, Logs, Metrics) 75.89 kB +0.03% +16 B 🔺
CDN Bundle (incl. Tracing, Replay) 91.5 kB +0.03% +22 B 🔺
CDN Bundle (incl. Tracing, Replay, Logs, Metrics) 93.43 kB +0.03% +23 B 🔺
CDN Bundle (incl. Tracing, Replay, Feedback) 97.6 kB +0.03% +24 B 🔺
CDN Bundle (incl. Tracing, Replay, Feedback, Logs, Metrics) 99.59 kB +0.02% +19 B 🔺
CDN Bundle - uncompressed 94.74 kB +0.08% +73 B 🔺
CDN Bundle (incl. Tracing) - uncompressed 157.74 kB +0.05% +73 B 🔺
CDN Bundle (incl. Logs, Metrics) - uncompressed 101.22 kB +0.08% +73 B 🔺
CDN Bundle (incl. Tracing, Logs, Metrics) - uncompressed 163.48 kB +0.05% +73 B 🔺
CDN Bundle (incl. Replay, Logs, Metrics) - uncompressed 232.78 kB +0.04% +73 B 🔺
CDN Bundle (incl. Tracing, Replay) - uncompressed 279.44 kB +0.03% +73 B 🔺
CDN Bundle (incl. Tracing, Replay, Logs, Metrics) - uncompressed 285.16 kB +0.03% +73 B 🔺
CDN Bundle (incl. Tracing, Replay, Feedback) - uncompressed 293.14 kB +0.03% +73 B 🔺
CDN Bundle (incl. Tracing, Replay, Feedback, Logs, Metrics) - uncompressed 298.85 kB +0.03% +73 B 🔺
@sentry/nextjs (client) 58.07 kB +0.03% +17 B 🔺
@sentry/sveltekit (client) 53.25 kB +0.02% +9 B 🔺
@sentry/core/server 44.25 kB - -
@sentry/core/browser 13.93 kB - -
@sentry/node 157.04 kB +0.06% +88 B 🔺
@sentry/node/import (ESM hook with diagnostics-channel injection) 82.28 kB - -
@sentry/node - without tracing 97.12 kB +0.1% +94 B 🔺
@sentry/node - without channel injection 137.38 kB +0.07% +89 B 🔺
@sentry/aws-serverless 105.48 kB +0.1% +97 B 🔺
@sentry/cloudflare (withSentry) - minified 200.76 kB +0.04% +79 B 🔺
@sentry/cloudflare (withSentry) 499.11 kB +0.02% +55 B 🔺
@sentry/nextjs/cloudflare (withSentry) - minified 222.76 kB +0.04% +79 B 🔺

View base workflow run

@github-actions

github-actions Bot commented Nov 6, 2026

Copy link
Copy Markdown
Contributor

Optional E2E tests

Some optional checks were not successful. They do not block the merge. 6 not successful, 50 successful. See the run.

Check Status
❌ CI: Optional E2E Tests / E2E nextjs-16-cacheComponents (cloudflare) Test (optional) Failing after 10m Details
❌ CI: Optional E2E Tests / E2E node-eve (latest) Test (optional) Failing after 54s Details
❌ CI: Optional E2E Tests / E2E node-eve (orchestrion) Test (optional) Failing after 2m Details
❌ CI: Optional E2E Tests / E2E cloudflare-pi-durable (latest) Test (optional) Failing after 1m Details
❌ CI: Optional E2E Tests / E2E node-eve Test (optional) Failing after 2m Details
❌ CI: Optional E2E Tests / E2E node-flue (latest) Test (optional) Failing after 9m Details
Successful checks
Check Status
✅ CI: Optional E2E Tests / E2E astro-7 Test (optional) Successful in 1m Details
✅ CI: Optional E2E Tests / E2E nuxt-5-sourcemaps Test (optional) Successful in 45s Details
✅ CI: Optional E2E Tests / E2E cloudflare-mastra Test (optional) Successful in 1m Details
✅ CI: Optional E2E Tests / E2E cloudflare-flue-send-to-sentry Test (optional) Successful in 10m Details
✅ CI: Optional E2E Tests / E2E cloudflare-pi-durable Test (optional) Successful in 53s Details
✅ CI: Optional E2E Tests / E2E tanstackstart-react-sourcemaps Test (optional) Successful in 45s Details
✅ CI: Optional E2E Tests / E2E nextjs-16 (vinext, bun) Test (optional) Successful in 2m Details
✅ CI: Optional E2E Tests / E2E react-router-7-framework-instrumentation Test (optional) Successful in 2m Details
✅ CI: Optional E2E Tests / E2E tanstackstart-react-cloudflare Test (optional) Successful in 49s Details
✅ CI: Optional E2E Tests / E2E astro-7-static Test (optional) Successful in 1m Details
✅ CI: Optional E2E Tests / E2E node-openai-decisions (latest) Test (optional) Successful in 45s Details
✅ CI: Optional E2E Tests / E2E nuxt-5 Test (optional) Successful in 2m Details
✅ CI: Optional E2E Tests / E2E node-mastra Test (optional) Successful in 9m Details
✅ CI: Optional E2E Tests / E2E debug-id-sourcemaps Test (optional) Successful in 42s Details
✅ CI: Optional E2E Tests / E2E gen-ai-libraries (cloudflare) Test (optional) Successful in 55s Details
✅ CI: Optional E2E Tests / E2E nuxt-5 (tunnel-dev) Test (optional) Successful in 1m Details
✅ CI: Optional E2E Tests / E2E nestjs-12 (latest) Test (optional) Successful in 1m Details
✅ CI: Optional E2E Tests / E2E gen-ai-libraries Test (optional) Successful in 1m Details
✅ CI: Optional E2E Tests / E2E vue-3 (no Options API) Test (optional) Successful in 1m Details
✅ CI: Optional E2E Tests / E2E nextjs-16 (deno) Test (optional) Successful in 2m Details
✅ CI: Optional E2E Tests / E2E nextjs-15 (turbo) Test (optional) Successful in 12m Details
✅ CI: Optional E2E Tests / E2E nuxt-5-sourcemaps (client source maps kept) Test (optional) Successful in 43s Details
✅ CI: Optional E2E Tests / E2E nextjs-16-tunnel (cloudflare) Test (optional) Successful in 1m Details
✅ CI: Optional E2E Tests / E2E nextjs-15 (latest) Test (optional) Successful in 4m Details
✅ CI: Optional E2E Tests / E2E cloudflare-workers-send-to-sentry Test (optional) Successful in 12m Details
✅ CI: Optional E2E Tests / E2E node-express-mcp-v2 Test (optional) Successful in 13m Details
✅ CI: Optional E2E Tests / E2E node-openai-decisions Test (optional) Successful in 42s Details
✅ CI: Optional E2E Tests / E2E nextjs-14 (latest) Test (optional) Successful in 1m Details
✅ CI: Optional E2E Tests / E2E node-pi-durable (latest) Test (optional) Successful in 54s Details
✅ CI: Optional E2E Tests / E2E cloudflare-think Test (optional) Successful in 1m Details
✅ CI: Optional E2E Tests / E2E gen-ai-libraries (latest) Test (optional) Successful in 1m Details
✅ CI: Optional E2E Tests / E2E cloudflare-agent Test (optional) Successful in 55s Details
✅ CI: Optional E2E Tests / E2E nextjs-16 (vinext) Test (optional) Successful in 2m Details
✅ CI: Optional E2E Tests / E2E react-send-to-sentry Test (optional) Successful in 3m Details
✅ CI: Optional E2E Tests / E2E node-express-send-to-sentry-static Test (optional) Successful in 1m Details
✅ CI: Optional E2E Tests / E2E nextjs-orpc Test (optional) Successful in 1m Details
✅ CI: Optional E2E Tests / E2E deno (latest) Test (optional) Successful in 12m Details
✅ CI: Optional E2E Tests / E2E node-express-mcp-v1 Test (optional) Successful in 40s Details
✅ CI: Optional E2E Tests / E2E node-express-send-to-sentry Test (optional) Successful in 1m Details
✅ CI: Optional E2E Tests / E2E cloudflare-think (ai v6) Test (optional) Successful in 10m Details
✅ CI: Optional E2E Tests / E2E tanstackstart-react (latest) Test (optional) Successful in 1m Details
✅ CI: Optional E2E Tests / E2E supabase-nextjs Test (optional) Successful in 3m Details
✅ CI: Optional E2E Tests / E2E nuxt-5-sourcemaps (static / nuxt generate) Test (optional) Successful in 52s Details
✅ CI: Optional E2E Tests / E2E node-fastify-6 Test (optional) Successful in 44s Details
✅ CI: Optional E2E Tests / E2E nextjs-16 (cloudflare, latest) Test (optional) Successful in 2m Details
✅ CI: Optional E2E Tests / E2E node-flue Test (optional) Successful in 11m Details
✅ CI: Optional E2E Tests / E2E node-pi-durable Test (optional) Successful in 1m Details
✅ CI: Optional E2E Tests / E2E node-mastra (latest) Test (optional) Successful in 1m Details
✅ CI: Optional E2E Tests / E2E solidstart-2 Test (optional) Successful in 1m Details
✅ CI: Optional E2E Tests / E2E node-fastify-6 (tracer provider) Test (optional) Successful in 57s Details

@chargome
chargome marked this pull request as ready for review November 6, 2026 10:28
@chargome
chargome requested review from a team as code owners November 6, 2026 10:28
@chargome
chargome requested review from andreiborza, isaacs, msonnb, mydea, nicohrubec and s1gr1d and removed request for a team, isaacs, msonnb, mydea and s1gr1d November 6, 2026 10:28

@andreiborza andreiborza left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I'd just inline this and avoid the extra function and the eslint disabling

unwrappedFunction = originalFunction;
// `markFunctionWrapped` sets the original as an own property. An inherited lookup could walk a
// prototype chain that loops through a Proxy and overflow the stack, which native `toString` never does.
if (SETUP_CLIENTS.has(getClient() as Client) && hasOwnProperty(this, '__sentry_original__')) {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Suggested change
if (SETUP_CLIENTS.has(getClient() as Client) && hasOwnProperty(this, '__sentry_original__')) {
if (SETUP_CLIENTS.has(getClient() as Client) && Object.prototype.hasOwnProperty.call(this, '__sentry_original__')) {

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

This brings back the exact issue we gave as the reason for closing #25964

Comment on lines +22 to +26
// eslint-disable-next-line @typescript-eslint/unbound-method
const hasOwnProperty = Function.prototype.call.bind(Object.prototype.hasOwnProperty) as (
obj: unknown,
key: PropertyKey,
) => boolean;

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Suggested change
// eslint-disable-next-line @typescript-eslint/unbound-method
const hasOwnProperty = Function.prototype.call.bind(Object.prototype.hasOwnProperty) as (
obj: unknown,
key: PropertyKey,
) => boolean;

@chargome
chargome merged commit 587f05a into develop Nov 6, 2026
754 of 763 checks passed
@chargome
chargome deleted the fix-tostring-cyclic-proxy branch November 6, 2026 10:50
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.

FunctionToString overflows on cyclic Proxy prototype chains

2 participants