T09 · Insecure Skill Coding Practices
- Location
scripts/indexer.py:123- Finding
Scan Root Escape Through Symbolic Links
- Content
View full analysis
Vulnerability Details
File Location:
scripts/indexer.py, lines 31–32, 87–93, and 123–124
Vulnerability Type: Improper symbolic-link handling leading to out-of-scope local file disclosure
Risk Level: MediumVulnerable Code
python with open(filepath, 'r', encoding='utf-8', errors='replace') as f: tree = ast.parse(f.read(), filename=str(filepath))python elif isinstance(node, ast.Assign): for target in node.targets: if isinstance(target, ast.Name): # Module-level variable if isinstance(target.ctx, ast.Store): symbols.append({ 'name': target.id, 'type': 'variable', 'file': rel_path, 'line': node.lineno, 'value': ast.dump(node.value)[:80], })python for filepath in root.rglob('*'): if not filepath.is_file(): continueTechnical Analysis
The scanner resolves the supplied project root, but it neither rejects symbolic-link files nor resolves and validates each discovered file against that root.
Path.is_file()follows symbolic links, and the subsequentopen()operation reads the symlink target.Consequently, an untrusted project can contain a
.pysymbolic link whose target is a readable Python file outside the requested scan directory. The scanner will parse that external file as though it belonged to the project. The generated index may include symbol names, imports, docstrings, and truncated AST representations of assignment values. Literal values embedded in external Python configuration files may therefore be copied into the JSON index.Attack Path
- An attacker prepares a project directory containing a
.pysymbolic link. - The symbolic link points to a readable Python source or configuration file outside the project root.
- A user invokes the
scanc ...[truncated 1200 chars]
- An attacker prepares a project directory containing a
- Remediation
View remediation
Remediation Suggestions
-
Reject symbolic links before reading files:
python if filepath.is_symlink() or not filepath.is_file(): continue -
Apply defense in depth by resolving every candidate and ensuring it remains under the resolved project root:
python try: resolved_file = filepath.resolve(strict=True) resolved_file.relative_to(root) except (OSError, ValueError): continue if not resolved_file.is_file(): continue -
Open the validated resolved path rather than the original path.
-
Where supported, use no-follow file-opening semantics to reduce time-of-check/time-of-use symlink races.
-
Catch file-resolution and permission errors without exposing sensitive absolute paths unnecessarily.
-
Avoid indexing assignment values by default. If they are required, redact string, byte, and numeric constants or provide an explicit opt-in option.
-
Add tests covering direct file symlinks, nested symlink paths, broken links, links escaping the root, and links remaining inside the root.
-
