-
Notifications
You must be signed in to change notification settings - Fork 27.3k
fix(compiler): sanitize href/xlink:href attributes of any element…
#69191
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -455,10 +455,16 @@ export class DomElementSchemaRegistry extends ElementSchemaRegistry { | |
|
|
||
| const normalizedTag = normalizeTagName(tagName); | ||
| propName = propName.toLowerCase(); | ||
| let nsWildcardTag: string | undefined; | ||
| if (normalizedTag.startsWith(':')) { | ||
| const lastColonIndex = normalizedTag.lastIndexOf(':'); | ||
| nsWildcardTag = `${normalizedTag.slice(0, lastColonIndex + 1)}*`; | ||
| } | ||
|
|
||
| const securitySchema = SECURITY_SCHEMA(); | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 |
||
| const ctx = | ||
| securitySchema[normalizedTag + '|' + propName] ?? | ||
| (nsWildcardTag !== undefined ? securitySchema[nsWildcardTag + '|' + propName] : undefined) ?? | ||
| securitySchema['*|' + propName] ?? | ||
| SecurityContext.NONE; | ||
|
|
||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -68,43 +68,7 @@ export function SECURITY_SCHEMA(): {[k: string]: SecurityContext} { | |
| ['video', ['src']], | ||
| ]); | ||
|
|
||
| registerContext(SecurityContext.URL, MATH_ML_NAMESPACE, [ | ||
| // MathML namespace | ||
| // https://crsrc.org/c/third_party/blink/renderer/core/sanitizer/sanitizer.cc;l=753-768;drc=b3eb16372dcd3317d65e9e0265015e322494edcd;bpv=1;bpt=1 | ||
| ['annotation', ['href', 'xlink:href']], | ||
| ['annotation-xml', ['href', 'xlink:href']], | ||
| ['maction', ['href', 'xlink:href']], | ||
| ['malignmark', ['href', 'xlink:href']], | ||
| ['math', ['href', 'xlink:href']], | ||
| ['mroot', ['href', 'xlink:href']], | ||
| ['msqrt', ['href', 'xlink:href']], | ||
| ['merror', ['href', 'xlink:href']], | ||
| ['mfrac', ['href', 'xlink:href']], | ||
| ['mglyph', ['href', 'xlink:href']], | ||
| ['msub', ['href', 'xlink:href']], | ||
| ['msup', ['href', 'xlink:href']], | ||
| ['msubsup', ['href', 'xlink:href']], | ||
| ['mmultiscripts', ['href', 'xlink:href']], | ||
| ['mprescripts', ['href', 'xlink:href']], | ||
| ['mi', ['href', 'xlink:href']], | ||
| ['mn', ['href', 'xlink:href']], | ||
| ['mo', ['href', 'xlink:href']], | ||
| ['mpadded', ['href', 'xlink:href']], | ||
| ['mphantom', ['href', 'xlink:href']], | ||
| ['mrow', ['href', 'xlink:href']], | ||
| ['ms', ['href', 'xlink:href']], | ||
| ['mspace', ['href', 'xlink:href']], | ||
| ['mstyle', ['href', 'xlink:href']], | ||
| ['mtable', ['href', 'xlink:href']], | ||
| ['mtd', ['href', 'xlink:href']], | ||
| ['mtr', ['href', 'xlink:href']], | ||
| ['mtext', ['href', 'xlink:href']], | ||
| ['mover', ['href', 'xlink:href']], | ||
| ['munder', ['href', 'xlink:href']], | ||
| ['munderover', ['href', 'xlink:href']], | ||
| ['semantics', ['href', 'xlink:href']], | ||
| ['none', ['href', 'xlink:href']], | ||
| ]); | ||
| registerContext(SecurityContext.URL, MATH_ML_NAMESPACE, [['*', ['href', 'xlink:href']]]); | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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) |
||
|
|
||
| registerContext(SecurityContext.RESOURCE_URL, /** Namespace */ undefined, [ | ||
| ['base', ['href']], | ||
|
|
@@ -161,8 +125,10 @@ function registerContext( | |
| specs: readonly [tagName: string, attributeNames: readonly string[]][], | ||
| ): void { | ||
| for (const [element, attributeNames] of specs) { | ||
| let tagName = | ||
| namespace && element !== '*' && element !== 'unknown' ? `:${namespace}:${element}` : element; | ||
| let tagName = element; | ||
| if (namespace && element !== 'unknown') { | ||
| tagName = `:${namespace}:${element}`; | ||
| } | ||
| tagName = tagName.toLowerCase(); | ||
|
|
||
| for (const attr of attributeNames) { | ||
|
|
||
There was a problem hiding this comment.
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 usenormalizeTagNameto avoid combining the namespace and splitting it multiple times.