T09 · Insecure Skill Coding Practices
- Location
src/skill.py:43- Finding
Unrestricted File Access and Path Traversal in Network Operations
- Content
View full analysis
Optional[PipeNet]: try: if sys.version_info >= (3, 11): with open(toml_file_path, "rb") as f: data = tomllib.load(f) ``` ### Technical Analysis The public tool interface accepts a caller-controlled `file_path` and uses it directly with `open()` without canonicalization, an approved-root check, or an allowlist. Consequently, the Skill can attempt to read any filesystem path accessible to its operating-system account. The `network.name` value is loaded from attacker-controlled TOML and is subsequently interpolated into output paths. The optional `scenario_name` parameter is likewise interpolated into an HTML output path. Neither value is checked for path separators, `..` components, absolute-path syntax, control characters, or symbolic-link traversal. Although fixed `.toml` and `.html` suffixes limit the names of files that can be written, traversal components can still escape the intended `src/toml` and `src/html` directories. Existing files with compatible suffixes can potentially be overwritten. Symbolic links inside writable output directories may further expand the reachable write scope. Accepting uploaded network files is necessary for the declared functionality, ...[truncated 2179 chars]- Remediation
View remediation
Path: if not user_name or any(c not in "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789_-" for c in user_name): raise ValueError("Invalid network name") destination = (INPUT_ROOT / f"{user_name}{suffix}").resolve() if not destination.is_relative_to(INPUT_ROOT): raise ValueError("Path escapes the approved directory") return destination ``` 2. Replace caller-supplied host paths with upload identifiers or server-generated file IDs. Resolve those identifiers through a trusted registry. 3. If path input is unavoidable: - Require the `.toml` extension. - Reject absolute paths, `..`, path separators, NUL bytes, and control characters. - Resolve symbolic links and verify containment after resolution. - Require regular files and reject devices, FIFOs, sockets, and symbolic links. 4. Apply the same validation to `network.name` and `scenario_name`. Prefer server-generated output filenames rather than deriving them from TOML fields. 5. Create output files with exclusive creation where overwriting is unnecessary. Use restrictive permissions and a dedicated, non-executable output directory. 6. Run the Skill under a restricted operating-system account with access only to its upload and output directories. 7. Return generic errors to untrusted callers. Avoid exposing absolute paths, parser details, or unrelated local-file metadata. ]]>
