github / github/codeql

codeql js taint tracking - write "recursive" additional taint step

Đang mở
#19,098 2 bình luận 0 reaction 1 người được giao Được @mbg nhận Xem trên GitHub
javascript question
Ngôn ngữ chính
CodeQL
Star
10.1k
Fork
2.1k
Merge trung bình
2 ngày 15 giờ
Pull request đã merge (30 ngày)
141

Mô tả

I have the following code:
```js
function source() {
fn0();
fn1();
}

function fn0() {
const a = process.env.SECRET;
sink(a);
}

function fn1() {
fn0();
}
```

In this example everything coming from the env is tainted. However, I do not want to find a taint path that starts at `fn0` (where we have the env propread), but from `source`.

I came up with the following config that uses `isAdditionalFlowStep` to check whether the current function has a call to a function where an env propread is made:

```ql
module Config implements DataFlow::ConfigSig {
predicate isSource(DataFlow::Node source) {
exists(Function f |
f.getName() = "source" and
(
source.asExpr() = f.getAParameter()
or
source.(DataFlow::FunctionNode).getFunction() = f
)
)
}

predicate isSink(DataFlow::Node node) {
exists(DataFlow::CallNode cn |
cn.getAnArgument() = node and
cn.getCalleeName() = "sink"
)
}

predicate isAdditionalFlowStep(DataFlow::Node fromNode, DataFlow::Node toNode) {
exists(DataFlow::FunctionNode fnEnv, DataFlow::PropRead propRead |
propRead = toNode and
propRead.getPropertyName() = "SECRET" and
propRead.asExpr().getEnclosingFunction() = fnEnv.getFunction() and
fromNode.(DataFlow::InvokeNode).getACallee() = fnEnv.getFunction()
)
or
toNode.(DataFlow::InvokeNode).getEnclosingFunction() =
fromNode.(DataFlow::FunctionNode).getFunction()
}
}
```

This finds the taint path `source` -> `fn0`, but not `source`->`fn1`->`fn0`.
I am not sure how to restructure the predicate to introduce these taint steps in a recursive manner.

Hướng dẫn đóng góp

Mở hướng dẫn đóng góp

Đánh giá

Issue này chưa được đánh giá.

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.