T09 · Insecure Skill Coding Practices
- Location
scripts/capture_baseline.py:193- Finding
Path Traversal Permits File Deletion Outside the Baseline Directory
- Content
View full analysis
- Remediation
View remediation
str: if not isinstance(name, str) or not SAFE_TEST_NAME.fullmatch(name): raise ValueError( "Test names may contain only letters, digits, underscores, and hyphens." ) return name ``` 2. Resolve the baseline directory and candidate path, then verify containment: ```python def baseline_path(baseline_dir: Path, name: str) -> Path: validate_test_name(name) root = baseline_dir.resolve() candidate = (root / f"{name}.json").resolve() if candidate.parent != root: raise ValueError("Baseline path escapes the baseline directory.") return candidate ``` 3. Use this centralized helper for all baseline reads, writes, and deletions. 4. Reject duplicate test names during suite validation to prevent ambiguous baseline operations. 5. Run the monitor under a dedicated, unprivileged account with write access only to its own report and baseline directories. 6. Add tests covering names containing `../`, absolute paths, path separators, empty strings, Unicode separator-like characters, and valid identifiers. ]]>
