Skip to content
Open
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
12 changes: 5 additions & 7 deletions tools/sandbox-lint/src/sandbox_lint/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -121,15 +121,13 @@


def _normalise(path: str) -> str:
"""Strip a single trailing slash so '~/.aws' and '~/.aws/' compare equal.
"""Strip all trailing slashes so '~/.aws' and '~/.aws//' compare equal.

The sandbox treats both forms as the same directory; the validator
must too, otherwise the forbidden-list could be bypassed by a
trailing-slash variant.
The sandbox treats every trailing-slash count as the same directory;
the validator must too, otherwise the forbidden-list could be bypassed
by a multi-slash variant.
"""
if path.endswith("/") and len(path) > 1:
return path[:-1]
return path
return path.rstrip("/") or "/"


def _normalised_set(paths: list[str]) -> set[str]:
Expand Down
2 changes: 2 additions & 0 deletions tools/sandbox-lint/tests/test_validator.py
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,7 @@ def test_invariant_missing_deny_read_root(baseline: dict[str, Any]) -> None:
"~/.config/gcloud",
"/",
"~/",
"~/.ssh//",
],
)
def test_invariant_allow_read_rejects_credential_paths(baseline: dict[str, Any], forbidden: str) -> None:
Expand All @@ -181,6 +182,7 @@ def test_invariant_allow_read_rejects_credential_paths(baseline: dict[str, Any],
"~/.gnupg",
"~/.ssh",
"~/.aws/",
"~/.aws//",
],
)
def test_invariant_allow_write_rejects_credential_paths(baseline: dict[str, Any], forbidden: str) -> None:
Expand Down