Skip to content

fix(compiler): disallow i18n event attributes#68821

Open
Hexix23 wants to merge 1 commit into
angular:mainfrom
Hexix23:fix-i18n-event-attrs-validation
Open

fix(compiler): disallow i18n event attributes#68821
Hexix23 wants to merge 1 commit into
angular:mainfrom
Hexix23:fix-i18n-event-attrs-validation

Conversation

@Hexix23
Copy link
Copy Markdown

@Hexix23 Hexix23 commented May 20, 2026

PR Checklist

Please check if your PR fulfills the following requirements:

PR Type

What kind of change does this PR introduce?

  • Bugfix
  • Security hardening

What is the current behavior?

Angular disallows binding to event-handler attributes such as onclick and onerror through validateAttribute() / validateProperty(), but the i18n metadata path still allowed the same attribute names to be marked for translation with i18n-on*.

This creates an XSS sink in the i18n pipeline: a lower-trust translation file could replace a benign static handler such as onerror="void 0" with executable JavaScript in the localized build.

Affected versions / verification

I reproduced the vulnerable behavior in localized AOT builds against:

The #68591 hardening correctly covers schema-driven i18n security contexts such as URL, ResourceURL, iframe policy attributes, and SVG animation attributes. This event-handler case remained separate because on* attributes are rejected by Angular's event-attribute validation path rather than by SECURITY_SCHEMA.

What is the new behavior?

i18n-on* attributes are rejected during i18n metadata collection with the same security error shape used for other disallowed translated attributes.

This prevents translated static attributes from bypassing Angular's event-attribute validation invariant.

The implementation intentionally performs the event-attribute check directly in the i18n metadata gate, alongside the existing Trusted Types sink check, so this path rejects translated executable event handlers before they are collected as translatable attribute metadata.

Does this PR introduce a breaking change?

  • Yes

Applications that intentionally translate static event-handler attributes such as i18n-onerror will now fail compilation. This is intentional because translated event-handler attributes are executable JavaScript sinks.

Other information

The change is intentionally limited to translated event-handler attributes. Normal non-security-sensitive translated attributes continue to work, and the existing schema-driven i18n sanitizer/validator paths continue to handle URL, ResourceURL, iframe policy, and SVG animation attributes.

Fix validation run locally:

  • bazelisk test //packages/core/test:test
  • bazelisk test //packages/compiler/test:test
  • pnpm ng-dev commit-message validate-range

@angular-robot angular-robot Bot added the area: compiler Issues related to `ngc`, Angular's template compiler label May 20, 2026
@ngbot ngbot Bot added this to the Backlog milestone May 20, 2026
Copy link
Copy Markdown
Contributor

@alan-agius4 alan-agius4 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 added target: patch This PR is targeted for the next patch release action: review The PR is still awaiting reviews from at least one requested reviewer labels May 20, 2026
@Hexix23 Hexix23 force-pushed the fix-i18n-event-attrs-validation branch from f980879 to ca6e783 Compare May 20, 2026 12:43
Copy link
Copy Markdown
Contributor

@alan-agius4 alan-agius4 left a comment

Choose a reason for hiding this comment

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

Avoiding DOM schema validation here; a simple check for the on prefix is sufficient

Reject translated event-handler attributes so localization cannot bypass Angular event-attribute validation.
@Hexix23 Hexix23 force-pushed the fix-i18n-event-attrs-validation branch from ca6e783 to d366587 Compare May 20, 2026 13:01
Copy link
Copy Markdown
Author

@Hexix23 Hexix23 left a comment

Choose a reason for hiding this comment

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

Thanks Alan, updated to avoid DOM schema validation here and keep the direct on prefix check in the i18n metadata gate.

Copy link
Copy Markdown
Contributor

@alan-agius4 alan-agius4 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

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