Skip to content

Fix non-Latin-1 attachment names and plugin CLI headers timeout - #1809

Merged
SawyerHood merged 2 commits into
mainfrom
bb/draft-pr-for-1621-non-latin-1-chars-em-dash-in-i-thr_8aaxd9sz46
Aug 18, 2026
Merged

SawyerHood merged 2 commits into
mainfrom
bb/draft-pr-for-1621-non-latin-1-chars-em-dash-in-i-thr_8aaxd9sz46

Conversation

@SawyerHood

Copy link
Copy Markdown
Collaborator

What was wrong

Two separate defects produced the symptoms in #1621 (see the investigation report). The TypeError: Cannot convert argument to a ByteString … 8212 log lines came from the bundled tasks plugin: GET /api/v1/plugins/tasks/http/attachments/download wrote the raw attachment file name into the legacy filename= parameter of Content-Disposition. sanitizeFileName keeps non-Latin-1 characters, so an em dash (or CJK, emoji, curly quotes) made the Response constructor throw and every download or inline preview of that attachment returned 500. The bb secret request … fetch failed symptom had a different cause: the CLI proxies plugin commands with one bare fetch() to POST /api/v1/plugins/:id/cli, and the server sends nothing (not even headers) until the command returns. A human who takes more than 5 minutes to fill the secrets form hits Node's default undici headersTimeout (300 s); the fetch rejects with fetch failed, the server sees the abort, and the pending interaction disappears. The secrets path never puts free text into headers.

What changed

  • plugins/tasks/attachments/index.ts: new buildContentDisposition() follows RFC 6266. filename= carries an ASCII fallback (fileName.replace(/[^\x20-\x7e]/g, "-").replace(/["\\]/g, "_")); the real name travels percent-encoded in filename*=UTF-8''…. Stored file names do not change.
  • apps/cli/src/plugin-cli-proxy.ts: runPluginCliCommand dispatches through a lazily created undici Agent({ headersTimeout: 0 }). The server's interaction timeout (10 min default, 1 h max) and a closed socket still bound the wait. undici is imported lazily so built-in bb commands do not pay its startup cost (measured: no change to bb --version time; bundle grows ~1 MB).
  • apps/cli/src/client.ts: cliFetch accepts the Node dispatcher fetch extension (CliRequestInit).
  • apps/cli/package.json / pnpm-lock.yaml: add undici@^7.28.0 (already in the lockfile as a transitive dependency).

Tests

Verification

pnpm exec turbo run build typecheck test --filter=@bb/cli --filter=bb-plugin-tasks --force
# @bb/cli: 49 files, 451 tests passed; bb-plugin-tasks: 36 files, 339 tests passed
pnpm exec prettier --check <changed files>   # clean
pnpm exec eslint <changed files>             # clean

Deviation from the report

The report's preferred fix for the CLI (NDJSON heartbeat streaming for POST /plugins/:id/cli) is out of scope for this PR; this uses the report's cheaper alternative (undici Agent dispatcher). The fix applies to all plugin CLI commands, not only secrets, because the CLI has one shared dispatch path. No server/host-daemon wire change, so no HOST_DAEMON_PROTOCOL_VERSION bump.

Fixes #1621

Report: https://get-bb.github.io/reports/issues/1621.html

AGENT GENERATED: by Claude Opus 5

@bb-slop-cop

bb-slop-cop Bot commented Aug 18, 2026

Copy link
Copy Markdown
Contributor

🚨 SLOP COP 🚨 · review

I am the SlopCop. I am reviewing this pull request for security, code quality, performance, architecture, and end-to-end behavior.

Comment thread plugins/tasks/attachments/index.ts Outdated
const asciiFallback = fileName
.replace(/[^\x20-\x7e]/g, "-")
.replace(/["\\]/g, "_");
const encodedName = encodeURIComponent(fileName).replaceAll("'", "%27");

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🚨 slopcop/review — The new filename* value is invalid for names with parentheses.

encodeURIComponent leaves parentheses unescaped. RFC 5987 excludes them from attr-char. A strict parser rejects 報告 (final).txt.

Percent-encode every character outside attr-char. Add a parser test for a Unicode name with parentheses.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Fixed in 97c3f84: encodeExtValue() percent-encodes every UTF-8 byte outside RFC 5987 attr-char (so ( ) ' * are escaped); test with 報告 (final)'.txt asserts the exact header, the attr-char grammar, and the decoded round trip.

Comment thread apps/cli/src/plugin-cli-proxy.ts Outdated
let pluginCliDispatcher: Promise<Dispatcher> | undefined;
function getPluginCliDispatcher(): Promise<Dispatcher> {
pluginCliDispatcher ??= import("undici").then(
({ Agent }) => new Agent({ headersTimeout: 0 }),

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🚨 slopcop/review — Keep a finite deadline for plugin CLI commands.

The server has an interaction deadline, but it has no general plugin-command deadline. A stalled plugin can now hold resources without a limit.

Use a finite client deadline above the interaction maximum, or add a server deadline. Test a handler that never resolves.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Fixed in 97c3f84: the dispatcher now uses a finite headersTimeout of 65 min (PLUGIN_CLI_HEADERS_TIMEOUT_MS) — above ui.requestInput's 60-minute maximum so the server's interaction deadline fires first and resolves the form cleanly, but bounded so a plugin that never resolves cannot hold the CLI process forever. Test asserts the bound; a real never-resolving handler would need a 65-minute test, so the existing scaled-down test proves the dispatcher path.

Comment thread plugins/tasks/attachments/index.ts Outdated
const asciiFallback = fileName
.replace(/[^\x20-\x7e]/g, "-")
.replace(/["\\]/g, "_");
const encodedName = encodeURIComponent(fileName).replaceAll("'", "%27");

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🚨 slopcop/review — Remove Unicode bidirectional controls from stored file names.

This fix now sends these controls through filename*. A malicious name can show a false file extension after download.

Remove bidi controls during file-name sanitation. Add a test with a bidirectional-control file name.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Fixed in 97c3f84: bidi controls (U+061C, U+200E/F, U+202A–U+202E, U+2066–U+2069) become _ in sanitizeFileName (stored name) and again in the Content-Disposition builder for pre-existing rows; test uploads photo<RLO>gnp.exe and asserts stored name and both header parameters.

@bb-slop-cop bb-slop-cop Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🚨 SLOP COP 🚨 · review

Plain-English summary: This pull request keeps international attachment names during downloads. It also lets plugin commands wait longer for human input.

I found three issues that need fixes.

  • The new filename* value does not encode parentheses. A strict RFC parser rejects 報告 (final).txt. Some clients can lose the correct Unicode name.
  • Unicode bidirectional controls remain in downloaded names. An unsafe name can show a false file extension.
  • The CLI disables the header timeout for every plugin command. The server has no general plugin-command deadline, so one command can wait forever.

The new Undici dependency adds about 725 KB uncompressed, or 157 KB compressed, to the CLI bundle. I treat this as a tradeoff, not a defect.

I found no duplicate Content-Disposition formatter. The project-attachment sanitizer has a different storage purpose. A response-header or heartbeat design could remove the timeout problem later.

Both package type checks passed. The focused CLI suite passed 26 tests. The focused attachment suite passed 11 tests.

I also used the live development server and a browser. The browser downloaded all 4,762 bytes with status 200. The returned header reproduced the parentheses defect.

I left this as a comment-only review. I did not approve the pull request or request changes.

SawyerHood and others added 2 commits August 18, 2026 19:29
The tasks plugin download route put the raw attachment file name into the
legacy `filename=` parameter of Content-Disposition. Header values must be
ByteStrings, so an em dash (or any non-Latin-1 character) made the Response
constructor throw and every download of that attachment returned 500 with
the "Cannot convert argument to a ByteString" log line. Follow RFC 6266:
ASCII fallback in `filename=`, percent-encoded UTF-8 in `filename*`.

The CLI proxied plugin commands with a bare fetch(). `bb secret request`
holds POST /api/v1/plugins/secrets/cli open while a human fills the form,
so Node's default undici headersTimeout (300 s) rejected the call with a
bare "fetch failed" and the server aborted the interaction. Dispatch plugin
commands through an undici Agent with no headers timeout; the server's
interaction timeout bounds the wait.

Fixes #1621

Co-Authored-By: Claude <[email protected]>
- Percent-encode every byte outside RFC 5987 attr-char in filename*
  (encodeURIComponent kept ( ) ' *).
- Replace Unicode bidirectional controls with `_` in stored attachment
  names and in Content-Disposition, so a name cannot spoof its extension.
- Keep a finite plugin CLI headers timeout (65 min): above the 60-minute
  ui.requestInput maximum so the server deadline decides first, but bounded
  because the server has no general plugin-command deadline.

Co-Authored-By: Claude <[email protected]>
@SawyerHood
SawyerHood force-pushed the bb/draft-pr-for-1621-non-latin-1-chars-em-dash-in-i-thr_8aaxd9sz46 branch from d6164be to 97c3f84 Compare August 18, 2026 19:31
@SawyerHood
SawyerHood merged commit 09f1f51 into main Aug 18, 2026
10 checks passed
@SawyerHood
SawyerHood deleted the bb/draft-pr-for-1621-non-latin-1-chars-em-dash-in-i-thr_8aaxd9sz46 branch August 18, 2026 21:08
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

1 participant