Skip to content

Python: Add small api enhancements determined useful during documentation work#5398

Merged
RasmusWL merged 6 commits into
github:mainfrom
yoff:python-api-enhancements
Apr 6, 2021
Merged

Python: Add small api enhancements determined useful during documentation work#5398
RasmusWL merged 6 commits into
github:mainfrom
yoff:python-api-enhancements

Conversation

@yoff
Copy link
Copy Markdown
Contributor

@yoff yoff commented Mar 12, 2021

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.

@yoff yoff requested a review from a team as a code owner March 12, 2021 17:11
Copy link
Copy Markdown
Contributor

@tausbn tausbn left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good to me. I have made a few suggestions on some minor things I noticed.

Comment thread python/ql/src/semmle/python/dataflow/new/internal/DataFlowPublic.qll Outdated
Comment thread python/ql/src/semmle/python/dataflow/new/internal/LocalSources.qll Outdated
Comment thread python/ql/src/semmle/python/dataflow/new/internal/LocalSources.qll Outdated
Comment on lines +2 to +5
* 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.
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 ParameterNode now extends LocalSourceNode, thus making methods like flowsTo available.
  • Local taint tracking can now be performed using the taintFlowsTo method on the LocalSourceNode class.

and so on...

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I like that direction..

@yoff yoff requested a review from tausbn March 12, 2021 18:00
tausbn
tausbn previously approved these changes Mar 12, 2021
Copy link
Copy Markdown
Contributor

@tausbn tausbn left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Comment thread python/change-notes/2021-03-12-small-api-enhancements.md
tausbn
tausbn previously approved these changes Mar 13, 2021
Comment thread python/ql/src/semmle/python/dataflow/new/internal/LocalSources.qll Outdated
Comment thread python/ql/src/semmle/python/dataflow/new/internal/DataFlowPublic.qll Outdated
Copy link
Copy Markdown
Member

@RasmusWL RasmusWL left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Indeed that imports all the concepts and actually changes test output (because all classes are also django helper classes).

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have opened the relevant can of worms on slack...

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

actually changes test output (because all classes are also django helper classes).

What output is changed? (what tests are we talking about)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

// Removing this import perturbs the compilation process enough that the points-to analysis gets
// compiled -- and cached -- differently depending on whether the data flow library is imported. By
// importing it privately here, we ensure that the points-to analysis is compiled the same way.
private import semmle.python.dataflow.new.DataFlow
, and with this change, we privately bring the taint tracking library into scope, which transitively brings all our framework modeling into scope.

@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.

@yoff yoff requested a review from RasmusWL March 16, 2021 23:13
@RasmusWL RasmusWL removed their request for review March 17, 2021 10:45
yoff and others added 4 commits March 17, 2021 15:11
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...
@yoff yoff force-pushed the python-api-enhancements branch from b74d640 to b3ff3f7 Compare March 17, 2021 14:12
@yoff yoff requested a review from RasmusWL March 17, 2021 14:13
@yoff
Copy link
Copy Markdown
Contributor Author

yoff commented Mar 17, 2021

Sorry for the force push, but I did not feel like dancing with git revert...

Copy link
Copy Markdown
Member

@RasmusWL RasmusWL left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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? 😊

@yoff
Copy link
Copy Markdown
Contributor Author

yoff commented Mar 17, 2021

That is fine, there is no great rush here.

and `taintFlowsTo` for now..
@yoff yoff requested review from RasmusWL and tausbn March 24, 2021 00:23
RasmusWL
RasmusWL previously approved these changes Mar 24, 2021
Copy link
Copy Markdown
Member

@RasmusWL RasmusWL left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍 as we agreed

Copy link
Copy Markdown
Member

@RasmusWL RasmusWL left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Still 👍

@RasmusWL RasmusWL merged commit 0ebb24e into github:main Apr 6, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants