Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

NodeJS Taint Tracking - Modelingthis.prop and Writing Source Predicates for Parameterless Methods in CodeQL#18373

dvec01 started this conversation inGeneral
Discussion options

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 thetest -> execSync path:

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 thef.getAParameter() = source.asExpr() and replacing it withsource.asExpr().getEnclosingFunction() = f clause would help, as it causes all calls in the source method to be marked as sources, which is overly broad. For example if the test method was changed to:

test(){execSync(arguments[0]);execSync("echo test");}

it would also highlight the second call, which uncontrollable/ untainted data.

My questions:
What is the recommended approach to model accesses toarguments,this orsuper as tainted (similar tohttps://codeql.github.com/codeql-standard-libraries/java/semmle/code/java/dataflow/FlowSteps.qll/type.FlowSteps$TaintInheritingContent.html)?

What’s the best way to write a source predicate for methods with no parameters?

Many thanks in advance.

You must be logged in to vote

Replies: 3 comments

Comment options

Hi@dvec01,

Thanks for your question. It's not completely clear to me what you want your source to be.arguments is accessible through thegetArgumentsVariable predicate of theFunction class. I'm not sure if that helps?

You must be logged in to vote
0 replies
Comment options

Hi@jketema ,
here is an example that hopefully makes my problem more clear:

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 isthis.userInput, but I need the query to consider the paths that start at thesource method (even if there are no dataflow/ taint steps), that is the sink should be reachable from this method. Is there a way to achieve this using the TaintTracking module?

You must be logged in to vote
0 replies
Comment options

What is the recommended approach to model accesses to arguments, this or super as tainted
Access toarguments:

DataFlow::FunctionNodetestFunc(){result.getName()="test"}predicateisSource(DataFlow::Nodenode){// using 'arguments' as sourcenode=testFunc().getFunction().getArgumentsVariable().getAnAccess().flow()or// using 'this' as sourcenode=testFunc().getReceiver()}

What’s the best way to write a source predicate for methods with no parameters?

Usingarguments orthis methods above, depending on what contains the tainted data.

Note that there is currently no way to specify a source that is inside of a content, but if you treatthis as a source it should consider all of its properties as tainted.

You must be logged in to vote
0 replies
Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment
Category
General
Labels
None yet
3 participants
@dvec01@asgerf@jketema

[8]ページ先頭

©2009-2025 Movatter.jp