Draft
Python: Add taint flow through list.extend and list.insert#22310
Conversation
Co-authored-by: hvitved <3667920+hvitved@users.noreply.github.com>
Copilot
AI
changed the title
[WIP] Fix taint loss in list.extend, list.insert, and += methods
Python: Add taint flow through list.extend and list.insert
Aug 10, 2026
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.
CodeQL's Python taint tracking propagated through
list.appendbut not throughlist.extend,list.insert, or+=, causing security queries (e.g.CommandInjection.ql) to silently miss flows that differ only in which list-mutation idiom is used.Flow summaries
ListExtendflow summary inpython/ql/lib/semmle/python/frameworks/Stdlib.qll: propagates element content from the argument'sListElement/SetElement/AnyTupleElementinto the receiver'sListElement, plus a blunt taint fallback — same shape as the existingListAppend/ListSummary/SetSummarymodels.ListInsertflow summary: propagates the inserted value into the receiver'sListElement, plus a blunt taint fallback.Tests
test_collections.py:list_extend()now assertstainted(previouslyMISSING); addedlist_extend_iteration()andlist_insert()covering the new summaries.test_builtins.py: added precise flow-label tests forlist.extendandlist.insert.Known remaining gap:
+=acc += [user]still isn't tracked. It desugars to Python's+operator, handled by the sharedconcatStep, which is a global additional taint step — the shared dataflow library deliberately withholds "implicit content read" privileges from such global steps (only sinks and locally-defined config steps get them), so a list value flowing through+isn't unwrapped to see its tainted content. Fixing this properly needs new content-aware store/read steps for binary+in the core dataflow library, a materially larger change than a library flow summary. This is left as a documentedMISSINGtest case (list_iadd()), consistent with the pre-existing, similarly-unaddresseddict |merge gap in the same test file.