Skip to content

Use validate_relative_path (not assert) for new-file path confinement in create_text_file#1589

Open
alex-schose wants to merge 1 commit into
oraios:mainfrom
alex-schose:fix/create-text-file-path-confinement
Open

Use validate_relative_path (not assert) for new-file path confinement in create_text_file#1589
alex-schose wants to merge 1 commit into
oraios:mainfrom
alex-schose:fix/create-text-file-path-confinement

Conversation

@alex-schose

Copy link
Copy Markdown

CreateTextFileTool.apply guards the new-file branch with
assert abs_path.is_relative_to(project_root), while the overwrite branch uses the
always-on validate_relative_path. Python strips assert statements under -O /
PYTHONOPTIMIZE, so when the server runs optimized, the new-file branch performs no
path-containment check and a create_text_file call with a ../ relative path can
write outside the project root (Path.resolve() collapses the ..).

This change makes the new-file branch use the same always-on guard as the overwrite
branch — consistent behavior, not dependent on assertions being enabled. It also keeps
the new-file path consistent with Serena's documented symlink stance
(validate_relative_pathis_path_in_project is lexical), unlike the prior
.resolve()-based check.

Low severity (requires running under -O); filed as a defense-in-depth hardening fix.

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant