GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — fix(core): Read __sentry_original__ as own property to avoid overflow on cyclic Proxy prototype chains by chiliec · Pull Request #25964 · getsentry/sentry-javascript

Conversation

@chiliec

@chiliec chiliec commented Oct 30, 2026

Copy link
Copy Markdown
Contributor

Fixes #25963

What

functionToStringIntegration patches Function.prototype.toString to return the original source for wrapped functions. The wrapper calls getOriginalFunction(this), which reads this.__sentry_original__. For a function that does not have that own property, the read walks the prototype chain. If the chain loops back through a Proxy, the walk never terminates and overflows the stack inside the wrapper frame, while native toString returns normally for the same function. Anti-tamper/fingerprinting probes (e.g. Castle bot detection) use exactly this kind of cyclic-proxy probe to detect patched natives.

This remained after #25921 / #25922, which fixed the apply re-entry and huge-argument-list overflows — not this property lookup.

Fix

markFunctionWrapped always sets __sentry_original__ as an own non-enumerable property, so reading it as an own property is equivalent for every legitimately wrapped function and avoids the unbounded prototype-chain walk:

return Object.prototype.hasOwnProperty.call(func, '__sentry_original__') ? func.__sentry_original__ : undefined;

Tests

Added a regression test to the existing FunctionToString suite that gives a function a prototype chain looping through a Proxy and asserts the patched toString (invoked via the bound Function.prototype.call form, as the reported probe does) returns the native result instead of overflowing.

Validation (local):

cd packages/core
pnpm vitest run test/lib/integrations/functiontostring.test.ts test/lib/utils/object.test.ts
  • RED (before the fix): does not overflow the stack when the prototype chain loops through a Proxy fails with RangeError: Maximum call stack size exceeded at getOriginalFunction (src/utils/object.ts).
  • GREEN (after the fix): Test Files 2 passed (2), Tests 46 passed (46) — the new test plus all existing functiontostring and object tests pass.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
@chiliec
chiliec requested review from a team as code owners October 30, 2026 17:36
@chiliec
chiliec requested review from isaacs, logaretm, msonnb and mydea and removed request for a team October 30, 2026 17:36
@chiliec
fix(core): Read __sentry_original__ as an own property in getOriginal…
78f76f3
…Function

The FunctionToString integration's patched toString reads this.__sentry_original__
via getOriginalFunction, which walks the prototype chain for a function that lacks
the own property. When the chain loops back through a Proxy the walk never
terminates and overflows the stack inside the wrapper, while native toString
returns normally. markFunctionWrapped always sets __sentry_original__ as an own
non-enumerable property, so reading it as an own property is equivalent for every
wrapped function and avoids the unbounded prototype walk.

Signed-off-by: Vladimir Babin <[email protected]>
@chiliec
chiliec requested review from nicohrubec and removed request for a team October 30, 2026 17:36
@chiliec
chiliec force-pushed the fix/functiontostring-cyclic-proxy-prototype branch from bee0f9d to 78f76f3 Compare October 30, 2026 17:36
@github-actions github-actions Bot added the external PR from an external contributor label Oct 30, 2026
cursor[bot]
cursor Bot reviewed Oct 30, 2026
View reviewed changes

@cursor cursor Bot left a comment

Copy link
Copy Markdown

There was a problem hiding this comment.

Choose a reason for hiding this comment

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

Cursor Bugbot has reviewed your changes and found 1 potential issue.

Fix All in Cursor

❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.

Want reviews to match your repository better? Bugbot Learning can learn team-specific rules from PR activity. A team admin can enable Learning in the Cursor dashboard.

Reviewed by Cursor Bugbot for commit 78f76f3. Configure here.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
Comment thread packages/core/test/lib/integrations/functiontostring.test.ts
getClient()?.addIntegration(fts);

expect(callToString(inspectedFunction)).toBe(expected);
});

@cursor cursor Bot Oct 30, 2026

Copy link
Copy Markdown

There was a problem hiding this comment.

Choose a reason for hiding this comment

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

Regression test skips patched toString

Low Severity

The new test binds Function.prototype.toString before addIntegration, so callToString keeps the native function when this case runs first or alone. That path never enters getOriginalFunction and can pass without the overflow fix. Flagged from the review rules: a fix PR's regression test needs to fail without the change.

Fix in Cursor Fix in Web

Triggered by project rule: PR Review Guidelines for Cursor Bot

Reviewed by Cursor Bugbot for commit 78f76f3. Configure here.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
logaretm
logaretm requested changes Oct 30, 2026
View reviewed changes

@logaretm logaretm left a comment

Copy link
Copy Markdown
Member

There was a problem hiding this comment.

Choose a reason for hiding this comment

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

Thanks for digging into this! Per our contributing guide, we would have appreciated a discussion first before taking it on, since we shipped two PRs in this area.

I'm closing this because Object.prototype.hasOwnProperty.call looks up .call every time it runs, so a page that hooks Function.prototype.call sends the wrapper into infinite recursion again, which is the same kind of re-entry #25921 fixed.

Here is an example:

// e.g. an anti-tamper or call-tracing script
Function.prototype.call = function (thisArg, ...args) {
  const isNative = this.toString().includes('[native code]');
  return Reflect.apply(this, thisArg, args);
};

setTimeout.toString(); // RangeError: Maximum call stack size exceeded

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
@logaretm logaretm closed this Oct 30, 2026
@chargome chargome mentioned this pull request Nov 6, 2026
fix(core): Avoid stack overflow in FunctionToString on cyclic Proxy prototype chains #26162
Merged
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Reviewers

@cursor cursor[bot] cursor[bot] left review comments
@logaretm logaretm logaretm requested changes
@msonnb msonnb Awaiting requested review from msonnb msonnb was automatically assigned from getsentry/team-javascript-sdks-browser
@isaacs isaacs Awaiting requested review from isaacs isaacs was automatically assigned from getsentry/team-javascript-sdks-server
@mydea mydea Awaiting requested review from mydea mydea was automatically assigned from getsentry/team-javascript-sdks-server
@nicohrubec nicohrubec Awaiting requested review from nicohrubec nicohrubec was automatically assigned from getsentry/team-javascript-sdks-framework

Uh oh!

There was an error while loading. Please reload this page.

Assignees

No one assigned

Labels

external PR from an external contributor

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

FunctionToString overflows on cyclic Proxy prototype chains

Uh oh!

There was an error while loading. Please reload this page.

2 participants

@chiliec @logaretm
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
You are visitor 01402775 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.