Skip to content

fix: harden uploaded filename validation#37810

Open
xiaweiwei67-stack wants to merge 1 commit into
langgenius:mainfrom
xiaweiwei67-stack:fix/harden-upload-filename
Open

fix: harden uploaded filename validation#37810
xiaweiwei67-stack wants to merge 1 commit into
langgenius:mainfrom
xiaweiwei67-stack:fix/harden-upload-filename

Conversation

@xiaweiwei67-stack

Copy link
Copy Markdown
Contributor

Summary

FileService.upload_file only rejected the path separators / and \ in the original filename. That name is stored as display metadata (UploadFile.name) and can surface in ZIP entry names, Content-Disposition headers, and log lines.

This additionally rejects NUL bytes, control characters (CR/LF etc. - header/log injection vectors), and the bare dot-names . / ... The storage key is already UUID-based, so this is defense-in-depth, and the existing ValueError("Filename contains invalid characters") message/behavior is unchanged. Legitimate names (spaces, accented/CJK characters, .. as a substring such as v1..2.zip) are still accepted.

Adds a parametrized unit test covering the new rejections. Verified with ruff check and ruff format on the changed files.

Fixes #37809

Screenshots

N/A (backend input validation; no UI change).

Checklist

  • This change requires a documentation update, included: Dify Document
  • I understand that this PR may be closed in case there was no previous discussion or issues. (This doesn't apply to typos!)
  • I've added a test for each change that was introduced, and I tried as much as possible to make a single atomic change.
  • I've updated the documentation accordingly.
  • I ran make lint && make type-check (backend) and cd web && pnpm exec vp staged (frontend) to appease the lint gods

From Cursor

upload_file only rejected "/" and "\" in the original filename. That name is
kept as display metadata (UploadFile.name) and can surface in ZIP entry names,
Content-Disposition headers, and logs, so also reject NUL bytes, control
characters (CR/LF etc. - header/log injection vectors), and the bare dot-names
"." / "..". The storage key is already UUID-based, so this is defense-in-depth;
the existing error message/behavior is unchanged.

Adds a parametrized unit test covering the new rejections.
@dosubot dosubot Bot added the size:S This PR changes 10-29 lines, ignoring generated files. label Jun 23, 2026
@github-actions

Copy link
Copy Markdown
Contributor

Pyrefly Type Coverage

Metric Base PR Delta
Type coverage 50.90% 50.90% -0.00%
Strict coverage 50.41% 50.41% -0.00%
Typed symbols 30,162 30,162 0
Untyped symbols 29,379 29,382 +3
Modules 2927 2927 0

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

size:S This PR changes 10-29 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Uploaded filename validation only rejects path separators (allows NUL/control characters and dot-names)

1 participant