Skip to content

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

Closed
alan-agius4 wants to merge 4 commits into
angular:mainfrom
alan-agius4:svg-a-link
Closed

fix(compiler): sanitize dynamic href and xlink:href bindings on SVG a…#68868
alan-agius4 wants to merge 4 commits into
angular:mainfrom
alan-agius4:svg-a-link

Conversation

@alan-agius4
Copy link
Copy Markdown
Contributor

… 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.

@alan-agius4 alan-agius4 requested a review from AndrewKushnir May 21, 2026 18:51
@alan-agius4 alan-agius4 added action: review The PR is still awaiting reviews from at least one requested reviewer target: rc This PR is targeted for the next release-candidate labels May 21, 2026
@pullapprove pullapprove Bot requested a review from josephperrott May 21, 2026 18:51
@angular-robot angular-robot Bot added the area: compiler Issues related to `ngc`, Angular's template compiler label May 21, 2026
@ngbot ngbot Bot added this to the Backlog milestone May 21, 2026
Copy link
Copy Markdown
Contributor

@AndrewKushnir AndrewKushnir left a comment

Choose a reason for hiding this comment

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

@alan-agius4 thanks for the improvement! I've left a comment with a proposed refactoring, but please don't treat it as blocking.

Comment thread packages/compiler/src/schema/dom_element_schema_registry.ts Outdated
… 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.
…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.
…text lookup

Normalize namespaced tag names (e.g., :xhtml:a to a) inside i18nResolveSanitizer before looking up their security context. This ensures custom namespaced tag attributes undergo correct translation sanitization at runtime.
Copy link
Copy Markdown
Member

@josephperrott josephperrott left a comment

Choose a reason for hiding this comment

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

LGTM

Reviewed-for: fw-security

Copy link
Copy Markdown
Member

@pkozlowski-opensource pkozlowski-opensource left a comment

Choose a reason for hiding this comment

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

LGTM

Reviewed-for: fw-security

@alan-agius4 alan-agius4 removed the request for review from alxhub May 27, 2026 14:01
@alan-agius4 alan-agius4 added action: merge The PR is ready for merge by the caretaker and removed action: review The PR is still awaiting reviews from at least one requested reviewer labels May 27, 2026
@alxhub
Copy link
Copy Markdown
Member

alxhub commented May 27, 2026

This PR was merged into the repository. The changes were merged into the following branches:

@alxhub alxhub closed this in 75033d2 May 27, 2026
alxhub pushed a commit that referenced this pull request May 27, 2026
…ntSchemaRegistry (#68868)

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.

PR Close #68868
alxhub pushed a commit that referenced this pull request May 27, 2026
…text lookup (#68868)

Normalize namespaced tag names (e.g., :xhtml:a to a) inside i18nResolveSanitizer before looking up their security context. This ensures custom namespaced tag attributes undergo correct translation sanitization at runtime.

PR Close #68868
alxhub pushed a commit that referenced this pull request May 27, 2026
… elements (#68868)

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.

PR Close #68868
alxhub pushed a commit that referenced this pull request May 27, 2026
…ntSchemaRegistry (#68868)

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.

PR Close #68868
alxhub pushed a commit that referenced this pull request May 27, 2026
…text lookup (#68868)

Normalize namespaced tag names (e.g., :xhtml:a to a) inside i18nResolveSanitizer before looking up their security context. This ensures custom namespaced tag attributes undergo correct translation sanitization at runtime.

PR Close #68868
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

action: merge The PR is ready for merge by the caretaker area: compiler Issues related to `ngc`, Angular's template compiler area: core Issues related to the framework runtime area: zones Issues related to zone.js target: rc This PR is targeted for the next release-candidate

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Security regression: SVG <a [attr.href]> skips URL sanitizer in 22.0.0-rc.1 (@next) and main HEAD

5 participants