-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Python : Add Flask sinks for path injection query #6330
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
Conversation
Just a small note : https://github.com/cksgf/ServerManagement/blob/49491cc6f94980e6be7791d17be947c27071eb56/route/file.py#L93 should be a true positive for this case but since add a flow to track that may add a lot of FP's, I am in two minds here. @RasmusWL Any thoughts on this? |
I think having additional taint steps for We've added these things like this in the past: codeql/python/ql/src/semmle/python/frameworks/Stdlib.qll Lines 44 to 52 in d282f6a
Would also be great if you can implement the new sink by using codeql/python/ql/src/semmle/python/frameworks/Stdlib.qll Lines 394 to 404 in d282f6a
|
a476229
to
c1c1d89
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Since the creation of this PR, we have added support for os.path.dirname
(see below), so please merge in newest main
, and remove that part.
codeql/python/ql/lib/semmle/python/frameworks/Stdlib.qll
Lines 283 to 291 in 8b6baa2
/** An additional taint step for path computations. */ | |
private class OsPathComputationAdditionalTaintStep extends TaintTracking::AdditionalTaintStep { | |
override predicate step(DataFlow::Node nodeFrom, DataFlow::Node nodeTo) { | |
exists(OsPathComputation call | | |
nodeTo = call and | |
nodeFrom = call.getPathArg() | |
) | |
} | |
} |
If you can add your new modeling to this file instead https://github.com/github/codeql/blob/main/python/ql/lib/semmle/python/frameworks/Flask.qll (and adjust QLDoc accordingly), I would be happy to merge this PR 👍 I'm not sure how I did not spot this on my last review, sorry about that 🤷♂️
Having a test that shows off the new modeling would also be very good, and should be added somewhere within this folder: https://github.com/github/codeql/tree/main/python/ql/test/library-tests/frameworks/flask it should use the format expected by our ConceptsTest, so something like the one below, highlight all the interesting different variations that we handle (that is, using both normal arguments and keyword arguments) flask.send_from_directory("filepath") # $ getAPathArgument="filepath" |
c1c1d89
to
4fd3f21
Compare
@RasmusWL I need some help fixing the tests here. the tests fail with the output I attach below. The arguments are detected by CodeQL on real projects otherwise. So, this looks like an issue with the test runner.
I don't have a clue what's wrong here. Can you please take a look? |
and auto-formatting
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM now, thanks for updating it 👍
Flask's
send_file
andsend_from_directory
calls can allow a remote attacker to potentially access any file stored on the system if the path is controlled by them.This query modifies the existing Python path injection query to add support for the same.