Skip to content

fix(update): set filter="data" on tarfile.extractall in auto-updater#2298

Open
ktwu01 wants to merge 1 commit into
MoonshotAI:mainfrom
ktwu01:fix/updater-tarfile-filter-2273
Open

fix(update): set filter="data" on tarfile.extractall in auto-updater#2298
ktwu01 wants to merge 1 commit into
MoonshotAI:mainfrom
ktwu01:fix/updater-tarfile-filter-2273

Conversation

@ktwu01
Copy link
Copy Markdown

@ktwu01 ktwu01 commented May 15, 2026

Summary

Partial fix for #2273 — addresses the third sub-item (defense-in-depth on the extractor) without touching the sha256-manifest piece, which needs a CDN-side change to publish .sha256 sidecars and is best handled by the maintainers.

src/kimi_cli/ui/shell/update.py extracted the downloaded update tarball with bare tar.extractall(tmpdir). PEP 706 deprecated this call shape: Python 3.12 emits DeprecationWarning and a future release will raise. filter="data" is the recommended default — it rejects absolute paths, parent-traversal members, device nodes, setuid bits, and symlinks pointing outside the extraction tree, which is exactly the right default for an auto-updater that goes on to chmod +x the extracted file.

The codebase's other two archive-extraction sites (cli/plugin.py:77 and vis/api/sessions.py:657) already have explicit path-traversal checks before extractall; the auto-updater was the lone outlier. This brings it in line.

What this PR does NOT cover

The other two items in #2273 (sha256 manifest verification, optional signature verification) require publishing a .sha256 sidecar (or manifest.json) alongside each kimi-{version}-{target}.tar.gz on cdn.kimi.com. That's a CDN/release-pipeline change, not a code-only one — I'd rather leave it to a follow-up where the publishing side and the verifying side can land together. Happy to send that follow-up PR once the team confirms the manifest format and CDN path.

Test plan

  • One-line code change, no behavior change on well-formed tarballs (the canonical kimi-cli release artifacts are flat archives of a kimi binary, which filter="data" does not modify).
  • filter="data" is the safest of the three PEP 706 filters and the documented recommendation for untrusted sources.
  • grep -rn "extractall" src/ confirms this was the only unfiltered site.

Refs #2273


Open in Devin Review

PEP 706 deprecated calling tarfile.extractall() without an explicit
filter argument. Python 3.12 emits DeprecationWarning and a future
release will raise. CVE-2007-4559 (the original "tar slip" bug) made
filter="data" the recommended default: it rejects absolute paths,
parent-traversal members, and special files even for trusted sources,
which is the right default for an auto-updater that writes into a
temp dir and then chmod +x's the result.

The other archive-extraction sites in the codebase (cli/plugin.py:77
and vis/api/sessions.py:657) already have explicit path-traversal
checks before extractall, so this brings the auto-updater in line
with the rest of the codebase as defense-in-depth.

Refs MoonshotAI#2273
Copy link
Copy Markdown
Contributor

@devin-ai-integration devin-ai-integration Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

✅ Devin Review: No Issues Found

Devin Review analyzed this PR and found no potential bugs to report.

View in Devin Review to see 2 additional findings.

Open in Devin Review

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.

1 participant