Skip to content

Commit 1ee224c

Browse files
Hexix23atscott
authored andcommitted
fix(compiler): disallow i18n event attributes
Reject translated event-handler attributes so localization cannot bypass Angular event-attribute validation. (cherry picked from commit 6c41f5c)
1 parent 1bd5a56 commit 1ee224c

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
@@ -376,6 +376,15 @@ describe('security integration tests', function () {
376376
expect(link.getAttribute('href')).toEqual('unsafe:javascript:alert(1)');
377377
});
378378

379+
it('should throw error on translated event attributes', () => {
380+
const template = `<img src="/missing-image.png" onerror="void 0" i18n-onerror>`;
381+
TestBed.overrideComponent(SecuredComponent, {set: {template}});
382+
383+
expect(() => TestBed.createComponent(SecuredComponent)).toThrowError(
384+
/Translating attribute 'onerror' is disallowed for security reasons./,
385+
);
386+
});
387+
379388
it('should throw error on security-sensitive attributes with constant values', () => {
380389
const template = `<iframe srcdoc="foo" i18n-srcdoc></iframe>`;
381390
TestBed.overrideComponent(SecuredComponent, {set: {template}});

0 commit comments

Comments
 (0)