Python: Handle guards being compared to boolean literals#21296
Open
yoff wants to merge 4 commits intogithub:mainfrom
Open
Python: Handle guards being compared to boolean literals#21296yoff wants to merge 4 commits intogithub:mainfrom
yoff wants to merge 4 commits intogithub:mainfrom
Conversation
a80fc8c to
9c2ce6a
Compare
Contributor
There was a problem hiding this comment.
Pull request overview
This PR extends Python’s guard-node handling in the dataflow/tainttracking library so that guard calls (e.g., is_safe(x)) are recognized even when compared against boolean literals using ==, !=, is, and is not.
Changes:
- Extend guard-node recursion to treat comparisons against boolean literals as guard nodes with appropriate polarity.
- Add taint-tracking tests covering
==/!=andis/is notcomparisons toTrue/False, and update expected results. - Add a change note documenting the enhancement.
Reviewed changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
| python/ql/test/library-tests/dataflow/tainttracking/customSanitizer/test_logical.py | Adds a new test function covering boolean-literal comparisons for guards. |
| python/ql/test/library-tests/dataflow/tainttracking/customSanitizer/InlineTaintTest.expected | Updates expected sanitizer/guard nodes for the new test cases. |
| python/ql/lib/semmle/python/dataflow/new/internal/DataFlowPublic.qll | Extends guard-node logic to recurse through boolean-literal comparisons. |
| python/ql/lib/change-notes/2026-02-08-guards-compared-to-boolean-literals.md | Adds a release note for the new guard-comparison handling. |
python/ql/lib/change-notes/2026-02-08-guards-compared-to-boolean-literals.md
Outdated
Show resolved
Hide resolved
python/ql/test/library-tests/dataflow/tainttracking/customSanitizer/test_logical.py
Outdated
Show resolved
Hide resolved
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.
Inspired by https://github.com/github/codeql/pull/21288/changes#diff-502cb70dbb74ee46cda83c2b3c626120ae120bcd444e146be09bc46599cf981eR194-R215
While we wait for adoption of the shared guards library (which will handle much more than this), this PR is an easy addition to the guards handling in Python.
When a guard such as
isSafe(x)is defined, we now also automatically handleisSafe(x) == trueandisSafe(x) != false(as well asisandis not).