Skip to content

Commit c5b1588

Browse files
committed
update the SQL/NoSQL models to use dataflow nodes
1 parent 4d05343 commit c5b1588

File tree

8 files changed

+33
-37
lines changed

8 files changed

+33
-37
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
@@ -115,7 +115,7 @@ predicate isBaseAdditionalFlowStep(
115115
inlbl = TaintedObject::label() and
116116
outlbl = TaintedObject::label() and
117117
exists(NoSql::Query query, DataFlow::SourceNode queryObj |
118-
queryObj.flowsToExpr(query) and
118+
queryObj.flowsTo(query) and
119119
queryObj.flowsTo(trg) and
120120
src = queryObj.getAPropertyWrite().getRhs()
121121
)

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: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@ import javascript
66

77
/** Provides classes for modeling NoSql query sinks. */
88
module NoSql {
9-
/** An expression that is interpreted as a NoSql query. */
10-
abstract class Query extends Expr {
9+
/** An expression that is interpreted as a NoSQL query. */
10+
abstract class Query extends DataFlow::Node {
1111
/** Gets an expression that is interpreted as a code operator in this query. */
1212
DataFlow::Node getACodeOperator() { none() }
1313
}
@@ -84,7 +84,7 @@ private module MongoDB {
8484
class Query extends NoSql::Query {
8585
QueryCall qc;
8686

87-
Query() { this = qc.getAQueryArgument().asExpr() }
87+
Query() { this = qc.getAQueryArgument() }
8888

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

521-
MongoDBQueryPart() { this = f.getQueryArgument().asSink().asExpr() }
521+
MongoDBQueryPart() { this = f.getQueryArgument().asSink() }
522522

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

628-
Query() { this = qc.getAQueryArgument().asExpr() }
628+
Query() { this = qc.getAQueryArgument() }
629629

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

688-
Query() { this = qc.getAQueryArgument().asExpr() }
688+
Query() { this = qc.getAQueryArgument() }
689689

690690
override DataFlow::Node getACodeOperator() { result = qc.getACodeOperator() }
691691
}
@@ -770,7 +770,7 @@ private module Redis {
770770
RedisKeyArgument() {
771771
exists(string method, int argIndex |
772772
QuerySignatures::argumentIsAmbiguousKey(method, argIndex) and
773-
this = redis().getMember(method).getParameter(argIndex).asSink().asExpr()
773+
this = redis().getMember(method).getParameter(argIndex).asSink()
774774
)
775775
}
776776
}

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

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -5,26 +5,26 @@
55
import javascript
66

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

1111
private class SqlStringFromModel extends SqlString {
12-
SqlStringFromModel() { this = ModelOutput::getASinkNode("sql-injection").asSink().asExpr() }
12+
SqlStringFromModel() { this = ModelOutput::getASinkNode("sql-injection").asSink() }
1313
}
1414

1515
/**
16-
* An expression that sanitizes a string to make it safe to embed into
16+
* An dataflow node that sanitizes a string to make it safe to embed into
1717
* a SQL command.
1818
*/
19-
abstract class SqlSanitizer extends Expr {
20-
Expr input;
21-
Expr output;
19+
abstract class SqlSanitizer extends DataFlow::Node {
20+
DataFlow::Node input;
21+
DataFlow::Node output;
2222

2323
/** Gets the input expression being sanitized. */
24-
Expr getInput() { result = input }
24+
DataFlow::Node getInput() { result = input }
2525

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

@@ -90,13 +90,13 @@ private module MySql {
9090

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

9696
/** A call to the `escape` or `escapeId` method that performs SQL sanitization. */
97-
class EscapingSanitizer extends SQL::SqlSanitizer, MethodCallExpr {
97+
class EscapingSanitizer extends SQL::SqlSanitizer instanceof API::CallNode {
9898
EscapingSanitizer() {
99-
this = [mysql(), pool(), connection()].getMember(["escape", "escapeId"]).getACall().asExpr() and
99+
this = [mysql(), pool(), connection()].getMember(["escape", "escapeId"]).getACall() and
100100
input = this.getArgument(0) and
101101
output = this
102102
}
@@ -198,9 +198,9 @@ private module Postgres {
198198
/** An expression that is passed to the `query` method and hence interpreted as SQL. */
199199
class QueryString extends SQL::SqlString {
200200
QueryString() {
201-
this = any(QueryCall qc).getAQueryArgument().asExpr()
201+
this = any(QueryCall qc).getAQueryArgument()
202202
or
203-
this = API::moduleImport("pg-cursor").getParameter(0).asSink().asExpr()
203+
this = API::moduleImport("pg-cursor").getParameter(0).asSink()
204204
}
205205
}
206206

@@ -349,7 +349,7 @@ private module Postgres {
349349

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

@@ -398,7 +398,7 @@ private module Sqlite {
398398

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

@@ -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)