T05 · Unauthorized Access and Privilege Escalation
- Location
scripts/generate_code_doc.py:98- Finding
Source tree scanners follow symbolic links outside the authorized project directory
- Content
View full analysis
- Remediation
View remediation
bool: candidate = os.path.realpath(path) try: return os.path.commonpath([source_root, candidate]) == source_root except ValueError: return False ``` 3. Perform containment validation before traversing a directory or opening a file. Do not use string `startswith()` as a path-boundary check. 4. Call `entry.is_dir(follow_symlinks=False)` and `entry.is_file(follow_symlinks=False)` where appropriate. 5. Track visited directories using canonical paths or `(st_dev, st_ino)` pairs to prevent cycles and duplicate traversal. 6. Add configurable limits for recursion depth, file count, individual file size, and total bytes read to reduce denial-of-service exposure. 7. Apply the same hardened traversal helper consistently in `find_code_files()`, `count_source_lines()`, and `detect_languages()`. 8. Add tests covering directory symlinks, file symlinks, symlink cycles, path-prefix collisions, and links targeting locations outside `source_dir`. ]]>
