fix(kap-server): sanitize download filenames - #2286
Conversation
🦋 Changeset detectedLatest commit: d046f5b The changes in this PR will be included in the next version bump. This PR includes changesets to release 1 package
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: d046f5b9b4
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| const segs = rel.split('/'); | ||
| const base = segs[segs.length - 1] ?? rel; | ||
| return base.replace(/"/g, '\\"'); | ||
| const sanitized = base.replace(/[\u0000-\u001f\u007f"\\]/g, '_'); |
There was a problem hiding this comment.
Normalize non-Latin-1 filenames before setting headers
When a workspace file has a name such as 报告.txt or an emoji filename, this sanitizer leaves those characters unchanged and the download handler interpolates the result into Content-Disposition. On the Node 24 server, header values containing code points outside Latin-1 throw ERR_INVALID_CHAR, so these downloads fail with a server error instead of streaming the file. Since this change is meant to make response-header filenames safe, sanitize to ASCII or use a properly encoded filename* fallback before calling reply.header.
Useful? React with 👍 / 👎.
Related Issue
No linked issue.
Problem
Session file downloads only escaped quotes in
Content-Disposition, so control characters and backslashes could still leak into the response header value.What changed
Sanitize download filenames down to safe ASCII characters, fall back to
downloadwhen needed, and add a direct unit test for the filename sanitizer.Checklist
gen-changesetsskill, or this PR needs no changeset.gen-docsskill, or this PR needs no doc update.