Python Class Variable data flow #9684
-
Hi, def source():
return "SOURCE"
class Test():
VAR = source()
def sink(s):
print(s)
VAR = source()
sink(VAR) # Found data flow
sink(source()) # Also found
sink(Test().VAR). # Query can't detect this The query I'm using is:
The query should detect all data flows from function |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 5 replies
-
Hi, thank you very much for alerting us to this hole in our analysis! It looks like we do indeed not handle this flow. I think what would be needed is to add a jump step along the lines of predicate readClassVarStep(DataFlow::EssaNode fromNode, DataFlow::AttrRead toNode) {
exists(ClassDef classDef, SsaVariable c | classDef.defines(c.getVariable()) |
fromNode.getVar().getScope() = classDef.getDefinedClass() and
toNode.getObject().(DataFlow::CallCfgNode).getFunction().(DataFlow::CfgNode).getNode() =
c.getAUse()
)
} and then a corresponding one for writing to class variables. I think you cannot add jump steps, but you could add override predicate isAdditionalFlowStep(DataFlow::Node fromNode, DataFlow::Node toNode) {
readClassVarStep(fromNode, toNode)
} to your configuration. Alternatively, depending on your use case, you could perhaps use instance variables instead. We do support those; you can get an idea of what we handle from the field flow tests here and here. |
Beta Was this translation helpful? Give feedback.
Hi, thank you very much for alerting us to this hole in our analysis! It looks like we do indeed not handle this flow. I think what would be needed is to add a jump step along the lines of
and then a corresponding one for writing to class variables.
I think you cannot add jump steps, but you could add