Conversation
Validate names on every save_file path and keep exfil directory creation contained under exfil_dir. Co-authored-by: Cursor <cursoragent@cursor.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
Hardens file writes in
FileSvcagainst path traversal and applies the check consistently across every caller.save_filenow validates the filename on every call, not just multipart uploads.Sink mode (
target_dir+ basename) runs the full_validate_filenamecheck (character whitelist,../separator/NUL rejection, base64-looking names).Path mode (
''+ relative path) validates each path component structurally, then both modes enforcerealpathcontainment under the parent directory.Agent contact handlers (DNS, FTP, Gist, Slack) validate the agent-supplied filename before saving and log/drop the upload on failure, instead of relying on
save_filealone.create_exfil_sub_directoryandcreate_exfil_operation_directorynow rejectdir_namevalues that resolve outsideexfil_dir(e.g.../or absolute paths fromX-Request-IDor agentpaw).create_exfil_operation_directoryalso raises instead of indexing an empty list when no operation matches the agent.Report and event log writers no longer route through
create_exfil_sub_directory, since they write underreports_dir, notexfil_dir; they create their directory directly.Type of change
How Has This Been Tested?
pytest tests/services/test_file_svc.py tests/security/test_filename_validation.py, including new tests:test_create_exfil_sub_directory_rejects_escape(relative../and absolutedir_name)test_create_exfil_operation_directory_rejects_escapetest_save_file_rejects_path_traversalupdated for the new validation errorChecklist