Open
Conversation
Adds test cases from #21582 demonstrating false negatives: - Address stored in class attribute (`self.bind_addr`) - `os.environ.get` with insecure default value - `gevent.socket` (alternative socket module)
This takes care of most of the false negatives from the preceding commit. Additionally, we add models for some known wrappers of `socket.socket` from the `gevent` and `eventlet` packages.
51859b9 to
c0ce669
Compare
Now that we're using global data-flow, we might as well make use of the fact that we know where the source is.
Looking at the results of the the previous DCA run, there was a bunch of false positives where `bind` was being used with a `AF_UNIX` socket (a filesystem path encoded as a string), not a `(host, port)` tuple. These results should be excluded from the query, as they are not vulnerable. Ideally, we would just add `.TupleElement[0]` to the MaD sink, except we don't actually support this in Python MaD... So, instead I opted for a more low-tech solution: check that the argument in question flows from a tuple in the local scope. This eliminates a bunch of false positives on `python/cpython` leaving behind four true positive results.
Contributor
There was a problem hiding this comment.
Pull request overview
Improves the Python py/bind-socket-all-network-interfaces query to reduce false negatives (per #21582) by switching to global data-flow/Models-as-Data, and updates its tests to use inline expectations.
Changes:
- Convert the query to a
path-problemusing global taint tracking and Models-as-Data sinks. - Add/extend Models-as-Data type/sink models for
socket.socket.bind, and wrapper socket implementations ingevent/eventlet. - Migrate the query test to inline expectations and add regression cases.
Reviewed changes
Copilot reviewed 9 out of 9 changed files in this pull request and generated 1 comment.
Show a summary per file
| File | Description |
|---|---|
| shared/mad/codeql/mad/ModelValidation.qll | Allows the new sink kind used by the query’s Models-as-Data integration. |
| python/ql/src/Security/CVE-2018-1281/BindToAllInterfaces.ql | Updates the query to use global data-flow and emit paths. |
| python/ql/lib/semmle/python/frameworks/Stdlib.model.yml | Adds a bind() sink model and a socket.socket type model entry. |
| python/ql/lib/semmle/python/frameworks/Gevent.model.yml | Models gevent.socket.socket return type as socket.socket. |
| python/ql/lib/semmle/python/frameworks/Eventlet.model.yml | Models eventlet socket wrappers’ return type as socket.socket. |
| python/ql/test/query-tests/Security/CVE-2018-1281/BindToAllInterfaces_test.py | Converts to inline expectations and adds FN regression scenarios. |
| python/ql/test/query-tests/Security/CVE-2018-1281/BindToAllInterfaces.qlref | Enables inline expectation postprocessing for the test. |
| python/ql/test/query-tests/Security/CVE-2018-1281/BindToAllInterfaces.expected | Updates expected output for the new path-problem/inline expectations harness. |
| python/ql/src/change-notes/2026-03-26-improve-bind-all-interfaces-query.md | Documents the analysis change and new library recognition. |
python/ql/src/change-notes/2026-03-26-improve-bind-all-interfaces-query.md
Outdated
Show resolved
Hide resolved
owen-mc
reviewed
Mar 27, 2026
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Addresses the false negatives reported in #21582.
Also converts the tests for that query to use inline expectations.