Skip to content
Closed
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
30 changes: 26 additions & 4 deletions packages/compiler/src/render3/view/i18n/meta.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,10 @@ import * as i18n from '../../../i18n/i18n_ast';
import {createI18nMessageFactory, VisitNodeFn} from '../../../i18n/i18n_parser';
import * as html from '../../../ml_parser/ast';
import {ParseTreeResult} from '../../../ml_parser/parser';
import {splitNsName} from '../../../ml_parser/tags';
import * as o from '../../../output/output_ast';
import {SecurityContext} from '../../../core';
import {DomElementSchemaRegistry} from '../../../schema/dom_element_schema_registry';
import {isTrustedTypesSink} from '../../../schema/trusted_types_sinks';

import {hasI18nAttrs, I18N_ATTR, I18N_ATTR_PREFIX, icuFromI18nMessage} from './util';
Expand Down Expand Up @@ -49,6 +52,19 @@ const setI18nRefs = (originalNodeMap: Map<html.Node, html.Node>): VisitNodeFn =>
};
};

const domSchema = new DomElementSchemaRegistry();
const SVG_ANIMATION_ELEMENTS = new Set(['animate', 'set', 'animatemotion', 'animatetransform']);

function isSvgAnimationTranslatedAttribute(tagName: string, attrName: string): boolean {
const elementName = splitNsName(tagName)[1];

return (
SVG_ANIMATION_ELEMENTS.has(elementName.toLowerCase()) &&
domSchema.securityContext(elementName, attrName, /* isAttribute */ true) ===
SecurityContext.ATTRIBUTE_NO_BINDING
);
}

/**
* This visitor walks over HTML parse tree and converts information stored in
* i18n-related attributes ("i18n" and "i18n-*") into i18n meta object that is
Expand Down Expand Up @@ -201,14 +217,20 @@ export class I18nMetaVisitor implements html.Visitor {
} else if (attr.name.startsWith(I18N_ATTR_PREFIX)) {
// 'i18n-*' attributes
const name = attr.name.slice(I18N_ATTR_PREFIX.length);
let isTrustedType: boolean;
let isSecuritySensitive: boolean;
if (node instanceof html.Component) {
isTrustedType = node.tagName === null ? false : isTrustedTypesSink(node.tagName, name);
isSecuritySensitive =
node.tagName === null
? false
: isTrustedTypesSink(node.tagName, name) ||
isSvgAnimationTranslatedAttribute(node.tagName, name);
} else {
isTrustedType = isTrustedTypesSink(node.name, name);
isSecuritySensitive =
isTrustedTypesSink(node.name, name) ||
isSvgAnimationTranslatedAttribute(node.name, name);
}

if (isTrustedType) {
if (isSecuritySensitive) {
this._reportError(
attr,
`Translating attribute '${name}' is disallowed for security reasons.`,
Expand Down
22 changes: 22 additions & 0 deletions packages/core/test/linker/security_integration_spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -273,5 +273,27 @@ describe('security integration tests', function () {
/Translating attribute 'innerHTML' is disallowed for security reasons./,
);
});

it('should throw error on SVG animation retargeting attributes', () => {
const template = `
<svg>
<a href="/safe">
<set
attributeName="display"
to="inline"
i18n-attributeName
i18n-to
begin="0s"
fill="freeze">
</set>
</a>
</svg>
`;
TestBed.overrideComponent(SecuredComponent, {set: {template}});

expect(() => TestBed.createComponent(SecuredComponent)).toThrowError(
/Translating attribute 'attributeName' is disallowed for security reasons./,
);
});
});
});
Loading