Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 12 additions & 1 deletion packages/compiler/src/render3/view/i18n/meta.ts
Original file line number Diff line number Diff line change
Expand Up @@ -208,7 +208,7 @@ export class I18nMetaVisitor implements html.Visitor {
isTrustedType = isTrustedTypesSink(node.name, name);
}

if (isTrustedType || name.toLowerCase().startsWith('on')) {
if (isTrustedType || isPossibleEventHandler(name)) {
this._reportError(
attr,
`Translating attribute '${name}' is disallowed for security reasons.`,
Expand Down Expand Up @@ -350,3 +350,14 @@ export function i18nMetaToJSDoc(meta: I18nMeta): o.JSDocComment {
}
return o.jsDocComment(tags);
}

/**
* Check if the propertyName is a potential event handler.
* We consider a property to be a potential event handler if its name is longer than 2 characters and starts with 'on' (e.g. 'onclick', 'onload', etc.).
* @param propertyName The name of the property to check.
* @returns True if the property is a potential event handler, false otherwise.
*/
function isPossibleEventHandler(propertyName: string): boolean {
const name = propertyName.toLowerCase();
return name.length > 2 && name !== 'only' && name.startsWith('on');
}
7 changes: 7 additions & 0 deletions packages/core/test/linker/security_integration_spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -385,6 +385,13 @@ describe('security integration tests', function () {
);
});

it('should not throw error on translating "on" attribute', () => {
const template = `<div on="some-value" i18n-on></div>`;
TestBed.overrideComponent(SecuredComponent, {set: {template}});

expect(() => TestBed.createComponent(SecuredComponent)).not.toThrow();
});

it('should throw error on security-sensitive attributes with constant values', () => {
const template = `<iframe srcdoc="foo" i18n-srcdoc></iframe>`;
TestBed.overrideComponent(SecuredComponent, {set: {template}});
Expand Down
Loading