github / github/codeql

Python: Local/Global dataflow analysis not tracing class field?

オープン
#17,021 コメント 3 件 リアクション 0 件 担当者 0 名 GitHub で見る
question
主要言語
CodeQL
スター
10.1k
フォーク
2.1k
平均マージ
2日 15時間
マージ済み PR(30日)
141

説明

## Python
```python
class Cls:
def __init__(self) -> None:
self.field = 1
def __init__(self, num) -> None:
self.field = num
def print(self) -> None:
print(self.field)

if __name__ == '__main__':
var1 = Cls(2)
var2 = var1
var2.field = 3
var1.print()
var1.field2 = 4
print(var2.field2)

```
## CodeQL
```codeql
import python
import semmle.python.ApiGraphs
import semmle.python.dataflow.new.DataFlow
import semmle.python.dataflow.new.TaintTracking

module MyConf implements DataFlow::ConfigSig {
predicate isSource(DataFlow::Node source) {
source.asExpr() instanceof IntegerLiteral
}
predicate isSink(DataFlow::Node sink) {
sink = API::builtin("print").getACall().getArg(0)
}
}

module MyFlow = DataFlow::Global;

from DataFlow::Node source, DataFlow::Node sink
where MyFlow::flow(source, sink)
select source, sink
```
## Output
|source|sink|
|-|-|
|1|`self.field` in line 7|
|2|`self.field` in line 7|
## Expected result
|source|sink|
|-|-|
|1|`self.field` in line 7|
|2|`self.field` in line 7|
|3|`self.field` in line 7|
|4|`self.field` in line 16|

コントリビューションガイド

コントリビューションガイドを開く

調査の方向性

Start with the Python local/global dataflow implementation and the DataFlow::Global configuration in the issue's CodeQL example. Reproduce the query against the provided Python program, then trace how assignments to self.field and self.field2 are modeled. Done means the output includes sources 3 and 4 at the expected sinks.

索引モデルが issue の本文から書いたものです。

評価

技術スタック
python
領域
devtools, security
issue の種類
バグ
難易度
4/5
見積もり時間
3〜5日
活発さ
停滞
明瞭さ
おおむね明確
初心者へのやさしさ
35/100

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。