Repository navigation
feat(octane): support Trusted Types - #2162
Merged
Merged
Conversation
A TrustedHTML, TrustedScript, or TrustedScriptURL passed to dangerouslySetInnerHTML or an attribute now reaches its DOM sink as the object, as in React 19.3, so it works under an enforced require-trusted-types-for 'script' CSP. Markup Octane parses itself (compiled templates, binding fragments, streamed regions) goes through a module-private `octane` policy, and the streaming bootstrap's JSON carrier through `octane-stream`. Application strings never go through either. Refs #2053. Co-Authored-By: Claude Opus 5.5 <[email protected]>
trueadm
marked this pull request as ready for review
October 20, 2026 11:24
Deploying with
|
| Status | Name | Latest Commit | Preview URL | Updated (UTC) |
|---|---|---|---|---|
| ✅ Deployment successful! View logs |
octane-website-mcp | 80b1285 | Commit Preview URL Branch Preview URL |
Oct 20 2026, 11:42 AM |
Deploying with
|
| Status | Name | Latest Commit | Preview URL | Updated (UTC) |
|---|---|---|---|---|
| ✅ Deployment successful! View logs |
octane-website | 80b1285 | Commit Preview URL Branch Preview URL |
Oct 20 2026, 11:43 AM |
Contributor
Benchmark report
Compares js-framework: 1k/10k row operationsAll 20 timed operations (20 without a verdict)
All 64 work counters are unchanged. Application bundle size (bytes)
15 other measured values are unchanged. Public-import reachability bundles (bytes)
39 other measured values are unchanged. |
…o extra calls The js-framework work gate counted two more calls per template parse in Chromium: frameworkHTML and the policy's `(s) => s` rule. Create the `octane` policy once at module load with the native `String` as its rule and read it inline at each sink, and call trustedOr only for object values, so primitive attribute and HTML writes make no extra call. Co-Authored-By: Claude Opus 5.5 <[email protected]>
This was referenced Oct 20, 2026
Merged
trueadm
added a commit
that referenced
this pull request
Oct 23, 2026
* feat(octane): support Trusted Types Re-lands #2162. It merged into `next` on 2026-10-20, after #2103 had already integrated `next` into `main`, and `next` was then deleted, so the change never reached `main`. This is the #2162 squash commit (424e5cc) cherry-picked onto `main` without changes. A TrustedHTML, TrustedScript, or TrustedScriptURL passed to dangerouslySetInnerHTML or an attribute now reaches its DOM sink as the object, as in React 19.3, so it works under an enforced require-trusted-types-for 'script' CSP. Markup Octane parses itself (compiled templates, binding fragments, streamed regions) goes through a module-private `octane` policy, created at module load with the native `String` as its rule, and the streaming bootstrap's JSON carrier through `octane-stream`. Application strings never go through either. Refs #2053. Co-Authored-By: Claude Opus 5.5 <[email protected]> * test(octane): type the Trusted Types browser fixture main's test config rejects reading a server fixture's export through its index signature, so name the fixture module type, as other tests do. Co-Authored-By: Claude Opus 5.5 <[email protected]> * fix(octane): write changed script text through its Trusted Types sink setScriptText updated an existing Text node in place, so after the first write a TrustedScript never reached the script's textContent sink, and under enforcement a string update was not rejected. An unchanged body still writes nothing; a changed one now always assigns textContent. Co-Authored-By: Claude Opus 5.5 <[email protected]> --------- Co-authored-by: Claude Opus 5.5 <[email protected]>
trueadm
added a commit
that referenced
this pull request
Oct 23, 2026
…aries and deferred activation (#2224) * feat(octane): support Trusted Types Re-lands #2162. It merged into `next` on 2026-10-20, after #2103 had already integrated `next` into `main`, and `next` was then deleted, so the change never reached `main`. This is the #2162 squash commit (424e5cc) cherry-picked onto `main` without changes. A TrustedHTML, TrustedScript, or TrustedScriptURL passed to dangerouslySetInnerHTML or an attribute now reaches its DOM sink as the object, as in React 19.3, so it works under an enforced require-trusted-types-for 'script' CSP. Markup Octane parses itself (compiled templates, binding fragments, streamed regions) goes through a module-private `octane` policy, created at module load with the native `String` as its rule, and the streaming bootstrap's JSON carrier through `octane-stream`. Application strings never go through either. Refs #2053. Co-Authored-By: Claude Opus 5.5 <[email protected]> * test(octane): type the Trusted Types browser fixture main's test config rejects reading a server fixture's export through its index signature, so name the fixture module type, as other tests do. Co-Authored-By: Claude Opus 5.5 <[email protected]> * fix(octane): write changed script text through its Trusted Types sink setScriptText updated an existing Text node in place, so after the first write a TrustedScript never reached the script's textContent sink, and under enforcement a string update was not rejected. An unchanged body still writes nothing; a changed one now always assigns textContent. Co-Authored-By: Claude Opus 5.5 <[email protected]> * test(octane): cover Trusted Types hydration, streamed table/SVG boundaries and deferred activation Run the enforced `require-trusted-types-for 'script'` browser suite, which has no default policy, over the cases the streaming design doc lists: hydrateRoot of renderToString output, a streamed page whose <tbody> and <svg> boundaries reveal after the shell hydrates, and a deferred <Hydrate> boundary that a click activates. Each page then mounts fresh table and SVG content and rewrites its adopted dangerouslySetInnerHTML. A report-only run checks that the same pages raise no violations. Each case passes in dev and prod bundles and fails when the template, stream-bootstrap, setHTML or dev hydration-compare sink writes a string. Co-Authored-By: Claude Opus 5.5 <[email protected]> --------- Co-authored-by: Claude Opus 5.5 <[email protected]>
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.
Summary
TrustedHTML,TrustedScript, orTrustedScriptURLpassed todangerouslySetInnerHTMLor to an attribute (srcdoc, a script'ssrc, SVGxlinkHref, spreads) now reaches the DOM sink as the object instead of its string.octane. The streaming bootstrap's JSON carrier uses its ownoctane-streampolicy. Application strings never go through either policy.Refs #2053. This is the Trusted Types half of the issue; parallel transitions waits for #2043's update queues.
Why
Under
require-trusted-types-for 'script', a string written toinnerHTML, a script's text, or a script URL throws. Before this PR, Octane's first template parse failed under enforcement.setHTMLalso calledString()on applicationTrustedHTML, so even correctly typed values were rejected.Changes
src/trusted-types.ts:FRAMEWORK_POLICYis theoctanepolicy, created once at module load with the nativeStringas its rule. It isnullwithout Trusted Types, or when the policy is refused, in which case the sink reports the violation. Sinks read it inline, so a template parse runs no extra script function.trustedOr(value, text)is called only for object values. It returns the object only when it is a Trusted Types value and sanitizing did not replace its text.runtime/host-props.ts:setHTMLandsetScriptTextpass trusted values toinnerHTMLandtextContent, including the deferred commit ops.setAttribute,setPlainAttribute, andsetURLAttribute(the prod fast paths) pass trusted values tosetAttribute/setAttributeNS.runtime/templates.ts,dom-binding-program.ts, andhydration/stream-receiver.tsparse throughFRAMEWORK_POLICY.hydration/dev-values.tsparses the value it receives, so dev hydration comparison works under enforcement.runtime.server.ts: the$OCTRCJSON carrier createsoctane-streamon first use. This adds about 170 raw bytes to the inline stream runtime, sent only when a boundary is pending.docs/differences-from-react.md, covering the policy names, theTrustedScriptrequirement for<script dangerouslySetInnerHTML>, that only TT objects pass through, and that Float URLs stay strings;octaneminor.Validation
pnpm format:files:check(all changed files)pnpm typecheck:fileson every changed source, test, and fixture filepnpm test: not run locally (machine load rule). Left to CI.tests/conformance/trusted-types.test.ts, 7 cases, passes inoctaneandoctane-prod(14/14). It is modelled on React'strustedTypes-test.internal.js: a faketrustedTypesglobal and spies that assert the identical object reachesinnerHTML,textContent,setAttribute, andsetAttributeNS. It also checks:octanepolicy is created for templates;javascript:TrustedScriptURLis written as the sanitized string;With the
srcchange reverted, the 4 passthrough and policy cases fail.tests/browser/trusted-types/trusted-types.test.ts(octane-events-browser, Chromium, dev and prod bundles) passes 2/2. The page is served with an enforcedrequire-trusted-types-for 'script'; trusted-types octane octane-stream appand no default policy. The test checks:dangerouslySetInnerHTML,srcdoc, and scriptsrc;@tryboundary whose raw HTML contains</template>, which forces the JSON carrier;With the
srcchange reverted, both cases time out. With only the bootstrap change reverted, the streamed boundary never reveals.perf-review:node scripts/perf-review-scan.mjs, 0 candidates. Hot paths touched:setAttribute/setPlainAttribute/setURLAttribute, per attribute write) andsetHTMLgain one inlinetypeof value === 'object'test. Only object values (for exampleURL) calltrustedOr, which costs three nativeisXcalls in browsers with Trusted Types.parseTemplate: once per template, one nativecreateHTMLwhere Trusted Types exists, with no script call.calls_runrose by 2 (the lazyframeworkHTMLplus its(s) => srule). The second commit removes both calls.concise-code:src/trusted-types.ts, shared by four importers: host-props, templates, dom-binding-program, and stream-receiver.FRAMEWORK_POLICYandtrustedOr, each with callers.createPolicythrow without'allow-duplicates'.windowwould let any script use it to launder strings.Risk / follow-ups
preinit/preload, hoisted async scripts inruntime/head.ts) still take strings, as in React.dom-bindings.ts) receive pre-coerced strings.'allow-duplicates'. This is documented.Provenance
agent-authored)🤖 Generated with Claude Code
Need help on this PR? Tag
@codesmith-botwith what you need.Note
Medium Risk
Touches core DOM write paths (innerHTML, attributes, streaming bootstrap) and CSP-sensitive sinks; behavior is well-tested but any mistake could break rendering or weaken URL sanitization for non-TT values.
Overview
Adds Trusted Types support aligned with React 19.3 so apps can run under
require-trusted-types-for 'script'.Application-authored values:
TrustedHTML,TrustedScript, andTrustedScriptURLpassed todangerouslySetInnerHTML, script bodies, and sinks likesrcdoc/ scriptsrc/ SVGxlinkHrefare written to the DOM as the object, notString(value). Sanitized URLs (e.g. blockedjavascript:) still write the string. Ordinary objects keep a single stringify, unlike React’s pass-through for all objects.Framework-generated markup: Compiled templates, binding fragments, and streamed placement HTML parse through a lazy
octanepolicy (frameworkHTML). The streaming bootstrap’s JSON carrier uses a separate inlineoctane-streampolicy in$OCTRC. CSPtrusted-typesmust allow both; app strings never use these policies.Docs mark Trusted Types as implemented (new section in
differences-from-react.md). Conformance and Playwright browser tests cover sinks, hydration, streaming boundaries, and enforced CSP.Reviewed by Cursor Bugbot for commit 0bb7741. Bugbot is set up for automated code reviews on this repo. Configure here.