- Notifications
You must be signed in to change notification settings - Fork1.9k
Uh oh!
There was an error while loading.Please reload this page.
Uh oh!
There was an error while loading.Please reload this page.
-
I faced an issue when creating a path query for the following JavaScript code: const{ execSync}=require('child_process');test(){execSync(arguments[0]);} Here is the query I wrote to detect the import semmle.javascript.dataflow.TaintTrackingimport javascriptclassConfigextends TaintTracking::Configuration{Config(){this="config"}overridepredicateisSource(DataFlow::Nodesource){exists(Functionf|f.getName()="test"andf.getAParameter()=source.asExpr())}overridepredicateisSink(DataFlow::Nodesink){ DataFlow::moduleMember("child_process","execSync").getACall().getArgument(0)=sink}}import DataFlow::PathGraphfromConfigdataflow, DataFlow::PathNodesource, DataFlow::PathNodesinkwheredataflow.hasFlowPath(source,sink)selectsink,source,sink,"This command depends on $@.",source.getNode(),"" This query doesn’t return any paths because the test method takes no input, hence the isSource predicate fails because it relies on method parameters, which are absent in this case. Omitting the test(){execSync(arguments[0]);execSync("echo test");} it would also highlight the second call, which uncontrollable/ untainted data. My questions: What’s the best way to write a source predicate for methods with no parameters? Many thanks in advance. |
BetaWas this translation helpful?Give feedback.
All reactions
Replies: 3 comments
-
Hi@dvec01, Thanks for your question. It's not completely clear to me what you want your source to be. |
BetaWas this translation helpful?Give feedback.
All reactions
-
Hi@jketema , constchild_process=require('child_process');classTest{constructor(userInput){this.userInput=userInput;}source(){this.sink();}sink(){child_process.execSync(`${this.userInput}`,{stdio:'inherit'});}}newTest("/usr/bin/id").source(); In the above example the source is |
BetaWas this translation helpful?Give feedback.
All reactions
-
DataFlow::FunctionNodetestFunc(){result.getName()="test"}predicateisSource(DataFlow::Nodenode){// using 'arguments' as sourcenode=testFunc().getFunction().getArgumentsVariable().getAnAccess().flow()or// using 'this' as sourcenode=testFunc().getReceiver()}
Using Note that there is currently no way to specify a source that is inside of a content, but if you treat |
BetaWas this translation helpful?Give feedback.