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
3 changes: 3 additions & 0 deletions repoReleaseAudit/repo_release_audit.py
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,9 @@ def audit(root: Path, max_file_mb: float = 50.0, strict: bool = False) -> dict[s
github_limit = 100 * 1024 * 1024
total_bytes = 0
for relative, path in files:
if any(parent.is_symlink() for parent in path.parents if parent != root and root in parent.parents):
findings.append(Finding("error", "symlink-ancestor", relative))
continue
try:
metadata = path.lstat()
is_symlink = modes.get(relative) == "120000" or stat.S_ISLNK(metadata.st_mode)
Expand Down
38 changes: 38 additions & 0 deletions repoReleaseAudit/tests/test_repo_release_audit.py
Original file line number Diff line number Diff line change
Expand Up @@ -235,3 +235,41 @@ def test_unstaged_symlink_does_not_read_outside_target(tmp_path: Path) -> None:
result = audit_module.audit(root)
assert any(item["code"] == "symlink" and item["path"] == "settings.txt" for item in result["findings"])
assert not any(item["code"] == "secret-pattern" and item["path"] == "settings.txt" for item in result["findings"])


def test_symlinked_ancestor_is_not_scanned(tmp_path: Path, monkeypatch) -> None:
root = tmp_path / "repo"
init_repo(root)
directory = root / "nested"
directory.mkdir()
target = directory / "tracked.txt"
target.write_text("ghp_" + "b" * 24, encoding="utf-8")
git(root, "add", "nested/tracked.txt")
original = Path.is_symlink
monkeypatch.setattr(Path, "is_symlink", lambda path: path == directory or original(path))
result = audit_module.audit(root)
assert any(item["code"] == "symlink-ancestor" and item["path"] == "nested/tracked.txt" for item in result["findings"])
assert not any(item["code"] == "secret-pattern" and item["path"] == "nested/tracked.txt" for item in result["findings"])


def test_real_ancestor_symlink_is_not_followed(tmp_path: Path) -> None:
root = tmp_path / "repo"
init_repo(root)
directory = root / "nested"
directory.mkdir()
target = directory / "tracked.txt"
target.write_text("safe", encoding="utf-8")
git(root, "add", "nested/tracked.txt")
target.unlink()
directory.rmdir()
outside = tmp_path / "outside"
outside.mkdir()
(outside / "tracked.txt").write_text("ghp_" + "c" * 24, encoding="utf-8")
try:
directory.symlink_to(outside, target_is_directory=True)
except OSError as error:
import pytest
pytest.skip(f"symlinks unavailable: {error}")
result = audit_module.audit(root)
assert any(item["code"] == "symlink-ancestor" and item["path"] == "nested/tracked.txt" for item in result["findings"])
assert not any(item["code"] == "secret-pattern" and item["path"] == "nested/tracked.txt" for item in result["findings"])
Loading