T09 · Insecure Skill Coding Practices
Warning
- Location
- SKILL.md:142
- Finding
- Unconditional Header Prepending Can Break Executable Scripts## Vulnerability Details **File Location**: `SKILL.md:142-147` **Vulnerability Type**: Unsafe source-file mutation **Risk Level**: Medium ### Vulnerable Code ```text Apply a Ghost Catalog header to one or more files: 1. Read the file content 2. Determine the category from file extension and location 3. Query the catalog DB for the next available sequence number in that category 4. Generate the header with appropriate comment syntax 5. Prepend the header to the file (preserve existing content) 6. Insert into the catalog DB ``` The same vulnerable instructions are duplicated at `ghost-catalog/SKILL.md:142-147`. The generated header for Python and shell files is defined in `ghost-catalog/header-templates.md:3-17`: ```python # ============================================================================== # file_id: SOM-XXX-NNNN-vX.X.X # name: filename.py # description: Brief description of what this file does # project_id: PROJECT-NAME # category: script # tags: [tag1, tag2, tag3] # created: YYYY-MM-DD # modified: YYYY-MM-DD # version: X.X.X # agent_id: AGENT-DROID-001 # ============================================================================== ``` ### Technical Analysis The tagging procedure directs the agent to prepend a generated metadata block to every selected file. Python and shell scripts are explicitly supported, but the procedure does not detect or preserve shebang lines. On Unix-like systems, a shebang such as `#!/usr/bin/env python3` or `#!/bin/sh` must remain at the beginning of the file for direct execution. Prepending the catalog header moves the shebang away from byte zero and prevents the operating system from selecting the intended interpreter. This can cause an `Exec format error`, fail CI or deployment tasks, or produce interpreter-dependent fallback behavior. The procedure also lacks explicit handling for other position-sensitive content, including byte-order marks, Pyth ...[truncated 1645 chars]
- Remediation
- ## Remediation Suggestions 1. Detect a shebang before modifying Python, shell, Ruby, Perl, or other executable scripts. Preserve it as the first line and insert the metadata block immediately after it. 2. Define language-specific insertion rules for other position-sensitive content, including byte-order marks, Python encoding declarations, XML declarations, strict-mode directives, and framework pragmas. 3. Replace the unconditional “prepend” instruction with a safe insertion algorithm that parses the file type and determines the first valid metadata location. 4. Preserve file encoding, line endings, executable permissions, and final-newline state during writes. 5. Generate and display an exact diff before mutation. Require confirmation for batch operations and for executable files. 6. Create a recoverable backup or patch so failed tagging operations can be rolled back. 7. Extend post-write verification to confirm that the shebang remains at byte zero, required directives retain valid positions, permissions are unchanged, and directly executable scripts still resolve to the intended interpreter. 8. Apply the same correction to both duplicated definitions: `SKILL.md` and `ghost-catalog/SKILL.md`.
