Repository navigation
fix(security): normalize path casing for Windows write-safety checks #11148
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -42,8 +42,14 @@ | |
|
|
||
| _HOME = str(Path.home()) | ||
|
|
||
|
|
||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Current main moved the live predicate to |
||
| def _normalize_write_path(path: str) -> str: | ||
| """Normalize a path for deny-list and safe-root comparisons.""" | ||
| return os.path.normcase(os.path.realpath(os.path.expanduser(str(path)))) | ||
|
|
||
|
|
||
| WRITE_DENIED_PATHS = { | ||
| os.path.realpath(p) for p in [ | ||
| _normalize_write_path(p) for p in [ | ||
| os.path.join(_HOME, ".ssh", "authorized_keys"), | ||
| os.path.join(_HOME, ".ssh", "id_rsa"), | ||
| os.path.join(_HOME, ".ssh", "id_ed25519"), | ||
|
|
@@ -65,7 +71,7 @@ | |
| } | ||
|
|
||
| WRITE_DENIED_PREFIXES = [ | ||
| os.path.realpath(p) + os.sep for p in [ | ||
| _normalize_write_path(p) + os.sep for p in [ | ||
| os.path.join(_HOME, ".ssh"), | ||
| os.path.join(_HOME, ".aws"), | ||
| os.path.join(_HOME, ".gnupg"), | ||
|
|
@@ -91,14 +97,14 @@ def _get_safe_write_root() -> Optional[str]: | |
| if not root: | ||
| return None | ||
| try: | ||
| return os.path.realpath(os.path.expanduser(root)) | ||
| return _normalize_write_path(root) | ||
| except Exception: | ||
| return None | ||
|
|
||
|
|
||
| def _is_write_denied(path: str) -> bool: | ||
| """Return True if path is on the write deny list.""" | ||
| resolved = os.path.realpath(os.path.expanduser(str(path))) | ||
| resolved = _normalize_write_path(path) | ||
|
|
||
| # 1) Static deny list | ||
| if resolved in WRITE_DENIED_PATHS: | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
On current main this fixture reloads only the compatibility wrapper, while enforcement is in the already-imported
agent.file_safetymodule. Port these regressions to exerciseagent.file_safety.is_write_denied()so they prove the salvaged implementation.