-
Notifications
You must be signed in to change notification settings - Fork 956
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
Throw instead of rendering error on security issue #2070
Changes from 1 commit
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 |
---|---|---|
|
@@ -1080,13 +1080,20 @@ class ChildPart implements Disconnectable { | |
) { | ||
const parentNodeName = this._$startNode.parentNode?.nodeName; | ||
if (parentNodeName === 'STYLE' || parentNodeName === 'SCRIPT') { | ||
this._insert( | ||
new Text( | ||
'/* lit-html will not write ' + | ||
'TemplateResults to scripts and styles */' | ||
) | ||
); | ||
return; | ||
let message = 'Forbidden'; | ||
if (DEV_MODE) { | ||
if (parentNodeName === 'STYLE') { | ||
message = | ||
`Lit does not support binding inside style nodes. ` + | ||
`This is a security risk, as style injection attacks can exfiltrate data and spoof UIs. ` + | ||
`Consider instead using css\`...\` literals to compose styles, and accomplishing dynamicism by mutating the DOM rather than styles`; | ||
} else { | ||
message = | ||
`Lit does not support binding inside script nodes. ` + | ||
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 is fine as an existing restriction, but I'd like to dig into this more with the ISE team. First, in client-side rendering <script> tags in Lit templates will not execute (in SSR they can, but we could make sure they don't). Then <script> tags can be used for other purposes than executable JS, mainly because they're raw text elements and can contain unescaped "<" characters. The Playground Elements use <script> tags for file content. I've seen syntax highlighters that do the same. I could see cases where you want those to be dynamic... 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. Yeah, we could add some additional checks here, e.g. that there's a It is the case that even if the type is a javascript type, script tags rendered like this don't typically run, but are we certain that there isn't a way to make them run? e.g. render into an unattached document fragment, then attach that? Something something inert template and clone into document? 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. I'm not 100% sure if cloning drops the script-created bit, but I'd like to be! Seems like good tests to eventually add. |
||
`This is a security risk, as it could allow arbitrary code execution.`; | ||
} | ||
} | ||
throw new Error(message); | ||
} | ||
} | ||
this._$committedValue = this._insert(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.
Can you beak this line up to be < 80 cols?
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.
Done!