-
Notifications
You must be signed in to change notification settings - Fork 392
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
feat: secure wrap xlink #875
Conversation
Benchmark resultsBase commit: lwc-engine-benchmark
|
@@ -1,4 +1,4 @@ | |||
import { registerTemplate } from "lwc"; | |||
import { registerTemplate, sanitizeXLink } from "lwc"; |
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.
this should be called sanitize
with signature: (tagName: string, attrName: string, value: any)
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.
The tag name is probably not enough here, we also need the namespace as well.
function sanatizeAttribute(tagName: string, namespaceUri: string, attrName: string, attrValue: any): void
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.
since we were only concerned about sanitizing xlink function, i kept it explicit for locker. Do we anticipate more attributes that may need to be sanitized?
@@ -20,7 +20,7 @@ function tmpl($api, $cmp, $slotset, $ctx) { | |||
"use", | |||
{ | |||
attrs: { | |||
"xlink:href": "/x" | |||
"xlink:href": sanitizeXLink("/x") |
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.
this expression should be sanitize("use", "xlink:href", "/x")
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.
Do you foresee do that for all the attributes? Or only the one that we flagged as potential security issues?
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.
at this point i was only implementing the flagged one, wasn't sure there was more?
@@ -60,6 +61,10 @@ export function isIdReferencingAttribute(attrName: string): boolean { | |||
return ID_REFERENCING_ATTRIBUTES_SET.has(attrName); | |||
} | |||
|
|||
export function isXLinkAttribute(attrName: string): boolean { |
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.
make this a generic method that receives the tagName and the attrName, and determine if that requires sanitizing
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.
i made the sanitizeAttribute function generic as requested. However, this particular function merely checks if this attribute is indeed a 'xlink:href'.
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.
👍
@@ -3,7 +3,7 @@ import _nsBar from "ns/bar"; | |||
import _nsBuzz from "ns/buzz"; | |||
import _nsTable from "ns/table"; | |||
import _nsInput from "ns/input"; | |||
import { registerTemplate } from "lwc"; | |||
import { registerTemplate, sanitizeXLink } from "lwc"; |
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.
how is this going to work? who is responsible to populate this function? aura loader?
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.
Locker will be responsible for overriding the value.
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 also are going to add a sanitizeXLink no-op function on the lwc in the event of off-core usage where locker won't be available.
@@ -77,7 +77,7 @@ function tmpl($api, $cmp, $slotset, $ctx) { | |||
"use", | |||
{ | |||
attrs: { | |||
"xlink:href": "xx" | |||
"xlink:href": sanitizeAttribute("use", "http://www.w3.org/2000/svg", "xlink:href", "xx") |
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.
how are you planning to resolve the namespaceUri
?
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.
Is that something that the parser is producing already?
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.
yes this information is already collected.
@@ -386,6 +397,13 @@ function transform( | |||
if (isIdReferencingAttribute(attr.name)) { | |||
return generateScopedIdFunctionForIdRefAttr(attr.value); | |||
} | |||
|
|||
if (isXLinkAttribute(attr.name) && namespaceURI === SVG_NAMESPACE_URI) { |
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.
eventually this should be abstracted, but I'm fine with this
Benchmark resultsBase commit: lwc-engine-benchmark
|
Benchmark resultsBase commit: lwc-engine-benchmark
|
Benchmark resultsBase commit: lwc-engine-benchmark
|
LGTM so far |
Benchmark resultsBase commit: lwc-engine-benchmark
|
Benchmark resultsBase commit: lwc-engine-benchmark
|
Benchmark resultsBase commit: lwc-engine-benchmark
|
Details
Wrap the xlink:href into 'sanitize' function which will get patched by locker during runtime. When ran off-core, the function simply returns incoming value.
template compiler snippet for svg:
TODO: still need to handle expression values and check for svg
Does this PR introduce a breaking change?