-
Notifications
You must be signed in to change notification settings - Fork 1.8k
JS: recognize .split("?")[0] in more cases for URL redirection #3391
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
Conversation
I think the I am thinking of something like: class StringSplitCall extends DataFlow::MethodCallNode {
string getSplitAt() { getArgument(0).mayHaveStringValue(result) }
DataFlow::Node getUnsplit() { result = getReceiver() }
DataFlow::Node getAnElementRead(int i) { ... }
} |
I believe this also affects the DOM-based XSS query. Might be worth sharing the sanitizer if doing so doesn't have any adverse side effects. |
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.
Some minor comments.
/** | ||
* Gets a the SourceNode for the string before it is split. | ||
*/ | ||
DataFlow::SourceNode getUnsplit() { result = getReceiver().getALocalSource() } |
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 dislike the getUnsplit
name (even though it is my own suggestion).
Perhaps getStringSource
, and dually getASubstringRead(int i)
below would be better?
This has no result for "foo|bar".split("|").map(...)
. I can live with that if a renaming like the above is implemented.
If we need to reason about the shorthand above, we can introduce string getString()
and string getSubstring(int i)
.
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.
In the StringOps
module I tried to stick with getBaseString
as it was meaningful yet generic enough to be used consistently across the different string operations. I think we can use the same here, and possibly drop the getALocalSource
.
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 went with getBaseString
, and dropped the getALocalSource()
.
Co-authored-by: Esben Sparre Andreasen <esbena@github.com>
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.
LGTM. Modulo the missing change note part and a missing flowsTo
.
javascript/ql/src/Security/CWE-400/PrototypePollutionUtility.ql
Outdated
Show resolved
Hide resolved
Co-authored-by: Esben Sparre Andreasen <esbena@github.com>
An evaluation came back with not great performance, and an FP for the following pattern: window.location.replace(window.location.href.split("#")[0] + "#mappage"); I fixed the FP, and I'll look into the performance. |
A security/nightly evaluation came back with mixed results. So I think this is ready to land. |
Fixes these FPs that showed up in an anomalous query results a while ago.
The issue is we didn't recognize the
.split("?")[0]
pattern if there was any data-flow. E.g.With this PR a
.getALocalSource()
is added, such that we recognize the safe way of constructing a redirect URL in more cases.The pattern is not common, and I found no instances of it on our standard 236 benchmarks.
I know it looks like an ad-hoc addon, but the alternative solution would be to add another flow-label, and I don't think that would perform well.