René's URL Explorer Experiment


Title: FunctionToString integration's patched `Function.prototype.toString` throws SecurityError when its realm's browsing context was navigated cross-origin · Issue #21965 · getsentry/sentry-javascript · GitHub

Open Graph Title: FunctionToString integration's patched `Function.prototype.toString` throws SecurityError when its realm's browsing context was navigated cross-origin · Issue #21965 · getsentry/sentry-javascript

X Title: FunctionToString integration's patched `Function.prototype.toString` throws SecurityError when its realm's browsing context was navigated cross-origin · Issue #21965 · getsentry/sentry-javascript

Description: Is there an existing issue for this? I have checked for existing issues I have reviewed the documentation I am using the latest SDK release or the bug is reproducible on master How do you use Sentry? Sentry Saas (sentry.io) Which SDK are...

Open Graph Description: Is there an existing issue for this? I have checked for existing issues I have reviewed the documentation I am using the latest SDK release or the bug is reproducible on master How do you use Sentr...

X Description: Is there an existing issue for this? I have checked for existing issues I have reviewed the documentation I am using the latest SDK release or the bug is reproducible on master How do you use Sentr...

Opengraph URL: https://github.com/getsentry/sentry-javascript/issues/21965

X: @github

direct link

Domain: github.com

IPv4 address: 140.82.114.4


Hey, it has json ld scripts:
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"FunctionToString integration's patched `Function.prototype.toString` throws SecurityError when its realm's browsing context was navigated cross-origin","articleBody":"### Is there an existing issue for this?\n\n- [x] I have checked for existing issues\n- [x] I have reviewed the documentation\n- [x] I am using the latest SDK release or the bug is reproducible on master\n\n### How do you use Sentry?\n\nSentry Saas (sentry.io)\n\n### Which SDK are you using?\n\n@sentry/nuxt (the affected code is in @sentry/core, so all browser SDKs are affected)\n\n### SDK Version\n\n10.34.0 — the affected code is unchanged on current master (`packages/core/src/integrations/functiontostring.ts`)\n\n### Framework Version\n\nNuxt 4 (not framework-specific)\n\n### Description\n\nThe `functionToStringIntegration` (enabled by default) patches `Function.prototype.toString`. The patched function calls `getClient()` → `getCurrentScope()` → `getMainCarrier()` → `getSentryCarrier(GLOBAL_OBJ)` on **every** `.toString()` invocation, which performs a property read of `GLOBAL_OBJ.__SENTRY__`.\n\n`GLOBAL_OBJ` is `globalThis`, which in a `Window` realm is the **WindowProxy** of the realm's browsing context. If that browsing context is later **navigated to a cross-origin document** while code from the old realm can still be invoked (e.g. a still-alive parent window holding references into a same-origin child iframe whose `src` changed to a cross-origin URL), the `__SENTRY__` read on the WindowProxy throws:\n\n```\nSecurityError: Failed to read a named property '__SENTRY__' from 'Window':\nBlocked a frame with origin \"https://app.example.com\" from accessing a cross-origin frame.\n```\n\n(current Chrome wording: `Blocked a restricted frame with origin \"…\" from accessing another frame.`)\n\nBecause the patch is installed on `Function.prototype`, the throw is triggered by *any* third-party script calling `.toString()`. In our production case the chain was: Microsoft Clarity's MutationObserver serialization → Tawk.to's core-js `Function.prototype.toString` wrapper → Facebook Pixel's (`fbevents.js`) core-js `inspectSource` → Sentry's patched `toString` → `SecurityError`, surfacing as `onunhandledrejection` noise (24 events within ~1 second from a single page transition on a page embedding a third-party game iframe with `sandbox=\"... allow-top-navigation\"`).\n\nProduction stack (origins redacted, resolved via source maps):\n\n```\n/0.8.66/clarity.js (async/await machinery, MutationObserver serialization)\n/_s/v4/app/.../twk-chunk-vendors.js  (ShadowRoot.toString — core-js toString wrapper)\n/en_US/fbevents.js  (core-js inspectSource)\n@sentry/core/build/esm/integrations/functiontostring.js:24  (Function.prototype.toString)\n@sentry/core/build/esm/currentScopes.js:101  (getClient)\n@sentry/core/build/esm/currentScopes.js:10   (getCurrentScope)\n@sentry/core/build/esm/carrier.js:18         (getMainCarrier → getSentryCarrier(GLOBAL_OBJ) → __SENTRY__ read throws)\n```\n\nNote: the native `Function.prototype.toString` never throws for these calls — the throw is introduced solely by the integration's internal carrier access, so the SDK converts harmless third-party introspection into uncatchable (for the app) SecurityError noise, which Sentry itself then reports.\n\n### Steps to Reproduce\n\nSelf-contained repro (Chrome). Serve the two files below from `http://127.0.0.1:8801` and also expose the same directory on `http://127.0.0.1:8802` (different port = cross-origin but same-site, any static server works):\n\n`parent.html`:\n\n```html\n\u003c!doctype html>\n\u003ciframe id=\"f\" src=\"/child.html\">\u003c/iframe>\n\u003cscript>\n  const f = document.getElementById('f')\n  let done = false\n  f.onload = () => {\n    if (done) return\n    done = true\n    const childFn = f.contentWindow.exposedFn // keep a reference into the child realm\n    setTimeout(() => { f.src = 'http://127.0.0.1:8802/parent.html' }, 300) // navigate iframe cross-origin\n    setTimeout(() => {\n      try {\n        childFn.toString() // resolves to the child realm's patched Function.prototype.toString\n        console.log('ok')\n      } catch (e) {\n        console.log('THREW', e.name, e.message)\n      }\n    }, 1500)\n  }\n\u003c/script>\n```\n\n`child.html` (stands in for any same-origin frame that initialized a Sentry browser SDK — inlined replica of `functiontostring.ts` + `carrier.ts` so the repro needs no bundler; using the real SDK behaves identically):\n\n```html\n\u003c!doctype html>\n\u003cscript>\n  const SDK_VERSION = '10.34.0'\n  const GLOBAL_OBJ = globalThis\n  function getSentryCarrier(carrier) {\n    const __SENTRY__ = (carrier.__SENTRY__ = carrier.__SENTRY__ || {})\n    __SENTRY__.version = __SENTRY__.version || SDK_VERSION\n    return (__SENTRY__[SDK_VERSION] = __SENTRY__[SDK_VERSION] || {})\n  }\n  function getMainCarrier() { getSentryCarrier(GLOBAL_OBJ); return GLOBAL_OBJ }\n  function getClient() { getMainCarrier(); return undefined }\n  const SETUP_CLIENTS = new WeakMap()\n  const originalFunctionToString = Function.prototype.toString\n  Function.prototype.toString = function (...args) {\n    const originalFunction = this && this.__sentry_original__\n    const context = SETUP_CLIENTS.has(getClient()) && originalFunction !== undefined ? originalFunction : this\n    return originalFunctionToString.apply(context, args)\n  }\n  window.exposedFn = function exposedFn() {}\n\u003c/script>\n```\n\nObserved output:\n\n```\nTHREW SecurityError Failed to read a named property '__SENTRY__' from 'Window': Blocked a restricted frame with origin \"http://127.0.0.1:8801\" from accessing another frame.\n```\n\nThe same read also throws in any other \"realm outlives its document's origin\" situation (Android Chrome same-process cross-origin navigations of the top frame show the same signature).\n\n### Expected Result\n\nThe patched `Function.prototype.toString` should never throw where the native implementation would not. Suggested fix — wrap the patch body, mirroring the defensive style already used around the patch installation:\n\n```ts\nFunction.prototype.toString = function (this: WrappedFunction, ...args: any[]): string {\n  try {\n    const originalFunction = getOriginalFunction(this);\n    const context =\n      SETUP_CLIENTS.has(getClient() as Client) && originalFunction !== undefined ? originalFunction : this;\n    return originalFunctionToString.apply(context, args);\n  } catch {\n    // e.g. SecurityError reading __SENTRY__ off a WindowProxy whose browsing context\n    // was navigated cross-origin — fall back to native behavior\n    return originalFunctionToString.apply(this, args);\n  }\n};\n```\n\nWe've verified (against @sentry/core 10.34.0) that this keeps the unwrap behavior intact for live realms and degrades to exact native semantics otherwise. Happy to open a PR if this direction is acceptable.\n\n### Actual Result\n\n`SecurityError: Failed to read a named property '__SENTRY__' from 'Window': Blocked a frame with origin \"…\" from accessing a cross-origin frame.` thrown out of `Function.prototype.toString`, reported as unhandled-rejection error events.\n","author":{"url":"https://github.com/JT-Well","@type":"Person","name":"JT-Well"},"datePublished":"2026-07-05T06:27:48Z","url":"https://github.com/getsentry/sentry-javascript/issues/21965"}

react-profiling0
react-import-mapreact,react-dom,react-dom/client,react-dom/profiling,react-is,react/compiler-runtime,react/jsx-dev-runtime,react/jsx-runtime,scheduler@b8488ee2c322
route-pattern/_view_fragments/issues/show/:user_id/:repository/:id/issue_layout(.:format)
route-controllervoltron_issues_fragments
route-actionissue_layout
fetch-noncev2:aa9550c3-9e6f-4f89-1be8-20f44c29866f
current-catalog-service-hash81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114
request-idC472:2E648F:63DF8B:87D220:6B0441A0
html-safe-nonce11a57a7b91470e343537ff4cafa199955ffe589d76a8e746f5a878f8c437e428
visitor-payloadeyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJDNDcyOjJFNjQ4Rjo2M0RGOEI6ODdEMjIwOjZCMDQ0MUEwIiwidmlzaXRvcl9pZCI6IjY4NjY4NzY4MTM2Njc0ODQwNjQiLCJyZWdpb25fZWRnZSI6ImlhZCIsInJlZ2lvbl9yZW5kZXIiOiJpYWQifQ==
visitor-hmacfc472fed74c798e0fe501d44fb75f4a2929e684eff683be536071455a1fb98ca
hovercard-subject-tagissue:4811859920
github-keyboard-shortcutsrepository,issues,copilot
google-site-verificationApib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I
octolytics-urlhttps://collector.github.com/github/collect
analytics-location///voltron/issues_fragments/issue_layout
fb:app_id1401488693436528
apple-itunes-appapp-id=1477376905, app-argument=https://github.com/_view_fragments/issues/show/getsentry/sentry-javascript/21965/issue_layout
twitter:imagehttps://opengraph.githubassets.com/0c3d8d3414247726da850438bdc5b08b5ab8ebd765a916f646a1f3d22d765ca0/getsentry/sentry-javascript/issues/21965
twitter:cardsummary_large_image
og:imagehttps://opengraph.githubassets.com/0c3d8d3414247726da850438bdc5b08b5ab8ebd765a916f646a1f3d22d765ca0/getsentry/sentry-javascript/issues/21965
og:image:altIs there an existing issue for this? I have checked for existing issues I have reviewed the documentation I am using the latest SDK release or the bug is reproducible on master How do you use Sentr...
og:image:width1200
og:image:height600
og:site_nameGitHub
og:typeobject
og:author:usernameJT-Well
hostnamegithub.com
expected-hostnamegithub.com
None9185ccfefd80c1ff2d9ddcdb0cd2becf46b5a1efbbf30741a895e4bb8de25e64
turbo-cache-controlno-preview
go-importgithub.com/getsentry/sentry-javascript git https://github.com/getsentry/sentry-javascript.git
octolytics-dimension-user_id1396951
octolytics-dimension-user_logingetsentry
octolytics-dimension-repository_id3328572
octolytics-dimension-repository_nwogetsentry/sentry-javascript
octolytics-dimension-repository_publictrue
octolytics-dimension-repository_is_forkfalse
octolytics-dimension-repository_network_root_id3328572
octolytics-dimension-repository_network_root_nwogetsentry/sentry-javascript
turbo-body-classeslogged-out env-production page-responsive
disable-turbofalse
browser-stats-urlhttps://api.github.com/_private/browser/stats
browser-errors-urlhttps://api.github.com/_private/browser/errors
release06dc448a76fe4751ac1db26524aefa3aa3e889a8
ui-targetfull
theme-color#1e2327
color-schemelight dark
react-app-nameissues

Links:

Skip to contenthttps://github.com/getsentry/sentry-javascript/issues/21965#start-of-content
https://github.com/
Sign inhttps://github.com/login?return_to=https%3A%2F%2Fgithub.com%2Fgetsentry%2Fsentry-javascript%2Fissues%2F21965
GitHubRepository hosting, code review, and collaborationhttps://github.com/platform
CopilotAI coding agent for tasks, projects, and automated workhttps://github.com/features/copilot
ActionsCI/CD and automationhttps://github.com/features/actions
Code QualityQuality analysis, fixes, and enforcementhttps://github.com/features/code-quality
CodespacesCloud development environmentshttps://github.com/features/codespaces
Code SecurityVulnerability detection and remediationhttps://github.com/security/advanced-security/code-security
Secret ProtectionSecret scanning and leak preventionhttps://github.com/security/advanced-security/secret-protection
All Featureshttps://github.com/features
Documentationhttps://docs.github.com/en
Traininghttps://learn.github.com/skills
Certificationshttps://learn.github.com/credentials
Build with Copilothttps://github.com/features/ai
Customize Copilothttps://docs.github.com/en/copilot/how-tos/copilot-on-github/customize-copilot/customize-copilot-overview
Integrationshttps://github.com/marketplace
Trending reposhttps://github.com/trending
GitHub Sponsorshttps://github.com/open-source/sponsors
Developer articleshttps://github.com/resources/articles
ChangelogYour source for the latest features, improvements, and fixes across GitHub products, all in one place.https://github.blog/changelog/
Enterpriseshttps://github.com/enterprise
Teamhttps://github.com/team
Startupshttps://github.com/enterprise/startups
Nonprofitshttps://github.com/solutions/industry/nonprofits
Healthcarehttps://github.com/solutions/industry/healthcare
Financial serviceshttps://github.com/solutions/industry/financial-services
Manufacturinghttps://github.com/solutions/industry/manufacturing
Governmenthttps://github.com/solutions/industry/government
See all industrieshttps://github.com/solutions/industry
Why GitHubhttps://github.com/why-github
Customer Storieshttps://github.com/customer-stories
Business insightshttps://github.com/solutions/executive-insights
Trust Centerhttps://github.com/trust-center
GitHub Advanced SecurityEnterprise-grade code securityhttps://github.com/security/advanced-security
Copilot for businessEnterprise-grade AI featureshttps://github.com/features/copilot/copilot-business
Premium SupportEnterprise-grade 24/7 supporthttps://github.com/enterprise/premium-support
Documentationhttps://docs.github.com/en
Resource centerhttps://github.com/resources
Bloghttps://github.blog/
Events & webinarshttps://github.com/resources/events
Community Forumhttps://github.com/orgs/community/discussions
Customer Storieshttps://github.com/customer-stories
Integrationshttps://github.com/marketplace
Customer supporthttps://help.github.com/
Traininghttps://learn.github.com/skills
GitHub Statushttps://www.githubstatus.com/
Abouthttps://github.com/about
Partnershttps://github.com/partners
Changeloghttps://github.blog/changelog/
GitHub UniverseThe event for developers, by developers — talks, workshops, and what’s next for GitHub.https://githubuniverse.com/
Pricinghttps://github.com/pricing
Sign inhttps://github.com/login?return_to=https%3A%2F%2Fgithub.com%2Fgetsentry%2Fsentry-javascript%2Fissues%2F21965
Sign uphttps://github.com/signup?ref_cta=Sign+up&ref_loc=header+logged+out&ref_page=%2F%3Cuser-name%3E%2F%3Crepo-name%3E%2Fvoltron%2Fissues_fragments%2Fissue_layout&source=header-repo&source_repo=getsentry%2Fsentry-javascript
Reloadhttps://github.com/getsentry/sentry-javascript/issues/21965
Reloadhttps://github.com/getsentry/sentry-javascript/issues/21965
Reloadhttps://github.com/getsentry/sentry-javascript/issues/21965
getsentryhttps://github.com/getsentry
sentry-javascripthttps://github.com/getsentry/sentry-javascript
Codehttps://github.com/getsentry/sentry-javascript
Issues339 (339)https://github.com/getsentry/sentry-javascript/issues
Pull requests53 (53)https://github.com/getsentry/sentry-javascript/pulls
Discussionshttps://github.com/getsentry/sentry-javascript/discussions
Actionshttps://github.com/getsentry/sentry-javascript/actions
Security and quality7 (7)https://github.com/getsentry/sentry-javascript/security
Insightshttps://github.com/getsentry/sentry-javascript/insights
https://github.com/getsentry/sentry-javascript
New issuehttps://github.com/login?return_to=https://github.com/getsentry/sentry-javascript/issues/21965
New issuehttps://github.com/login?return_to=https://github.com/getsentry/sentry-javascript/issues/21965
#22273https://github.com/getsentry/sentry-javascript/pull/22273
FunctionToString integration's patched Function.prototype.toString throws SecurityError when its realm's browsing context was navigated cross-originhttps://github.com/getsentry/sentry-javascript/issues/21965#top
#22273https://github.com/getsentry/sentry-javascript/pull/22273
https://github.com/mydea
Browserhttps://github.com/getsentry/sentry-javascript/issues?q=state%3Aopen%20label%3A%22Browser%22
Bughttps://github.com/getsentry/sentry-javascript/issues?q=state%3Aopen%20label%3A%22Bug%22
Nuxthttps://github.com/getsentry/sentry-javascript/issues?q=state%3Aopen%20label%3A%22Nuxt%22
https://github.com/JT-Well
JT-Wellhttps://github.com/JT-Well
on Jul 5, 2026https://github.com/getsentry/sentry-javascript/issues/21965#issue-4811859920
getsantryhttps://github.com/apps/getsantry
Waiting for: Product Ownerhttps://github.com/getsentry/sentry-javascript/issues?q=state%3Aopen%20label%3A%22Waiting%20for%3A%20Product%20Owner%22
on Jul 5, 2026https://github.com/getsentry/sentry-javascript/issues/21965#event-27569078195
https://github.com/apps/linear-code
linear-codehttps://github.com/apps/linear-code
on Jul 5, 2026https://github.com/getsentry/sentry-javascript/issues/21965#issuecomment-4885093838
Linear Codehttps://linear.app
JS-2926https://linear.app/getsentry/issue/JS-2926
getsantryhttps://github.com/apps/getsantry
GitHub Issues with 👀 3https://github.com/orgs/getsentry/projects/227
on Jul 5, 2026https://github.com/getsentry/sentry-javascript/issues/21965#event-27569078892
getsantryhttps://github.com/apps/getsantry
GitHub Issues with 👀 3https://github.com/orgs/getsentry/projects/227
on Jul 5, 2026https://github.com/getsentry/sentry-javascript/issues/21965
github-actionshttps://github.com/apps/github-actions
Nuxthttps://github.com/getsentry/sentry-javascript/issues?q=state%3Aopen%20label%3A%22Nuxt%22
on Jul 5, 2026https://github.com/getsentry/sentry-javascript/issues/21965#event-27569079106
linear-codehttps://github.com/apps/linear-code
Bughttps://github.com/getsentry/sentry-javascript/issues?q=state%3Aopen%20label%3A%22Bug%22
Browserhttps://github.com/getsentry/sentry-javascript/issues?q=state%3Aopen%20label%3A%22Browser%22
on Jul 5, 2026https://github.com/getsentry/sentry-javascript/issues/21965#event-27569085151
JPeer264https://github.com/JPeer264
on Jul 6, 2026https://github.com/getsentry/sentry-javascript/issues/21965#event-27593371344
https://github.com/JPeer264
JPeer264https://github.com/JPeer264
on Jul 6, 2026https://github.com/getsentry/sentry-javascript/issues/21965#issuecomment-4891005345
@JT-Wellhttps://github.com/JT-Well
getsantryhttps://github.com/apps/getsantry
Waiting for: Product Ownerhttps://github.com/getsentry/sentry-javascript/issues?q=state%3Aopen%20label%3A%22Waiting%20for%3A%20Product%20Owner%22
on Jul 6, 2026https://github.com/getsentry/sentry-javascript/issues/21965#event-27598360609
getsantryhttps://github.com/apps/getsantry
GitHub Issues with 👀 3https://github.com/orgs/getsentry/projects/227
on Jul 6, 2026https://github.com/getsentry/sentry-javascript/issues/21965
JPeer264https://github.com/JPeer264
JT-Wellhttps://github.com/JT-Well
on Jul 6, 2026https://github.com/getsentry/sentry-javascript/issues/21965#event-27598362759
mydeahttps://github.com/mydea
on Jul 15, 2026https://github.com/getsentry/sentry-javascript/issues/21965#event-28010791471
fix(core): Prevent functionToStringIntegration from throwing on cross…https://github.com/getsentry/sentry-javascript/commit/814aa1d9f14f04841a43711447799ce7dd5530df
https://docs.github.com/articles/closing-issues-via-commit-messages
814aa1dhttps://github.com/getsentry/sentry-javascript/commit/814aa1d9f14f04841a43711447799ce7dd5530df
mydeahttps://github.com/mydea
mydeahttps://github.com/mydea
JPeer264https://github.com/JPeer264
JT-Wellhttps://github.com/JT-Well
on Jul 15, 2026https://github.com/getsentry/sentry-javascript/issues/21965#event-28010878468
mydeahttps://github.com/mydea
on Jul 17, 2026https://github.com/getsentry/sentry-javascript/issues/21965#event-28109289549
fix(core): Prevent functionToStringIntegration from throwing on cross…https://github.com/getsentry/sentry-javascript/commit/352266199adb82af024b489483d37e94a2a17e81
https://docs.github.com/articles/closing-issues-via-commit-messages
3522661https://github.com/getsentry/sentry-javascript/commit/352266199adb82af024b489483d37e94a2a17e81
mydeahttps://github.com/mydea
completedhttps://github.com/getsentry/sentry-javascript/issues?q=is%3Aissue%20state%3Aclosed%20archived%3Afalse%20reason%3Acompleted
#22273https://github.com/getsentry/sentry-javascript/pull/22273
on Jul 17, 2026https://github.com/getsentry/sentry-javascript/issues/21965#event-28109289594
https://github.com/apps/github-actions
github-actionshttps://github.com/apps/github-actions
on Jul 20, 2026https://github.com/getsentry/sentry-javascript/issues/21965#issuecomment-5022212721
GitHub Actionshttps://help.github.com/en/actions
#22273https://github.com/getsentry/sentry-javascript/pull/22273
10.67.0 releasehttps://github.com/getsentry/sentry-javascript/releases/tag/10.67.0
Lms24https://github.com/Lms24
on Jul 23, 2026https://github.com/getsentry/sentry-javascript/issues/21965#event-28369390571
fix(core): Avoid `functionToStringIntegration` causing infinite recur…https://github.com/getsentry/sentry-javascript/commit/567ee91d00aba2881ee69c43d2d87334efa94e87
567ee91https://github.com/getsentry/sentry-javascript/commit/567ee91d00aba2881ee69c43d2d87334efa94e87
Sign up for freehttps://github.com/signup?return_to=https://github.com/getsentry/sentry-javascript/issues/21965
Sign in to commenthttps://github.com/login?return_to=https://github.com/getsentry/sentry-javascript/issues/21965
mydeahttps://github.com/mydea
Browserhttps://github.com/getsentry/sentry-javascript/issues?q=state%3Aopen%20label%3A%22Browser%22
Bughttps://github.com/getsentry/sentry-javascript/issues?q=state%3Aopen%20label%3A%22Bug%22
Nuxthttps://github.com/getsentry/sentry-javascript/issues?q=state%3Aopen%20label%3A%22Nuxt%22
GitHub Issues with 👀 3https://github.com/orgs/getsentry/projects/227
https://github.com
Termshttps://docs.github.com/site-policy/github-terms/github-terms-of-service
Privacyhttps://docs.github.com/site-policy/privacy-policies/github-privacy-statement
Securityhttps://github.com/security
Statushttps://www.githubstatus.com/
Communityhttps://github.community/
Docshttps://docs.github.com/
Contacthttps://support.github.com?tags=dotcom-footer

Response headers:
Servergithub.com
Content-Typetext/html; charset=utf-8
Cache-Controlmax-age=0, private, must-revalidate

Viewport: width=device-width


URLs of crawlers that visited me.