Skip to content

fix(compiler): disallow i18n event attributes#68821

Merged
atscott merged 1 commit into
angular:mainfrom
Hexix23:fix-i18n-event-attrs-validation
Jun 10, 2026
Merged

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

Conversation

@Hexix23

@Hexix23 Hexix23 commented May 20, 2026

Copy link
Copy Markdown
Contributor

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

@alan-agius4 alan-agius4 left a comment

Copy link
Copy Markdown
Contributor

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

@alan-agius4 alan-agius4 left a comment

Copy link
Copy Markdown
Contributor

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

@Hexix23 Hexix23 force-pushed the fix-i18n-event-attrs-validation branch from ca6e783 to d366587 Compare May 20, 2026 13:01

@Hexix23 Hexix23 left a comment

Copy link
Copy Markdown
Contributor Author

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.

@alan-agius4 alan-agius4 left a comment

Copy link
Copy Markdown
Contributor

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

@JeanMeche

Copy link
Copy Markdown
Member

Looks liek we need a rebase here.

@alan-agius4 alan-agius4 added action: cleanup The PR is in need of cleanup, either due to needing a rebase or in response to comments from reviews and removed action: review The PR is still awaiting reviews from at least one requested reviewer labels Jun 8, 2026
@alan-agius4

Copy link
Copy Markdown
Contributor

@Hexix23 please rebase.

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 d366587 to c126e5f Compare June 9, 2026 21:23
@Hexix23

Hexix23 commented Jun 9, 2026

Copy link
Copy Markdown
Contributor Author

Rebased onto latest main.

@alan-agius4 alan-agius4 removed the action: cleanup The PR is in need of cleanup, either due to needing a rebase or in response to comments from reviews label Jun 10, 2026
@alan-agius4 alan-agius4 removed the request for review from kirjs June 10, 2026 05:45
@alan-agius4 alan-agius4 added the action: review The PR is still awaiting reviews from at least one requested reviewer label Jun 10, 2026

@josephperrott josephperrott left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

LGTM

@pullapprove pullapprove Bot requested a review from josephperrott June 10, 2026 13:19

@josephperrott josephperrott left a comment

Copy link
Copy Markdown
Member

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 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 Jun 10, 2026
@atscott atscott merged commit 6c41f5c into angular:main Jun 10, 2026
24 of 26 checks passed
@atscott

atscott commented Jun 10, 2026

Copy link
Copy Markdown
Contributor

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

@Raisolution

Copy link
Copy Markdown

Hello,

It looks like this change introduces a breaking behavior, but it was released as part of a patch version.

Could you please advise on the recommended migration path for cases where attributes contain on as part of their name but are not event bindings? One example is the scenario described here: telerik/kendo-angular#4945.

From a consumer perspective, it is unclear how such attributes should now be translated without being incorrectly treated as events. Could you please confirm this was the intended approach, or consider applying a fix if this behavior was not intentional?

Thank you.

@alan-agius4

alan-agius4 commented Jun 11, 2026

Copy link
Copy Markdown
Contributor

@Raisolution, with i18n any attribute even unbound ones can theoretically be exploited for XSS during i18n processing, that isn't the root cause here. In this specific scenario, the issue arises because the attribute is literally named on, which causes it to be incorrectly flagged as a potential event handler.

#69306 should fix this particular case.

@Raisolution

Raisolution commented Jun 11, 2026

Copy link
Copy Markdown

@alan-agius4 thank you for the clarification.

Yes, the issue is caused by the attribute name being interpreted as a potential event handler. This is the reason for raising the question - there are many valid translation attributes/messages where the name may start with on, without representing an event handler.

Could you please advise what the recommended approach is for such valid i18n cases, should consumers rename all such attributes/messages?

Edit: Thank you for the fix. It handles the concrete case with the word on, but the general problem will still be present. Would it be possible to list the concrete event-handler attributes that are considered problematic, instead of treating all attributes starting with on as unsafe?

Thank you.

@alan-agius4

alan-agius4 commented Jun 11, 2026

Copy link
Copy Markdown
Contributor

@Raisolution, we could add a comprehensive list, but it would drastically increase the bundle size by almost 1kb (minified) since there are 73 handlers starting with the on prefix. Note: the current check is also current used for bindings.

Can you provide examples of attributes starting with on that aren't handlers?

Generally, I'd recommend keeping attributes starting with on prefix reserved strictly for event handlers.

@Raisolution

Copy link
Copy Markdown

@alan-agius4 thank you for the prompt reaction and for providing the fix.

In the specific case, I do not currently have other concrete examples, the concern was more general, as there are valid words/messages starting with on that could theoretically hit the same problem.

That said, the proposed fix addresses the reported scenario, thank you again for the quick turnaround. 🍻

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 target: patch This PR is targeted for the next patch release

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants