[Javascript]: How to filter out StringLiteral source with LogicalOrExpr #701
-
Hi, I'm trying get my query to filter out For example: const token1 = process.env.TOKEN || 'token value'; // query should filter this out as source.
const token2 = 'token value'; // query should pick this up as source. codeql query: class NoneEmptyStringLiteral extends DataFlow::Node {
NoneEmptyStringLiteral() {
this.asExpr().(StringLiteral).getValue().length() > 1 and
not this.asExpr().(LogicalOrExpr).getRightOperand() instanceof StringLiteral
}
} Above query somehow works, but i'm not sure how the part What i'm confused about is what if i wish to get following line with comment. const token1 = process.env.TOKEN || 'token value'; // query should pick this up as source.
const token2 = 'token value'; Removing negation does not seem to work. class NoneEmptyStringLiteral extends DataFlow::Node {
NoneEmptyStringLiteral() {
this.asExpr().(StringLiteral).getValue().length() > 1 and
this.asExpr().(LogicalOrExpr).getRightOperand() instanceof StringLiteral // this does not have any effect.
}
} Hope this make sense :) |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 3 replies
-
You have a mistake in your I think you want something like this: class LogicalOrWithNonEmptyString extends DataFlow::Node {
LogicalOrWithNonEmptyString() {
exists(LogicalOrExpr logOr | logOr = this.asExpr() |
logOr.getAnOperand().(StringLiteral).getValue().lengt() > 1
)
}
} Or maybe: class LogicalOrWithNonEmptyString extends DataFlow::ValueNode {
override LogicalOrExpr astNode;
LogicalOrWithNonEmptyString() { astNode.getAnOperand().(StringLiteral).getValue() != "" }
} |
Beta Was this translation helpful? Give feedback.
You have a mistake in your
NoneEmptyStringLiteral
.You write both
this.asExpr().(StringLiteral)
andthis.asExpr().(LogicalOrExpr)
, which requires that the same dataflow-node is both a logical or and a stringliteral at the same time, which cannot happen.I think you want something like this:
Or maybe: