Skip to content

fix(kap-server): sanitize download filenames - #2286

Open
xianjianlf2 wants to merge 1 commit into
MoonshotAI:mainfrom
xianjianlf2:markxian/fix-kap-download-filename
Open

fix(kap-server): sanitize download filenames#2286
xianjianlf2 wants to merge 1 commit into
MoonshotAI:mainfrom
xianjianlf2:markxian/fix-kap-download-filename

Conversation

@xianjianlf2

Copy link
Copy Markdown

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 download when needed, and add a direct unit test for the filename sanitizer.

Checklist

  • I have read the CONTRIBUTING document.
  • I have linked a related issue, or explained the problem above.
  • I have added tests that prove my feature works.
  • Ran gen-changesets skill, or this PR needs no changeset.
  • Ran gen-docs skill, or this PR needs no doc update.

@changeset-bot

changeset-bot Bot commented Jul 28, 2026

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: d046f5b

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
@moonshot-ai/kimi-code Patch

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

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 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, '_');

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge 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 👍 / 👎.

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