Repository navigation
Fix non-Latin-1 attachment names and plugin CLI headers timeout - #1809
SawyerHood merged 2 commits into
Conversation
|
🚨 SLOP COP 🚨 · I am the SlopCop. I am reviewing this pull request for security, code quality, performance, architecture, and end-to-end behavior. |
| const asciiFallback = fileName | ||
| .replace(/[^\x20-\x7e]/g, "-") | ||
| .replace(/["\\]/g, "_"); | ||
| const encodedName = encodeURIComponent(fileName).replaceAll("'", "%27"); |
There was a problem hiding this comment.
🚨 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.
There was a problem hiding this comment.
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.
| let pluginCliDispatcher: Promise<Dispatcher> | undefined; | ||
| function getPluginCliDispatcher(): Promise<Dispatcher> { | ||
| pluginCliDispatcher ??= import("undici").then( | ||
| ({ Agent }) => new Agent({ headersTimeout: 0 }), |
There was a problem hiding this comment.
🚨 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.
There was a problem hiding this comment.
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.
| const asciiFallback = fileName | ||
| .replace(/[^\x20-\x7e]/g, "-") | ||
| .replace(/["\\]/g, "_"); | ||
| const encodedName = encodeURIComponent(fileName).replaceAll("'", "%27"); |
There was a problem hiding this comment.
🚨 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.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
🚨 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.
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]>
d6164be to
97c3f84
Compare
What was wrong
Two separate defects produced the symptoms in #1621 (see the investigation report). The
TypeError: Cannot convert argument to a ByteString … 8212log lines came from the bundled tasks plugin:GET /api/v1/plugins/tasks/http/attachments/downloadwrote the raw attachment file name into the legacyfilename=parameter ofContent-Disposition.sanitizeFileNamekeeps non-Latin-1 characters, so an em dash (or CJK, emoji, curly quotes) made theResponseconstructor throw and every download or inline preview of that attachment returned 500. Thebb secret request … fetch failedsymptom had a different cause: the CLI proxies plugin commands with one barefetch()toPOST /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 undiciheadersTimeout(300 s); the fetch rejects withfetch 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: newbuildContentDisposition()follows RFC 6266.filename=carries an ASCII fallback (fileName.replace(/[^\x20-\x7e]/g, "-").replace(/["\\]/g, "_")); the real name travels percent-encoded infilename*=UTF-8''…. Stored file names do not change.apps/cli/src/plugin-cli-proxy.ts:runPluginCliCommanddispatches through a lazily created undiciAgent({ headersTimeout: 0 }). The server's interaction timeout (10 min default, 1 h max) and a closed socket still bound the wait.undiciis imported lazily so built-inbbcommands do not pay its startup cost (measured: no change tobb --versiontime; bundle grows ~1 MB).apps/cli/src/client.ts:cliFetchaccepts the Nodedispatcherfetch extension (CliRequestInit).apps/cli/package.json/pnpm-lock.yaml: addundici@^7.28.0(already in the lockfile as a transitive dependency).Tests
plugins/tasks/attachments/attachments.test.ts: "downloads a non-Latin-1 file name with an ASCII fallback in filename= (issue Non-Latin-1 text: (a) tasks attachment download puts the raw file name in a response header (HTTP 500 + ByteString TypeError); (b) bb secrets CLI bare fetch() hits undici's 300s headersTimeout while the human fills the form #1621)" — adapted from the report's repro. Before:expected 500 to be 200. After: passes.apps/cli/src/__tests__/plugin-cli-proxy.test.ts: "outlives the global fetch headers timeout while a plugin command waits on a human" — realnode:httpserver that answers after 1.5 s; the global dispatcher is set toheadersTimeout: 200to scale the 300 s ceiling down. Barefetchrejects withUND_ERR_HEADERS_TIMEOUT(sanity),runPluginCliCommandmust still return exit 0. Before:TypeError: fetch failed / HeadersTimeoutError. After: passes.Verification
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 (undiciAgentdispatcher). 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 noHOST_DAEMON_PROTOCOL_VERSIONbump.Fixes #1621
Report: https://get-bb.github.io/reports/issues/1621.html