T05 · Unauthorized Access and Privilege Escalation
- Location
gitguard_skill/entropy.py:200- Finding
Repository Boundary Bypass Through Symbolic Links
- Content
View full analysis
Vulnerability Details
File Location:
gitguard_skill/entropy.py, lines 200-211
Vulnerability Type: Unrestricted symbolic-link traversal during secret scanning
Risk Level: MediumVulnerable Code
python for p in root.rglob("*"): if scanned >= max_files: break if not p.is_file(): continue if any(part in SKIP_DIR_NAMES for part in p.parts): continue if p.suffix.lower() not in SCANNABLE_EXTENSIONS and p.name != ".env": continue scanned += 1 findings.extend(scan_file(p, entropy_threshold)) return findingsThe called function reads the selected path without first rejecting symbolic links or validating the resolved target:
python def scan_file(path: Path, entropy_threshold: float = 4.0) -> list[SecretFinding]: findings: list[SecretFinding] = [] try: text = path.read_text(errors="ignore") except (UnicodeDecodeError, OSError): return findingsTechnical Analysis
Path.is_file()follows symbolic links. Likewise,Path.read_text()reads the target of a symbolic link. The scanner recursively discovers entries beneath the supplied repository path but does not:- Reject symbolic links.
- Resolve each candidate path before reading it.
- Verify that the resolved path remains inside the resolved repository root.
Consequently, a repository can contain a symlink with a supported extension, or named
.env, whose target is a file outside the repository. The scanner will treat that entry as an ordinary file and read its external target.Although detected values are masked before being returned, a finding still contains the target path, line number, credential classification, entropy, severity, confidence, and the first and last four characters of sufficiently long matched content. This violates the documented repository boundary and can expose sensitive metadata and partial credential material.
Attack Path
- An attacker prepares an untrusted repo ...[truncated 1657 chars]
- Remediation
View remediation
Remediation Suggestions
- Reject symbolic-link candidates before calling
is_file()or reading content:
python if p.is_symlink(): continue- Resolve the repository root once and enforce containment for every candidate:
python root = Path(repo_path).resolve() for p in root.rglob("*"): if p.is_symlink(): continue try: resolved = p.resolve(strict=True) resolved.relative_to(root) except (OSError, RuntimeError, ValueError): continue if not resolved.is_file(): continue-
Open only the validated resolved path and ensure no later operation reuses the unvalidated path.
-
Return repository-relative file names rather than absolute paths:
python display_path = str(resolved.relative_to(root))-
Where supported, use no-follow file-opening semantics and verify the opened file descriptor to reduce time-of-check/time-of-use race conditions.
-
Add regression tests covering:
- A symlink to an external
.envfile. - A symlink to an external file with a supported extension.
- Broken and cyclic symbolic links.
- Normal files inside the repository.
- Paths containing nested symlinks.
- A symlink to an external
-
Apply the same canonical-path containment policy to all public methods accepting repository paths, particularly if they are exposed through an MCP or other remotely callable service.
- Reject symbolic-link candidates before calling
