Skip to content

fix(compiler): sanitize href/xlink:href attributes of any element…#69191

Draft
JeanMeche wants to merge 1 commit into
angular:mainfrom
JeanMeche:compiler/mathml-namespace
Draft

fix(compiler): sanitize href/xlink:href attributes of any element…#69191
JeanMeche wants to merge 1 commit into
angular:mainfrom
JeanMeche:compiler/mathml-namespace

Conversation

@JeanMeche
Copy link
Copy Markdown
Member

… of the MathML namespace

The ensures that future, present and past (and precated) elements of that namespace get sanitized.

@angular-robot angular-robot Bot added the area: compiler Issues related to `ngc`, Angular's template compiler label Jun 5, 2026
@ngbot ngbot Bot added this to the Backlog milestone Jun 5, 2026
@JeanMeche JeanMeche requested a review from AndrewKushnir June 5, 2026 14:27
@JeanMeche JeanMeche force-pushed the compiler/mathml-namespace branch from fcba6aa to 5e9e889 Compare June 5, 2026 14:30
@alan-agius4 alan-agius4 marked this pull request as draft June 5, 2026 14:45
… of the MathML namespace

The ensures that future, present and past (and precated) elements of that namespace get sanitized.
@JeanMeche JeanMeche force-pushed the compiler/mathml-namespace branch from 5e9e889 to 9ce049a Compare June 5, 2026 15:19

const normalizedTag = normalizeTagName(tagName);
propName = propName.toLowerCase();
let nsWildcardTag: string | undefined;
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.

We already have a function to get the namespace normalizeTagName. Also in this case maybe do not use normalizeTagName to avoid combining the namespace and splitting it multiple times.

nsWildcardTag = `${normalizedTag.slice(0, lastColonIndex + 1)}*`;
}

const securitySchema = SECURITY_SCHEMA();
Copy link
Copy Markdown
Contributor

@alan-agius4 alan-agius4 Jun 5, 2026

Choose a reason for hiding this comment

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

This logic should probably be moved into a function in dom_security_schema.ts.

This is because the same logic in also present in i18n_parser and they should be kept in sync with a shared function it's easier to avoid updating one place and not the other.

Something like

getSecurityContextFromSchema(tagName, attributeName, namespace): SecurityContext 

['semantics', ['href', 'xlink:href']],
['none', ['href', 'xlink:href']],
]);
registerContext(SecurityContext.URL, MATH_ML_NAMESPACE, [['*', ['href', 'xlink:href']]]);
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.

NIT: can you leave the previous comment (Personally it's quite useful to check every now and than)

// https://crsrc.org/c/third_party/blink/renderer/core/sanitizer/sanitizer.cc;l=753-768;drc=b3eb16372dcd3317d65e9e0265015e322494edcd;bpv=1;bpt=1

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area: compiler Issues related to `ngc`, Angular's template compiler

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants