Skip to content

Python: Port taint tests to use inline expectations #5687

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
Apr 21, 2021

Conversation

RasmusWL
Copy link
Member

The meat of this PR is described in the new python/ql/test/experimental/meta/InlineTaintTest.qll file:

Defines a InlineExpectationsTest for checking whether any arguments in
ensure_tainted and ensure_not_tainted calls are tainted.

Also defines query predicates to ensure that:

  • if any arguments to ensure_not_tainted are tainted, their annotation is marked with SPURIOUS.
  • if any arguments to ensure_tainted are not tainted, their annotation is marked with MISSING.

The functionality of this module is tested in ql/test/experimental/meta/inline-taint-test-demo.

One of the things I liked the best about the old TestTaint.expected files was that it was easy to see how many failures we had. However, it's annoying to review code that only changes the .expected file, since you need to manually look up the .py file to get the full picture of what is now handled (see here as an example).

To ensure we can still easily get an overview of failures, I introduced the requirement to add SPURIOUS and MISSING annotations. So it should be easy to grep for (SPRURIOUS|MISSING): tainted and find all cases our taint-steps could be improved.

In regards to reviewing, it will be a pain to go through all files individually to see that everything is the same as before (I know, since I did this myself 😢) -- so I'll suggest that you look at the demo, and if you are convinced that the new InlineTaintTest.qll works properly, this PR should be good to go if tests pass 🤞

The meat of this PR is described in the new python/ql/test/experimental/meta/InlineTaintTest.qll file:

> Defines a InlineExpectationsTest for checking whether any arguments in
> `ensure_tainted` and `ensure_not_tainted` calls are tainted.
>
> Also defines query predicates to ensure that:
> - if any arguments to `ensure_not_tainted` are tainted, their annotation is marked with `SPURIOUS`.
> - if any arguments to `ensure_tainted` are not tainted, their annotation is marked with `MISSING`.
>
> The functionality of this module is tested in `ql/test/experimental/meta/inline-taint-test-demo`.
@RasmusWL RasmusWL added the no-change-note-required This PR does not need a change note label Apr 15, 2021
@RasmusWL RasmusWL requested a review from a team as a code owner April 15, 2021 16:12
@@ -3,73 +3,73 @@

class TaintTest(tornado.web.RequestHandler):
def get(self, name = "World!", number="0", foo="foo"): # $ requestHandler routedParameter=name routedParameter=number
ensure_tainted(name, number)
ensure_tainted(name, number) # $ tainted
Copy link
Contributor

Choose a reason for hiding this comment

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

Here you now have to split into two lines.

Copy link
Member Author

@RasmusWL RasmusWL Apr 19, 2021

Choose a reason for hiding this comment

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

no, this just means that all arguments on that line are tainted 😉

I didn't add any explicit tests showing what happens on ensure_tainted(is_tainted, is_not_tainted_yet) # $ tainted, but it should complain that there is a missing results for is_not_tainted_yet, which means it should be split into multiple lines. I'll just double check.

Copy link
Contributor

@yoff yoff left a comment

Choose a reason for hiding this comment

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

This is a great initiative 💪
In the longer run, I would prefer if we could generalise the interface to InlineExpectationTest so that we could recognise ensure_tainted and ensure_not_tainted as annotations directly. But given how you have coded around this very nicely (with your extra consistency predicates), it is more a nice-to-have at this point.

Only two minor points, which came piecemeal because I pressed the wrong button..

@RasmusWL
Copy link
Member Author

I added a few more examples of what is ok and what isn't (and how errors will look like). I also updated the format of my query predicates to better match what is usually given by inline test expectations 👍

@RasmusWL RasmusWL requested a review from yoff April 19, 2021 13:02
Copy link
Contributor

@yoff yoff left a comment

Choose a reason for hiding this comment

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

LGTM, happy to merge once the conflicts are resolved.

@RasmusWL
Copy link
Member Author

@RasmusWL RasmusWL requested a review from yoff April 21, 2021 08:08
Copy link
Contributor

@yoff yoff left a comment

Choose a reason for hiding this comment

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

LGTM

@yoff
Copy link
Contributor

yoff commented Apr 21, 2021

Interesting part of merge is 63a2657#diff-b952effafd539a00838363ef1cc0369a465f5f3687d60c839ceb19d3cf970da6

Thanks 😅

@codeql-ci codeql-ci merged commit 30d7f0d into github:main Apr 21, 2021
@RasmusWL
Copy link
Member Author

:shipit:

@RasmusWL RasmusWL deleted the inline-taint-tests branch April 21, 2021 13:24
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
no-change-note-required This PR does not need a change note Python
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants