Skip to content

fix(compiler): sanitize dynamic href and xlink:href bindings on SVG a…#68870

Open
alan-agius4 wants to merge 2 commits into
angular:21.2.xfrom
alan-agius4:backport-svg-a-link-21.2.x
Open

fix(compiler): sanitize dynamic href and xlink:href bindings on SVG a…#68870
alan-agius4 wants to merge 2 commits into
angular:21.2.xfrom
alan-agius4:backport-svg-a-link-21.2.x

Conversation

@alan-agius4
Copy link
Copy Markdown
Contributor

@alan-agius4 alan-agius4 commented May 21, 2026

… elements

Dynamic bindings to href and xlink:href attributes on SVG <a> elements (<svg:a>) were previously unmapped in the DOM security schema. As a result, they bypassed sanitization completely, creating a potential XSS vulnerability if bound to untrusted user inputs (e.g., javascript: URLs).

This fix mitigates this risk by:

  1. Registering href and xlink:href on <svg:a> elements under the SecurityContext.URL context in both the compiler and core DOM security schemas.

  2. Enabling template compilation to output runtime URL sanitization checks (ɵɵsanitizeUrl) on these attributes.

  3. Adding regression and verification test cases to ensure dynamic SVG link bindings are safely sanitized at runtime while static values are correctly allowed.

… elements

Dynamic bindings to `href` and `xlink:href` attributes on SVG `<a>` elements (`<svg:a>`) were previously unmapped in the DOM security schema. As a result, they bypassed sanitization completely, creating a potential XSS vulnerability if bound to untrusted user inputs (e.g., `javascript:` URLs).

This fix mitigates this risk by:

1. Registering `href` and `xlink:href` on `<svg:a>` elements under the `SecurityContext.URL` context in both the compiler and core DOM security schemas.

2. Enabling template compilation to output runtime URL sanitization checks (`ɵɵsanitizeUrl`) on these attributes.

3. Adding regression and verification test cases to ensure dynamic SVG link bindings are safely sanitized at runtime while static values are correctly allowed.

# Conflicts:
#	packages/core/src/sanitization/dom_security_schema.ts
@alan-agius4 alan-agius4 added the target: patch This PR is targeted for the next patch release label May 21, 2026
@pullapprove pullapprove Bot requested review from atscott and josephperrott May 21, 2026 19:40
@angular-robot angular-robot Bot added the area: compiler Issues related to `ngc`, Angular's template compiler label May 21, 2026
@alan-agius4 alan-agius4 requested review from AndrewKushnir and removed request for atscott May 21, 2026 19:40
@ngbot ngbot Bot added this to the Backlog milestone May 21, 2026
@alan-agius4 alan-agius4 added the action: review The PR is still awaiting reviews from at least one requested reviewer label May 21, 2026
…ntSchemaRegistry

Custom XML/XHTML namespaced elements (e.g., <xhtml:a>) fall back to the standard HTML namespace during element creation at compile-time/runtime. However, their property and security context lookups inside the schema registry were incorrectly performed using the full namespaced tag name (e.g., :xhtml:a), which bypassed the default a|href sanitization registry and incorrectly returned SecurityContext.NONE instead of SecurityContext.URL.

This commit introduces tag name normalization inside DomElementSchemaRegistry for custom namespaces (other than the built-in svg and math namespaces). Custom namespaced tag names are now normalized to their simple HTML element counterparts for all registry queries, ensuring that correct property schema validation and dynamic security sanitization rules (such as URL sanitization) are enforced at runtime.
@alan-agius4 alan-agius4 force-pushed the backport-svg-a-link-21.2.x branch from 8bcb469 to 1d41249 Compare May 22, 2026 09:30
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

action: review The PR is still awaiting reviews from at least one requested reviewer area: compiler Issues related to `ngc`, Angular's template compiler target: patch This PR is targeted for the next patch release

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants