Sanitize buffered upload filenames#6753
Conversation
Greptile SummaryThis PR makes buffered and streamed uploads use the same filename sanitization. The main changes are:
Confidence Score: 5/5This looks safe to merge.
Important Files Changed
Reviews (2): Last reviewed commit: "Add upload filename changelog fragment" | Re-trigger Greptile |
Merging this PR will not alter performance
Comparing Footnotes
|
masenf
left a comment
There was a problem hiding this comment.
it seems like this breaks directory upload.
if you make an upload component, then drag a whole directory onto it and upload it, i would expect the path segments to be retained.
Description
close #6752
Buffered uploads previously preserved client-supplied path segments in
UploadFile.path, while streamed uploadsnormalized filenames to a basename.
This made
rx.upload_filesandrx.upload_files_chunkexpose different filename/path behavior for the same multipartfilename, for example
../secret.txt.This PR adds one shared filename sanitizer and uses it for both upload paths.
Changes
_sanitize_upload_filenameto strip path segments from upload filenames._upload_file_from_starletteso buffered upload file construction is directly testable.Checks
uv run pytest tests/units/components/core/test_upload.py -quv run ruff check packages/reflex-components-core/src/reflex_components_core/core/_upload.py tests/units/ components/core/test_upload.pyuv run ruff format --check packages/reflex-components-core/src/reflex_components_core/core/_upload.py tests/units/ components/core/test_upload.pyuv run pyright packages/reflex-components-core/src/reflex_components_core/core/_upload.py tests/units/components/ core/test_upload.py