Loading
Fix traversal checks that crash instead of rejecting
What does this MR do and why?
Helpers.validate_traversal raises ValueError on a bad path and never returns a falsy
value. Several callers used it as if not validate_traversal(...), so their
rejection branches never ran. A bad path then returned a generic 500 instead of a clean
rejection.
This does not fix any security issues, just how the app responds when it detects traversal.
- Add
Helpers.is_path_within(), a boolean wrapper, and use it inreject_traversaland the import checks inmain_controller.py. - Route the file API and login photo checks through
reject_traversal, which removes the duplicated error blocks. - Make
reject_traversalsend 403 instead of 400 - Validate every path before acting in multi-item delete, copy, and move. Before, a bad path in a later item failed the request after earlier items were already deleted or moved.
Screenshots or screen recordings
N/A
How to set up and validate locally
- Create
keep.txtand adestdirectory in a server's root directory. - Send a delete with one good path and one bad path:
curl -k -X DELETE -H "Authorization: Bearer $TOKEN" https://localhost:8443/api/v2/servers/$SERVER/files -d '{"file_system_objects":[{"filename":"keep.txt"},{"filename":"../outside.txt"}]}' - Confirm the response is 403
TRAVERSAL DETECTEDandkeep.txtstill exists. Ondev, the response is a 500 andkeep.txtis deleted. - Send a move with one good target and one bad target:
curl -k -X POST -H "Authorization: Bearer $TOKEN" https://localhost:8443/api/v2/servers/$SERVER/files/move -d '{"file_system_objects":[{"source_path":"keep.txt","target_path":"dest"},{"source_path":"keep.txt","target_path":"../x"}]}' - Confirm the response is 403 and
keep.txtis still in the root, not indest. - Delete, move, and download a valid file in the panel file manager. All three work as before.
MR acceptance checklist
This checklist encourages us to confirm any changes have been analyzed to reduce risks in quality, performance, reliability, security, and maintainability.
- Have you checked this doesn't interfere/conflict/duplicate someone elses work?
- Have you fully tested your changes?
- Have you resolved any lint issues?
- Have you assigned a reviewer?
- Have you applied correct labels?
Edited by Iain Powrie