Python: Untrusted data used in external APIs #4735
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
My main goal for this PR was to provide something that is useful fairly quickly. Therefore I'm doing a few dirty tricks. See more details in the
.qllfile.As indicated in the test-file, there are a few limitations.
In
from unknown.lib import func; func(data),funcwill point-to Missing module attribute unknown.lib.func, so there will not even be aDataFlowPrivate::DataFlowCall.In
import unknown.lib; unknown.lib.func(data),funcdoesn't have any points-to information. Again, noDataFlowPrivate::DataFlowCallfor this call.I could have tried to handle this, but I decided not to invest more time in this. The query is not perfect, but should be helpful by now. Let's discuss if you think that's wrong :)
P.S. I added the
ExternalAPIs.qllfile right next to the query files. This means it can't be imported by anyone else (since there is a-in the path to it). Initially I just had it there because it was easy, but I was slightly skeptical about moving it topython/ql/src/semmle/python/security/dataflow/ExternalAPIs.qll, just because I wasn't too happy about publicly exposing it and having to think about deprecations for a file that I'm already actively planning to rewrite in the future. Let me know if you think we should do it differently.