T09 · Insecure Skill Coding Practices
- Location
gw_analyzer.py:354- Finding
Output Path Traversal Through Unsanitized Event and Detector Identifiers
- Content
View full analysis
- Remediation
View remediation
str: if not value or not SAFE_IDENTIFIER.fullmatch(value): raise ValueError(f"Invalid {field}") return value ``` 2. Reject absolute paths, path separators, `..` components, null characters, and platform-specific alternate separators. 3. Resolve and verify every destination before writing: ```python base = self.output_dir.resolve() destination = (base / filename).resolve() if destination.parent != base: raise ValueError("Output path escapes the configured output directory") ``` If subdirectories are intentionally supported, use `destination.is_relative_to(base)` on supported Python versions instead of requiring the immediate parent to equal `base`. 4. Apply validation inside the library methods, not only in the CLI, because direct Python callers bypass `argparse` choices. 5. Avoid silently overwriting existing files. Use exclusive creation where appropriate, generate collision-resistant output names, or require explicit overwrite authorization. 6. Add tests covering `../`, absolute paths, Windows separators, encoded separators, empty identifiers, and valid GWOSC event names. ]]>
