T09 · Insecure Skill Coding Practices
- Location
scripts/install.sh:89- Finding
Unconditional Overwrite of Persistent Agent Configuration and Memory
- Content
View full analysis
"$TARGET_DIR/IDENTITY.md" << 'EOF' ``` ```bash cat > "$TARGET_DIR/SOUL.md" << 'EOF' ``` ```bash cat > "$TARGET_DIR/TOOLS.md" << 'EOF' ``` ```bash cat > "$TARGET_DIR/MEMORY.md" << 'EOF' ``` Each command uses the shell `>` redirection operator, which truncates an existing destination file before writing the bundled replacement content. ### Technical Analysis The installer accepts an existing Agent workspace through `--dir` or resolves one through `--agent`. It then replaces four persistent control and state files without: - Checking whether the files already exist. - Obtaining confirmation before destructive modification. - Creating recoverable backups. - Requiring an explicit overwrite option. - Validating whether the destination is an appropriate disposable workspace. - Merging settings while preserving existing security rules. `IDENTITY.md` and `SOUL.md` can govern the Agent's identity, response behavior, and safety boundaries. `TOOLS.md` can affect its understanding of available tools and expected tool use. `MEMORY.md` represents persistent state that may affect future sessions. The skill openly intends to transform the Agent's persona, so the replacement content is not a hidden malicious payload. Nevertheless, silently truncating existing control and memory files is an unsafe installation practice. A user who points the installer at a populated workspace may irreversibly lose unrelated configuration, safety guidance, and accumulated memory. ### Attack Path 1. A user has an existing Agent workspace containing customized identity, safety, tool, and memory files. 2. The user runs: ```bash ./skills/zen-master/scripts/install.sh --dir /path/to/existing-agent-workspace ``` 3. The installer verifies only that the destinat ...[truncated 1378 chars]- Remediation
View remediation
&2 exit 1 fi ``` 2. Require an explicit `--force` or `--replace-config` option for destructive replacement. 3. Create timestamped backups before modifying any existing file: ```bash backup_dir="$TARGET_DIR/.zen-master-backup-$(date +%Y%m%d-%H%M%S)" mkdir -p "$backup_dir" cp -p "$TARGET_DIR/IDENTITY.md" "$backup_dir/" 2>/dev/null || true ``` 4. Display every affected path and request interactive confirmation unless a clearly documented noninteractive flag is supplied. 5. Prefer namespaced files, such as `skills/zen-master/IDENTITY.md`, rather than replacing workspace-level control files. 6. Where supported by the Agent platform, merge only explicitly approved configuration sections instead of replacing entire files. 7. Use atomic writes: - Write generated content to a temporary file inside the destination filesystem. - Validate the generated file. - Preserve ownership and permissions where appropriate. - Rename the temporary file into place only after successful validation. 8. Add an uninstall or rollback command that restores backups and removes only files created by this skill. ]]>
