Skip to content

Fix B202: detect unsafe tarfile.extract usage#1393

Open
9iang22 wants to merge 1 commit intoPyCQA:mainfrom
9iang22:fix-b202-extract-coverage-main
Open

Fix B202: detect unsafe tarfile.extract usage#1393
9iang22 wants to merge 1 commit intoPyCQA:mainfrom
9iang22:fix-b202-extract-coverage-main

Conversation

@9iang22
Copy link
Copy Markdown

@9iang22 9iang22 commented Apr 17, 2026

Fix B202 gap for tarfile.extract() calls

B202 currently flags unsafe tar extraction through extractall(), but it does not catch equivalent member-by-member extraction done with tarfile.extract(). This leaves a false-negative path for the CWE-22 path traversal when archive members are not validated.

This change closes that coverage gap, so B202 reports both extraction APIs consistently under the same safety model.
It also updates the functional example and expected counts so that test coverage reflects the added detection path.

Resolves: #1392

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

False negative: B202 unsafe tarfile.extract() not detected

1 participant