T09 · Insecure Skill Coding Practices
- Location
SKILL.md:142- Finding
Unconditional Header Prepending Can Break Executable Scripts
- Content
View full analysis
Vulnerability Details
File Location:
SKILL.md:142-147
Vulnerability Type: Unsafe source-file mutation
Risk Level: MediumVulnerable 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 DBThe same vulnerable instructions are duplicated at
ghost-catalog/SKILL.md:142-147. The generated header for Python and shell files is defined inghost-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 python3or#!/bin/shmust 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 anExec 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
View remediation
Remediation Suggestions
- 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.
- 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.
- Replace the unconditional “prepend” instruction with a safe insertion algorithm that parses the file type and determines the first valid metadata location.
- Preserve file encoding, line endings, executable permissions, and final-newline state during writes.
- Generate and display an exact diff before mutation. Require confirmation for batch operations and for executable files.
- Create a recoverable backup or patch so failed tagging operations can be rolled back.
- 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.
- Apply the same correction to both duplicated definitions:
SKILL.mdandghost-catalog/SKILL.md.
