Skip to content

fix(cli): keep attachment-download --all inside --output-dir - #36

Open
amirhmoradi wants to merge 1 commit into
mainfrom
upstream-sync/2026-10-05-attachment-filenames
Open

amirhmoradi wants to merge 1 commit into
mainfrom
upstream-sync/2026-10-05-attachment-filenames

Conversation

@amirhmoradi

Copy link
Copy Markdown
Contributor

Summary

tb attachment-download <id> --all --output-dir <dir> built each file path as join(dir, <attachment name>). Attachment names come from whoever sent the email, so a name like ../../.bashrc or /etc/cron.d/job wrote outside <dir>.

Names now go through a new safeFileName() in cli/src/client.js:

  • keeps only the last path segment (splits on / and \),
  • replaces control characters and Windows-reserved characters (<>:"|?*) with _,
  • falls back to attachment-<partName> when nothing usable is left (empty, ., .., trailing separator).

The single-file form (--output <path>) is unchanged because the user picks that path. CLI only. Nothing under extension/, bridge/ or the access policy changes.

Credit: the idea comes from DreatNU-oss/thunderbird-cli 651d9f1. This is a reimplementation; no fork code was copied. Found by the weekly upstream & forks scan (ODIAA-2402).

Changes

  • cli/src/client.js: safeFileName(name, fallback)
  • cli/src/cli.js: attachment-download --all uses it
  • test/quick-test.mjs: 8 cases (traversal, absolute, Windows separators, reserved chars, fallbacks)
  • docs/COMMANDS.md: documents the naming rule
  • CHANGELOG.md: ### Security entry under [Unreleased]

No command or tool count change (74 CLI / 42 MCP).

Tests

  • npm run test:all: pass (exit 0, every suite reports 0 failed; quick-test 74/74)
  • npm run test:pack-smoke: pass (10/10)

🤖 Generated with Claude Code

Attachment names come from the sender. `--all` joined them straight onto
--output-dir, so a name like "../../.bashrc" or "/etc/cron.d/job" wrote
outside the chosen directory. Names now go through safeFileName(), which
keeps only the last path segment (/ or \), replaces control and
Windows-reserved characters, and falls back to attachment-<partName>.

Idea from DreatNU-oss/thunderbird-cli 651d9f1 (reimplemented, not copied).
Found by the weekly upstream & forks scan (ODIAA-2402).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

This branch has not been deployed

No deployments
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