Sanitize buffered upload filenames - #6753
Conversation
Greptile SummaryThis PR aligns filename handling for buffered and streamed uploads. The main changes are:
Confidence Score: 5/5This looks safe to merge.
|
| Filename | Overview |
|---|---|
| packages/reflex-components-core/src/reflex_components_core/core/_upload.py | Adds the shared filename sanitizer and applies it to buffered and streamed uploads. |
| tests/units/components/core/test_upload.py | Adds coverage for path sanitization and preserved relative directories in both upload modes. |
| packages/reflex-components-core/news/6753.bugfix.md | Documents the aligned filename sanitization behavior. |
Reviews (4): Last reviewed commit: "Merge branch 'main' into fix/upload-file..." | Re-trigger Greptile
Merging this PR will degrade performance by 3.96%
|
| Mode | Benchmark | BASE |
HEAD |
Efficiency | |
|---|---|---|---|---|---|
| ❌ | Simulation | test_var_access[non_mutable_scalar] |
57.5 ms | 59.9 ms | -3.96% |
Tip
Investigate this regression by commenting @codspeedbot fix this regression on this PR, or directly use the CodSpeed MCP with your agent.
Comparing harsh21234i:fix/upload-filename-basename-buffered (cd91912) with main (346177c)2
Footnotes
-
8 benchmarks were skipped, so the baseline results were used instead. If they were deleted from the codebase, click here and archive them to remove them from the performance reports. ↩
-
No successful run was found on
main(d8a132b) during the generation of this report, so 346177c was used instead as the comparison base. There might be some changes unrelated to this pull request in this report. ↩
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.
|
Good catch. I adjusted the sanitizer so directory uploads keep safe relative paths instead of flattening everything to Current behavior:
I added coverage for both buffered uploads and streamed upload chunks to make sure safe directory paths are retained |
|
hey @masenf can you go through this? |
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