[flags] land enableTrustedTypesIntegration#540
Closed
everettbu wants to merge 1 commit into
Closed
Conversation
Greptile SummaryThis PR permanently enables the
Confidence Score: 5/5
Important Files Changed
Last reviewed commit: b9b92b9 |
Author
|
Upstream PR was closed or merged. Code is synced via branch mirror. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Mirror of facebook/react#35816
Original author: rickhanlonii
Summary
This flag enables React's integration with the browser Trusted Types API.
The Trusted Types API is a browser security feature that helps prevent DOM-based XSS attacks. When a site enables Trusted Types enforcement via
Content-Security-Policy: require-trusted-types-for 'script', the browser requires that values passed to DOM injection sinks (likeinnerHTML) are typed objects (TrustedHTML,TrustedScript,TrustedScriptURL) created through developer-defined sanitization policies, rather than raw strings.What changed
Previously, React always coerced values to strings (via
'' + value) before passing them to DOM APIs likesetAttributeandinnerHTML. This broke Trusted Types because it converted typed objects into plain strings, which the browser would then reject under Trusted Types enforcement.React now passes values directly to DOM APIs without string coercion, preserving Trusted Types objects so the browser can validate them. This applies to
dangerouslySetInnerHTML, all HTML and SVG attributes, and URL attributes (href,action, etc).Before (broken)
Using Trusted Types with something like
dangerouslySetInnerHTMLwould throw:After (works)
React now passes the TrustedHTML object directly to the DOM without stringifying it:
Non-breaking change