AI-generated analysisPublished automatically and not human-verified. Validated context appears in community notes below.
← Watch feed
Informational 18 Bitcoin

test: functional: drop rmtree usage and add lint check

Public commit record

What the developer wrote

Authored by David Gumberg

100/100 · Strong
test: functional: drop rmtree usage and add lint check

`shutil.rmtree` is dangerous because it recursively deletes. There are
not likely to be any issues with it's current uses, but it is possible
that some of the assumptions being made now won't always be true, e.g.
about what some of the variables being passed to `rmtree` represent.

For some remaining uses of rmtree that can't be avoided for now, use
`cleanup_dir` which asserts that the recursively deleted folder is a
child of the the `tmpdir` of the test run. Otherwise,
`tempfile.TemporaryDirectory` should be used which does it's own
deleting on being garbage collected, or old fashioned unlinking and
rmdir in the case of directories with known contents.
✓ Specific, descriptive subject✓ Names a concrete action or component✓ Uses a recognizable type or scope✓ Provides detailed explanatory context✓ Explains rationale or failure mode✓ Mentions testing or verification
The short version

What changed, and why it matters

This commit is a hardening change for Bitcoin Core's test code. It removes most uses of shutil.rmtree, a Python function that recursively deletes directories, because it could accidentally wipe out the wrong folder if a test variable ever pointed somewhere unexpected. The patch replaces those calls with safer alternatives: a new cleanup_folder helper that refuses to delete anything outside the test's temporary directory, tempfile.TemporaryDirectory which cleans itself up, or explicit removal of known files. It also adds a lint rule to prevent new rmtree uses in test code. This is a defensive, preventive fix in the test suite, not a fix for an active security bug in the running Bitcoin node software.

Recommended action

No urgent action needed. Reviewers should verify that cleanup_folder's path check correctly handles symlink and path-normalization edge cases, and that the lint exclusion for test_framework.py is appropriately narrow. Consider whether the lint should also cover test/functional/test_framework/ submodules if rmtree is later added there.

Security signals we found

01

Defensive removal of recursive deletion primitive in test code

02

Addition of path-relative-to-tmpdir guard before recursive delete

03

New lint rule to prevent reintroduction of shutil.rmtree in functional tests

04

Use of tempfile.TemporaryDirectory for automatic cleanup of IPC/coverage temp dirs

05

Commit message explicitly states this is precautionary, not a known exploit

Risk score

Why this scored 18/100

Our methodology →
Potential impact 2/30
Exploitability 1/25
Stealth signal 1/15
Affected reach 2/15
Confidence 8/10
Evidence quality 4/5
Human-validated context

Community notes

Notes can correct, qualify, or add evidence to the AI analysis. Every note shown here has been validated by a human moderator.

No validated notes yet.

The AI analysis stands alone for now. Submit a note if you can add evidence or important context.