Skip to content

Commit a391d34

Browse files
committed
Fix a regression in taintedclause
1 parent 468a780 commit a391d34

File tree

4 files changed

+14
-7
lines changed

4 files changed

+14
-7
lines changed

javascript/frameworks/cap/lib/advanced_security/javascript/frameworks/cap/CAPCqlInjectionQuery.qll

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,12 +41,13 @@ class CqlShortcutMethodCallWithStringConcat instanceof CqlShortcutMethodCall {
4141
}
4242

4343
/**
44-
* A CQL parser call (cds.ql, cds.parse.cql, ...) parameterized with a string
44+
* A CQL parser call (`cds.ql`, `cds.parse.cql`, ...) parameterized with a string
4545
* conatenation expression.
4646
*/
4747
class CqlClauseParserCallWithStringConcat instanceof CqlClauseParserCall {
4848
CqlClauseParserCallWithStringConcat() {
49-
exists(StringConcatenation::getAnOperand(super.getCdlString()))
49+
not this.getCdlString().(StringOps::Concatenation).asExpr() instanceof TemplateLiteral and
50+
exists(StringConcatenation::getAnOperand(this.getCdlString()))
5051
}
5152

5253
Location getLocation() { result = super.getLocation() }

javascript/frameworks/cap/lib/advanced_security/javascript/frameworks/cap/CDS.qll

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -942,11 +942,17 @@ class CqlUpsertMethodCall extends CqlShortcutMethodCall {
942942
abstract class CqlClauseParserCall extends DataFlow::CallNode {
943943
DataFlow::ExprNode cdlString;
944944

945+
/**
946+
* Gets the data flow node that represents the CDL string to be parsed.
947+
*/
945948
DataFlow::ExprNode getCdlString() { result = cdlString }
946949
}
947950

948951
class GlobalCQLFunction extends CqlClauseParserCall {
949-
GlobalCQLFunction() { this = DataFlow::globalVarRef("CQL").getACall() }
952+
GlobalCQLFunction() {
953+
this = DataFlow::globalVarRef("CQL").getACall() and
954+
cdlString = this.getArgument(0)
955+
}
950956
}
951957

952958
class CdsParseCqlCall extends CqlClauseParserCall {
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import javascript
2-
import advanced_security.javascript.frameworks.cap.CQL
2+
import advanced_security.javascript.frameworks.cap.CAPCqlInjectionQuery
33

4-
from ParseCQLTaintedClause clause
4+
from CqlClauseParserCallWithStringConcat clause
55
select clause

javascript/frameworks/cap/test/queries/cqlinjection/srv/service1.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -167,9 +167,9 @@ module.exports = class Service1 extends cds.ApplicationService {
167167
});
168168

169169
/* ========== 7. Service1 running query on the database service using CQN parsed with global function `CQL` ========== */
170-
this.on("send6", async (req) => {
170+
this.on("send7", async (req) => {
171171
const { id } = req.data;
172-
const query = cds.parse.cql(`SELECT * from Entity1 where ID =` + id);
172+
const query = CQL(`SELECT * from Entity1 where ID =` + id);
173173
cds.run(query);
174174
});
175175

0 commit comments

Comments
 (0)