Python: Add small api enhancements determined useful during documentation work#5398
Conversation
tausbn
left a comment
There was a problem hiding this comment.
Looks good to me. I have made a few suggestions on some minor things I noticed.
| * Make `ParameterNode` extend `LocalSourceNode`, thus making members like `flowsTo` available. | ||
| * Add member predicate `taintFlowsTo` to `LocalSourceNode` facilitating smoother syntax for local taint tracking. | ||
| * Add member `getALocalTaintSource` to `DataFlow::Node` facilitating smoother syntax for local taint tracking. | ||
| * Add predicate `parameterNode` to map from a `Parameter` to a data-flow node. |
There was a problem hiding this comment.
I'm a bit unsure about the way in which these sentences are formulated. They read more like commit messages than change notes. Perhaps one could rewrite this as e.g.
- The class
ParameterNodenow extendsLocalSourceNode, thus making methods likeflowsToavailable. - Local taint tracking can now be performed using the
taintFlowsTomethod on theLocalSourceNodeclass.
and so on...
There was a problem hiding this comment.
I like that direction..
tausbn
left a comment
There was a problem hiding this comment.
I'm still wondering if we should leave out the taint stuff until we have disentangled things a bit. I'll leave that decision up to you and rasmuswl.
RasmusWL
left a comment
There was a problem hiding this comment.
Nice, one small suggestion from me, otherwise looks good 👍
|
|
||
| /** | ||
| * Gets a local source node from which data may flow to this node in zero or more local taint-flow steps. | ||
| * WARNING: This will only have results if the taint tracking libraries have been imported into scope. |
There was a problem hiding this comment.
This warning seems annoying. Is there anything blocking us from just adding a private import TaintTrackingPublic? -- which would make things work out of the box
There was a problem hiding this comment.
Indeed that imports all the concepts and actually changes test output (because all classes are also django helper classes).
There was a problem hiding this comment.
I have opened the relevant can of worms on slack...
There was a problem hiding this comment.
actually changes test output (because all classes are also django helper classes).
What output is changed? (what tests are we talking about)
There was a problem hiding this comment.
We talked about this face-to-face. This approach had been taken previously, and the test changes can be seen in changes from b3ff3f7 (where suddenly, classes are also treated as DjangoViewClassHelper when using getAQlClass). This stems from the fact that as part of impoty python we also privately import the dataflow library
codeql/python/ql/src/python.qll
Lines 40 to 43 in 7e3dbb0
@yoff and I talked a bit about the fact that importing taint-tracking would also import all external library models, so that all concrete subclasses of AdditionalTaintStep would also be in scope, following the advice in https://github.com/github/codeql/blob/main/docs/ql-design-patterns.md#importing-all-subclasses-of-a-class (that arguably, I wrote myself).
In the end, we opted for making getALocalTaintSource just works out of the box without having to remember to import something manually yourself.
determined useful during documentation work.
Co-authored-by: Taus <tausbn@github.com>
I suspect it has to do with ParameterNode being a LocalSourceNode, but I really have no idea...
b74d640 to
b3ff3f7
Compare
|
Sorry for the force push, but I did not feel like dancing with |
RasmusWL
left a comment
There was a problem hiding this comment.
Since this import question is hard to change our mind about later down the line, I think it would be wise to exercise a bit more caution before merging this PR. Possibly even wait until we have had a chance to talk with Taus about this? 😊
|
That is fine, there is no great rush here. |
and `taintFlowsTo` for now..
These are features we would like to use in the examples in the documentation. We cannot do that before they are implemented and live.
This PR implement them, we will have to remember to update the documentation once they are live.