-
Notifications
You must be signed in to change notification settings - Fork 125
Add CWE-79: HTML template escaping passthrough #493
Add CWE-79: HTML template escaping passthrough #493
Conversation
Have started an all-projects evaluation |
ql/src/experimental/CWE-79/HTMLTemplateEscapingPassthrough.qhelp
Outdated
Show resolved
Hide resolved
ql/src/experimental/CWE-79/HTMLTemplateEscapingPassthrough.qhelp
Outdated
Show resolved
Hide resolved
* this allows the injection of arbitrary content (html, css, js) into the generated | ||
* output of the templates. | ||
*/ | ||
class ConversionFlowToPassthroughTypeConf extends TaintTracking::Configuration { |
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.
Hm. I'd be curious whether something like
exists(PassthroughTypeNode node | edges*(source, node) and edges*(node, sink) | node.getNode().getType() <is passthrough type>
would work here.
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 would that ever be done?
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 mean, how does that work? I haven't seen anything similar before.
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.
Sorry, I should have asked what you meant. edges
is a predicate that's automatically generated when you import PathGraph
and contains the final data-flow graph that's used for displaying results. It's therefore not actually complete, and does the flow-summary that you'll see.
Any news on that front? |
47 hits. Observations from triaging the first 20:
|
Is there an example of flow tags in codeql-go? |
I added an extra flow condition, and it seems to work (added a test). Not sure about where and how/why use |
It's probably very inefficient 😬 |
Flow tags are a feature available in the Javascript dataflow lib but regrettably not in Go yet. |
ef5cbe8
to
3e1916e
Compare
Is my code correct? AFAICT it works. |
Looks good -- it's possible to make a bit more efficient by restricting some of the flows to only investigate sources/sinks that are involved in a flow according to one of the others (starting with whichever flow we expect to be most rare, then working out from there). That would require using TaintTracking2 etc so dependent flows don't use the same instance of TaintTracking; however it's not necessary particularly when the waypoint (B, type conversion to html/template.JS or similar) is quite unusual. I'll try this out on LGTM now. |
5bfdc0d
to
a3ad589
Compare
Using the same instance of How can that be avoided? I'm trying to use |
Use a different version of TaintTracking for each Configuration. The DataFlow::Node types they use can be directly compared. |
There's only |
Nope, still same. |
Using two ~instances, Not sure whether that's good. |
The expected file has three subsections: nodes, edges, and results (the top-level |
This comment has been minimized.
This comment has been minimized.
I get the same results with both versions of the query (the first version that uses only one TaintTracking, and the second version using the two different TaintTracking). |
This comment has been minimized.
This comment has been minimized.
Never mind. That seems to be the flow steps in a regular flow, too. |
Going back to using one instance of |
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.
Mostly looking good -- I see a few results we could easily exclude though; since this is quite closely related to an XSS query, we should probably include the same sanitizers. They are defined here:
abstract class Sanitizer extends DataFlow::Node { } |
And here's an example of a user (https://github.com/github/codeql-go/blob/main/ql/src/semmle/go/security/ReflectedXssCustomizations.qll#L28), though we can just directly include these using the isSanitizer
method of any appropriate configuration.
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.
A few minor cleanups, then lgtm
ql/src/experimental/CWE-79/HTMLTemplateEscapingPassthrough.qhelp
Outdated
Show resolved
Hide resolved
Just noticed these had been done -- please do ping when you've applied review suggestions, or it's quite easy not to notice |
Co-authored-by: Sauyon Lee <sauyon@github.com>
…`conversion` flows to `template-exec`.
…Call, and a test for it
Co-authored-by: Chris Smowton <smowton@github.com>
ecb7ac9
to
68c0073
Compare
Rebased and set to automerge if CI passes. |
CI passed, but the automerge didn't happen. |
I will 🤗 |
Maybe it's missing the approval. |
This PR adds a new experimental query regarding CWE-79: Improper Neutralization of Input During Web Page Generation ('Cross-site Scripting'), and more specifically the cases when user-values are converted to types that allow completely avoiding the escaping that normally values would undergo in the HTML template execution.
Usage of such types on user-provided values leads to XSS.