Skip to content

Commit b46bb5e

Browse files
committed
Adjust cap log sink model to exclude only constant only template literals
1 parent de3756d commit b46bb5e

File tree

3 files changed

+11
-1
lines changed

3 files changed

+11
-1
lines changed

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

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,12 @@ class CdsLogger extends MethodCallNode {
2222
string getName() { result = name }
2323
}
2424

25+
class ConstantOnlyTemplateLiteral extends TemplateLiteral {
26+
ConstantOnlyTemplateLiteral() {
27+
forall(Expr e | e = this.getAnElement() | e instanceof TemplateElement)
28+
}
29+
}
30+
2531
/**
2632
* Arguments of calls to `cds.log.{trace, debug, info, log, warn, error}`
2733
*/
@@ -31,7 +37,7 @@ class CdsLogSink extends DataFlow::Node {
3137
this = loggingMethod.getAnArgument() and
3238
loggingMethod.getMethodName() = ["trace", "debug", "info", "log", "warn", "error"] and
3339
not this.asExpr() instanceof Literal and
34-
not this.asExpr() instanceof TemplateLiteral and
40+
not exists(ConstantOnlyTemplateLiteral t | this.asExpr() = t) and
3541
loggingMethod.getReceiver().getALocalSource() = log
3642
)
3743
}

javascript/frameworks/cap/test/models/cds/logger/logger.expected

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,3 +5,4 @@
55
| logger.js:7:24:7:28 | code0 |
66
| logger.js:8:25:8:29 | code0 |
77
| logger.js:12:10:12:14 | code1 |
8+
| logger.js:14:10:14:28 | `logging: ${code1}` |

javascript/frameworks/cap/test/models/cds/logger/logger.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,3 +10,6 @@ cds.log('nodejs').error(code0);
1010
const code0 = "some-name";
1111
const LOG = cds.log(code0);
1212
LOG.info(code1);
13+
14+
LOG.info(`logging: ${code1}`);
15+
LOG.info(`not actually logging`);

0 commit comments

Comments
 (0)