-
Notifications
You must be signed in to change notification settings - Fork 1.6k
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
Javascript: How can I filter some dataflow results? #6920
Comments
Can you provide some additional context for the query? Like the kind of problem are you trying to identify, or some additional nearby source code. Generally speaking from the security angle, if |
For example, the foo function is in third party, and it concats obj.body to a sql string, and just log obj.headers, like
Because foo is invisible, I make the arguement of foo as sink, request.body as source. |
Can FlowLabel do this work? And if so, how to use it in this example? Thanks |
https://codeql.github.com/docs/codeql-language-guides/using-flow-labels-for-precise-data-flow-analysis/ is the documentation for Instead of modelling: sink = any(CallNode n | n.getCalleeName() = "foo").getArgument(0) we can model: sink = any(CallNode n | n.getCalleeName() = "foo").getOptionArgument(0, "body")` That is: we essentially stop the dataflow tracking one step earlier. This approach works for all queries without introducing the complex |
It works in the above example. But in my real world code, the example is more like :
The arguement flows into other function. Is there a simple way to solve it? @esbena |
OK. Then I'll refer to https://codeql.github.com/docs/codeql-language-guides/using-flow-labels-for-precise-data-flow-analysis/ again. The Like in that example you need the following:
|
The origin query:
|
You need to change |
It seems that the DataFlow::Configuration is a local flow...
It turns out no result. @esbena |
The above code looks right to me, but it is confusing to see the Some suggestions towards spotting a bug:
|
I change my code to:
which FilterLabel means property I would like to filter, and PassLabel means that property I would like to pass.
|
For convenience, I put the demo code here: https://github.com/greatyy/test_codeql_json.git |
Your example ql code above only uses the
/**
* @kind path-problem
*/
import javascript
import DataFlow::PathGraph
import semmle.javascript.security.TaintedObject
class TaintedObjectInHeaders extends DataFlow::FlowLabel {
TaintedObjectInHeaders() { this = "tainted-object-in-headers" }
}
class JsonTrackingConfig extends DataFlow::Configuration {
JsonTrackingConfig() { this = "JsonTrackingConfig" }
override predicate isSource(DataFlow::Node nd, DataFlow::FlowLabel lbl) {
DataFlow::globalVarRef("request").getAPropertyRead("body") = nd and
lbl = TaintedObject::label()
}
override predicate isSink(DataFlow::Node nd, DataFlow::FlowLabel lbl) {
exists(DataFlow::CallNode process |
process.getCalleeName() = "foo" and nd = process.getArgument(0)
) and
(lbl instanceof TaintedObjectInHeaders or lbl = TaintedObject::label())
}
override predicate isAdditionalFlowStep(
DataFlow::Node pred, DataFlow::Node succ, DataFlow::FlowLabel predlbl,
DataFlow::FlowLabel succlbl
) {
succ.(DataFlow::SourceNode).getAPropertyWrite("headers").getRhs() = pred and
predlbl = TaintedObject::label() and
succlbl instanceof TaintedObjectInHeaders
or
TaintedObject::step(pred, succ, predlbl, succlbl)
}
}
from JsonTrackingConfig cfg, DataFlow::PathNode source, DataFlow::PathNode sink
where cfg.hasFlowPath(source, sink)
select sink.getNode(), source, sink, "Property access on JSON value originating $@.",
source.getNode(), "here"
|
Example:
while I query the above code, there are two flow path:
And I would like to show result 1 only, and filter result 2.
How can I solve the problem? Thanks
The text was updated successfully, but these errors were encountered: