Skip to content

Commit e2660c3

Browse files
Hexix23alxhub
authored andcommitted
fix(compiler): disallow i18n event attributes
Reject translated event-handler attributes so localization cannot bypass Angular event-attribute validation.
1 parent f34a93c commit e2660c3

2 files changed

Lines changed: 10 additions & 1 deletion

File tree

packages/compiler/src/render3/view/i18n/meta.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -208,7 +208,7 @@ export class I18nMetaVisitor implements html.Visitor {
208208
isTrustedType = isTrustedTypesSink(node.name, name);
209209
}
210210

211-
if (isTrustedType) {
211+
if (isTrustedType || name.toLowerCase().startsWith('on')) {
212212
this._reportError(
213213
attr,
214214
`Translating attribute '${name}' is disallowed for security reasons.`,

packages/core/test/linker/security_integration_spec.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -368,6 +368,15 @@ describe('security integration tests', function () {
368368
expect(link.getAttribute('href')).toEqual('unsafe:javascript:alert(1)');
369369
});
370370

371+
it('should throw error on translated event attributes', () => {
372+
const template = `<img src="/missing-image.png" onerror="void 0" i18n-onerror>`;
373+
TestBed.overrideComponent(SecuredComponent, {set: {template}});
374+
375+
expect(() => TestBed.createComponent(SecuredComponent)).toThrowError(
376+
/Translating attribute 'onerror' is disallowed for security reasons./,
377+
);
378+
});
379+
371380
it('should throw error on security-sensitive attributes with constant values', () => {
372381
const template = `<iframe srcdoc="foo" i18n-srcdoc></iframe>`;
373382
TestBed.overrideComponent(SecuredComponent, {set: {template}});

0 commit comments

Comments
 (0)