Skip to content

fix(compiler): emit the sanitizers ngtsc adds since 22.0.1 - #608

Open
GabeSilvaDev wants to merge 1 commit into
voidzero-dev:mainfrom
GabeSilvaDev:fix/sanitizer-parity
Open

GabeSilvaDev wants to merge 1 commit into
voidzero-dev:mainfrom
GabeSilvaDev:fix/sanitizer-parity

Conversation

@GabeSilvaDev

@GabeSilvaDev GabeSilvaDev commented Oct 22, 2026 •

Copy link
Copy Markdown
Contributor

Summary

Several bindings that ngtsc sanitizes compile without a sanitizer in OXC. Two of the gaps are direct XSS sinks in the compiled app:

<div [(innerHTML)]="userHtml"></div>
// A directive whose selector has no URL sink, applied to an <a> or <iframe>
// through hostDirectives, inheritance or createComponent({hostElement}).
@Directive({ selector: 'div[link]', host: { '[href]': 'url' } })

OXC on main:

i0.ɵɵtwoWayProperty("innerHTML", ctx.userHtml);
i0.ɵɵdomProperty("href", ctx.url);

ngc 22.2.2, and OXC with this change:

i0.ɵɵtwoWayProperty("innerHTML", ctx.userHtml, i0.ɵɵsanitizeHtml);
i0.ɵɵdomProperty("href", ctx.url, i0.ɵɵsanitizeUrlOrResourceUrl);

Most of these are upstream fixes from 22.0.1 on that the port had not picked up yet. Each one is gated on the releases that shipped it, like the existing schema versions:

Upstream change First released in OXC change
Sanitize two-way properties (angular/angular@3c70270c96) 20.3.25, 21.2.17, 22.0.1, 22.1.0-next.0 resolve_sanitizers handles TwoWayProperty ops.
Sanitize host bindings on concrete hosts (angular/angular@d06e3748b7) 20.3.28, 21.2.20, 22.1.0, 22.2.0-next.0 host_binding_security_context_for ports calcHostBindingSecurityContexts: the binding is checked against every known element, and NONE next to a URL kind gives ɵɵsanitizeUrlOrResourceUrl.
href / xlink:href of any MathML element (angular/angular@3927a5b271) 22.0.1, 22.1.0-next.0 New V22_0_1 schema kind with a :math:* key; lookups try the namespace's * key.
Namespace fallback in checkSecurityContext (angular/angular@32d7315094) and iframe credentialless (angular/angular@0152e3cbdf) 22.0.2, 22.1.0-next.1 New V22_0_2 schema kind: <svg><iframe [src]> falls back to `iframe
SVG animation elements outside <svg> (angular/angular@7168bed663) 22.1.5, 22.2.0-next.5 Profile flag that looks a bare tag up in the SVG keys last.

Static attributes (ɵɵtrustConstantHtml / ɵɵtrustConstantResourceUrl) and resolveI18nAttrSanitizers were ported in #598, so this PR no longer touches them.

html_to_r3 and dom_security_schema tests that asserted the old latest-version behavior now pin the version they describe. The selector-parsing tests check the declaring-selector half of the host lookup directly. The linker test whose comment said concrete host contexts were not ported now asserts both sides.

Tests

  • tests/sanitizer_parity_test.rs checks each fix against ngc 22.2.2 output, on the first fixed release of each line and on the release just before it.
  • security_backports_follow_each_release_line covers the version cutoffs, prereleases included.
  • regressions/sanitizer-parity.fixture.ts adds 12 e2e compare fixtures. All 12 fail on main and match ngc 22.2.2 with this change (known-difference only for the ɵsetClassDebugInfo filePath, like every other fixture). Across all 1227 fixtures nothing else changes status.
  • cargo fmt --all -- --check, cargo test --all-features (3485 passed) and cargo run -p oxc_angular_conformance (1264/1264, no snapshot diff) all pass.

Copilot AI balanced review requested due to automatic review settings October 22, 2026 03:36

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

An organization owner can choose the repository organization as the billing source for reviews requested by members with a paid Copilot license. Learn about Copilot code review billing. Review the Copilot code review billing settings.

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Oct 22, 2026 •

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ⚠️ Failed 2026-10-22T03:39:23.894431Z
We couldn’t complete this review. Comment @codex review to try again.
bdb3f5f PR opened
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

Port the sanitization fixes Angular shipped from 22.0.1 on, each gated on
the releases that got it upstream:

- sanitize two-way property bindings (angular/angular@3c70270c96)
- check host bindings against every concrete host element, so a selector
  without a URL sink no longer drops the sanitizer (angular/angular@d06e3748b7)
- treat href / xlink:href of any MathML element as a URL
  (angular/angular@3927a5b271)
- fall back from the :svg: / :math: keys to the HTML keys and validate
  iframe credentialless (angular/angular@32d7315094, angular/angular@0152e3cbdf)
- look an <animate> outside <svg> up in the SVG keys
  (angular/angular@7168bed663)
@GabeSilvaDev GabeSilvaDev changed the title fix(compiler): emit the sanitizers and trusted constants ngtsc adds fix(compiler): emit the sanitizers ngtsc adds since 22.0.1 Oct 22, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants