Skip to content

Commit b62e5b1

Browse files
committed
update the SQL/NoSQL models to use dataflow nodes
1 parent ff84480 commit b62e5b1

File tree

8 files changed

+32
-36
lines changed

8 files changed

+32
-36
lines changed

javascript/ql/experimental/adaptivethreatmodeling/lib/experimental/adaptivethreatmodeling/NosqlInjectionATM.qll

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,7 @@ predicate isBaseAdditionalFlowStep(
116116
inlbl = TaintedObject::label() and
117117
outlbl = TaintedObject::label() and
118118
exists(NoSql::Query query, DataFlow::SourceNode queryObj |
119-
queryObj.flowsToExpr(query) and
119+
queryObj.flowsTo(query) and
120120
queryObj.flowsTo(trg) and
121121
src = queryObj.getAPropertyWrite().getRhs()
122122
)

javascript/ql/lib/semmle/javascript/frameworks/Knex.qll

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ module Knex {
4343

4444
/** A SQL string passed to a raw Knex method. */
4545
private class RawKnexSqlString extends SQL::SqlString {
46-
RawKnexSqlString() { this = any(RawKnexCall call).getArgument(0).asExpr() }
46+
RawKnexSqlString() { this = any(RawKnexCall call).getArgument(0) }
4747
}
4848

4949
/** A call that triggers a SQL query submission by calling then/stream/asCallback. */

javascript/ql/lib/semmle/javascript/frameworks/NoSQL.qll

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import semmle.javascript.Promises
88
/** Provices classes for modelling NoSQL query sinks. */
99
module NoSql {
1010
/** An expression that is interpreted as a NoSQL query. */
11-
abstract class Query extends Expr {
11+
abstract class Query extends DataFlow::Node {
1212
/** Gets an expression that is interpreted as a code operator in this query. */
1313
DataFlow::Node getACodeOperator() { none() }
1414
}
@@ -85,7 +85,7 @@ private module MongoDB {
8585
class Query extends NoSql::Query {
8686
QueryCall qc;
8787

88-
Query() { this = qc.getAQueryArgument().asExpr() }
88+
Query() { this = qc.getAQueryArgument() }
8989

9090
override DataFlow::Node getACodeOperator() { result = qc.getACodeOperator() }
9191
}
@@ -519,7 +519,7 @@ private module Mongoose {
519519
class MongoDBQueryPart extends NoSql::Query {
520520
MongooseFunction f;
521521

522-
MongoDBQueryPart() { this = f.getQueryArgument().getARhs().asExpr() }
522+
MongoDBQueryPart() { this = f.getQueryArgument().getARhs() }
523523

524524
override DataFlow::Node getACodeOperator() {
525525
result = getADollarWhereProperty(f.getQueryArgument())
@@ -626,7 +626,7 @@ private module Minimongo {
626626
class Query extends NoSql::Query {
627627
QueryCall qc;
628628

629-
Query() { this = qc.getAQueryArgument().asExpr() }
629+
Query() { this = qc.getAQueryArgument() }
630630

631631
override DataFlow::Node getACodeOperator() { result = qc.getACodeOperator() }
632632
}
@@ -686,7 +686,7 @@ private module MarsDB {
686686
class Query extends NoSql::Query {
687687
QueryCall qc;
688688

689-
Query() { this = qc.getAQueryArgument().asExpr() }
689+
Query() { this = qc.getAQueryArgument() }
690690

691691
override DataFlow::Node getACodeOperator() { result = qc.getACodeOperator() }
692692
}
@@ -771,7 +771,7 @@ private module Redis {
771771
RedisKeyArgument() {
772772
exists(string method, int argIndex |
773773
QuerySignatures::argumentIsAmbiguousKey(method, argIndex) and
774-
this = redis().getMember(method).getParameter(argIndex).getARhs().asExpr()
774+
this = redis().getMember(method).getParameter(argIndex).getARhs()
775775
)
776776
}
777777
}

javascript/ql/lib/semmle/javascript/frameworks/SQL.qll

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -6,26 +6,26 @@ import javascript
66
import semmle.javascript.Promises
77

88
module SQL {
9-
/** A string-valued expression that is interpreted as a SQL command. */
10-
abstract class SqlString extends Expr { }
9+
/** A string-valued dataflow node that is interpreted as a SQL command. */
10+
abstract class SqlString extends DataFlow::Node { }
1111

1212
private class SqlStringFromModel extends SqlString {
13-
SqlStringFromModel() { this = ModelOutput::getASinkNode("sql-injection").getARhs().asExpr() }
13+
SqlStringFromModel() { this = ModelOutput::getASinkNode("sql-injection").getARhs() }
1414
}
1515

1616
/**
17-
* An expression that sanitizes a string to make it safe to embed into
17+
* An dataflow node that sanitizes a string to make it safe to embed into
1818
* a SQL command.
1919
*/
20-
abstract class SqlSanitizer extends Expr {
21-
Expr input;
22-
Expr output;
20+
abstract class SqlSanitizer extends DataFlow::Node {
21+
DataFlow::Node input;
22+
DataFlow::Node output;
2323

2424
/** Gets the input expression being sanitized. */
25-
Expr getInput() { result = input }
25+
DataFlow::Node getInput() { result = input }
2626

2727
/** Gets the output expression containing the sanitized value. */
28-
Expr getOutput() { result = output }
28+
DataFlow::Node getOutput() { result = output }
2929
}
3030
}
3131

@@ -91,13 +91,13 @@ private module MySql {
9191

9292
/** An expression that is passed to the `query` method and hence interpreted as SQL. */
9393
class QueryString extends SQL::SqlString {
94-
QueryString() { this = any(QueryCall qc).getAQueryArgument().asExpr() }
94+
QueryString() { this = any(QueryCall qc).getAQueryArgument() }
9595
}
9696

9797
/** A call to the `escape` or `escapeId` method that performs SQL sanitization. */
98-
class EscapingSanitizer extends SQL::SqlSanitizer, MethodCallExpr {
98+
class EscapingSanitizer extends SQL::SqlSanitizer instanceof API::CallNode {
9999
EscapingSanitizer() {
100-
this = [mysql(), pool(), connection()].getMember(["escape", "escapeId"]).getACall().asExpr() and
100+
this = [mysql(), pool(), connection()].getMember(["escape", "escapeId"]).getACall() and
101101
input = this.getArgument(0) and
102102
output = this
103103
}
@@ -199,9 +199,9 @@ private module Postgres {
199199
/** An expression that is passed to the `query` method and hence interpreted as SQL. */
200200
class QueryString extends SQL::SqlString {
201201
QueryString() {
202-
this = any(QueryCall qc).getAQueryArgument().asExpr()
202+
this = any(QueryCall qc).getAQueryArgument()
203203
or
204-
this = API::moduleImport("pg-cursor").getParameter(0).getARhs().asExpr()
204+
this = API::moduleImport("pg-cursor").getParameter(0).getARhs()
205205
}
206206
}
207207

@@ -350,7 +350,7 @@ private module Postgres {
350350

351351
/** An expression that is interpreted as SQL by `pg-promise`. */
352352
class PgPromiseQueryString extends SQL::SqlString {
353-
PgPromiseQueryString() { this = any(PgPromiseQueryCall qc).getAQueryArgument().asExpr() }
353+
PgPromiseQueryString() { this = any(PgPromiseQueryCall qc).getAQueryArgument() }
354354
}
355355
}
356356

@@ -399,7 +399,7 @@ private module Sqlite {
399399

400400
/** An expression that is passed to the `query` method and hence interpreted as SQL. */
401401
class QueryString extends SQL::SqlString {
402-
QueryString() { this = any(QueryCall qc).getAQueryArgument().asExpr() }
402+
QueryString() { this = any(QueryCall qc).getAQueryArgument() }
403403
}
404404
}
405405

@@ -470,15 +470,15 @@ private module MsSql {
470470
class QueryString extends SQL::SqlString {
471471
QueryString() {
472472
exists(DatabaseAccess dba | dba instanceof QueryTemplateExpr or dba instanceof QueryCall |
473-
this = dba.getAQueryArgument().asExpr()
473+
this = dba.getAQueryArgument()
474474
)
475475
}
476476
}
477477

478478
/** An element of a query template, which is automatically sanitized. */
479479
class QueryTemplateSanitizer extends SQL::SqlSanitizer {
480480
QueryTemplateSanitizer() {
481-
this = any(QueryTemplateExpr qte).getAQueryArgument().asExpr() and
481+
this = any(QueryTemplateExpr qte).getAQueryArgument() and
482482
input = this and
483483
output = this
484484
}

javascript/ql/lib/semmle/javascript/security/dataflow/NosqlInjectionCustomizations.qll

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,5 @@ module NosqlInjection {
3636
}
3737

3838
/** An expression interpreted as a NoSql query, viewed as a sink. */
39-
class NosqlQuerySink extends Sink, DataFlow::ValueNode {
40-
override NoSql::Query astNode;
41-
}
39+
class NosqlQuerySink extends Sink instanceof NoSql::Query { }
4240
}

javascript/ql/lib/semmle/javascript/security/dataflow/NosqlInjectionQuery.qll

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ class Configuration extends TaintTracking::Configuration {
4545
inlbl = TaintedObject::label() and
4646
outlbl = TaintedObject::label() and
4747
exists(NoSql::Query query, DataFlow::SourceNode queryObj |
48-
queryObj.flowsToExpr(query) and
48+
queryObj.flowsTo(query) and
4949
queryObj.flowsTo(trg) and
5050
src = queryObj.getAPropertyWrite().getRhs()
5151
)

javascript/ql/lib/semmle/javascript/security/dataflow/SqlInjectionCustomizations.qll

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -28,13 +28,11 @@ module SqlInjection {
2828
}
2929

3030
/** An SQL expression passed to an API call that executes SQL. */
31-
class SqlInjectionExprSink extends Sink, DataFlow::ValueNode {
32-
override SQL::SqlString astNode;
33-
}
31+
class SqlInjectionExprSink extends Sink instanceof SQL::SqlString { }
3432

3533
/** An expression that sanitizes a value for the purposes of string based query injection. */
36-
class SanitizerExpr extends Sanitizer, DataFlow::ValueNode {
37-
SanitizerExpr() { astNode = any(SQL::SqlSanitizer ss).getOutput() }
34+
class SanitizerExpr extends Sanitizer {
35+
SanitizerExpr() { this = any(SQL::SqlSanitizer ss).getOutput() }
3836
}
3937

4038
/** An GraphQL expression passed to an API call that executes GraphQL. */
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import javascript
22

33
query predicate test_query20(SQL::SqlString ss, string res) {
4-
ss instanceof AddExpr and res = "Use templating instead of string concatenation."
4+
ss.asExpr() instanceof AddExpr and res = "Use templating instead of string concatenation."
55
}

0 commit comments

Comments
 (0)