Skip to content

🐛 Restore sanitize toJSON hooks after failures#4750

Merged
watson merged 1 commit into
mainfrom
watson/fix-sanitize
Jun 8, 2026
Merged

🐛 Restore sanitize toJSON hooks after failures#4750
watson merged 1 commit into
mainfrom
watson/fix-sanitize

Conversation

@watson
Copy link
Copy Markdown
Collaborator

@watson watson commented Jun 8, 2026

Motivation

sanitize() temporarily detaches Object.prototype.toJSON and Array.prototype.toJSON while cloning customer-provided data.

If sanitization throws before the normal return path, for example while reading an enumerable getter, those prototype toJSON methods were not restored. This can leave page prototypes modified after a failed sanitization attempt and affect later serialization.

Changes

Wrap the sanitizer traversal in a try/finally so detached prototype toJSON methods are restored on both success and failure paths.

Add a regression test covering a throwing getter while Object.prototype.toJSON is detached.

Test instructions

Run:

yarn test:unit --spec packages/browser-core/src/tools/serialisation/sanitize.spec.ts

Checklist

  • Tested locally
  • Tested on staging
  • Added unit tests for this change.
  • Added e2e/integration tests for this change.
  • Updated documentation and/or relevant AGENTS.md file

sanitize() temporarily detaches Object.prototype.toJSON and
Array.prototype.toJSON while cloning customer-provided data. If sanitization
throws while reading a hostile getter, those prototype methods were not restored.

Wrap the sanitizer traversal in a try/finally so prototype toJSON methods are
restored on both success and failure paths.

Add a regression test that verifies prototype toJSON restoration after a
sanitization failure.
@watson watson requested a review from a team as a code owner June 8, 2026 12:45
Copy link
Copy Markdown
Collaborator Author

watson commented Jun 8, 2026

This stack of pull requests is managed by Graphite. Learn more about stacking.

@cit-pr-commenter-54b7da
Copy link
Copy Markdown

Bundles Sizes Evolution

📦 Bundle Name Base Size Local Size 𝚫 𝚫% Status
Rum 171.86 KiB 171.88 KiB +27 B +0.02%
Rum Profiler 7.88 KiB 7.88 KiB 0 B 0.00%
Rum Recorder 21.21 KiB 21.21 KiB 0 B 0.00%
Logs 54.31 KiB 54.34 KiB +27 B +0.05%
Rum Slim 129.69 KiB 129.72 KiB +27 B +0.02%
Worker 22.96 KiB 22.96 KiB 0 B 0.00%

@datadog-prod-us1-5
Copy link
Copy Markdown

datadog-prod-us1-5 Bot commented Jun 8, 2026

Tests

🎉 All green!

🧪 All tests passed
❄️ No new flaky tests detected

🎯 Code Coverage (details)
Patch Coverage: 81.25%
Overall Coverage: 76.78% (+0.00%)

This comment will be updated automatically if new data arrives.
🔗 Commit SHA: 80c9a84 | Docs | Datadog PR Page | Give us feedback!

@watson watson mentioned this pull request Jun 8, 2026
5 tasks
@watson watson merged commit 0543fc8 into main Jun 8, 2026
31 checks passed
@watson watson deleted the watson/fix-sanitize branch June 8, 2026 13:02
@github-actions github-actions Bot locked and limited conversation to collaborators Jun 8, 2026
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants