Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions src/gaia/security.py
Comment thread
kovtcharov-amd marked this conversation as resolved.
Original file line number Diff line number Diff line change
Expand Up @@ -410,8 +410,11 @@ def is_write_blocked(self, path: str) -> Tuple[bool, str]:
Tuple of (is_blocked, reason). If blocked, reason explains why.
"""
try:
real_path = Path(os.path.realpath(path)).resolve()
real_path_str = str(real_path)
# Use os.path.realpath exclusively for symlink resolution — do NOT
# chain Path.resolve(), which re-resolves on Python <3.12 via a
# separate code path and can disagree with realpath.
real_path_str = os.path.realpath(path)
real_path = Path(real_path_str)
# Apply macOS /private normalization so /etc, /var/run, etc. match
# the BLOCKED_DIRECTORIES entries (they're stored unprefixed).
norm_path = os.path.normpath(_normalize_macos_symlinks(real_path_str))
Expand Down
8 changes: 3 additions & 5 deletions tests/unit/test_security_edge_cases.py
Original file line number Diff line number Diff line change
Expand Up @@ -344,12 +344,10 @@ def test_exception_during_path_resolution_returns_blocked(self, validator):
assert is_blocked is True
assert "unable to validate" in reason.lower()

def test_exception_from_path_resolve_returns_blocked(self, validator):
"""When Path.resolve() raises, is_write_blocked returns (True, reason)."""
def test_exception_from_path_construction_returns_blocked(self, validator):
"""When path construction raises, is_write_blocked returns (True, reason)."""
with patch("os.path.realpath", return_value="/tmp/test.txt"):
with patch.object(
Path, "resolve", side_effect=RuntimeError("Resolve failed")
):
with patch("os.path.normpath", side_effect=RuntimeError("Normpath failed")):
is_blocked, reason = validator.is_write_blocked("/tmp/test.txt")

assert is_blocked is True
Expand Down
Loading