T09 · Insecure Skill Coding Practices
Error
- Location
- scripts/bootstrap.sh:7
- Finding
- Persistent Emacs Lisp Code Execution Through Working-Directory Path Injection## Vulnerability Details **File Location**: `scripts/bootstrap.sh`, lines 7–14 **Vulnerability Type**: Relative-path configuration injection with persistent code execution **Risk Level**: High ```bash EMACS_DIR="$HOME/.emacs.d" mkdir -p "$EMACS_DIR" if [ ! -f "$EMACS_DIR/init.el" ]; then cp assets/agent-init.el "$EMACS_DIR/init.el" fi # Ensure Daemon is running if ! pgrep -f "emacs --daemon" > /dev/null; then ``` The daemon is subsequently started at lines 15–17: ```bash if ! pgrep -f "emacs --daemon" > /dev/null; then emacs --daemon fi ``` ### Technical Analysis The source path `assets/agent-init.el` is resolved relative to the caller's current working directory rather than relative to the location of `bootstrap.sh`. The audited project does not contain the referenced `assets/agent-init.el` file. Consequently, when the user does not already have `~/.emacs.d/init.el`, executing the bootstrap script from an attacker-controlled directory containing `assets/agent-init.el` causes that attacker-controlled file to be copied into the user's persistent Emacs configuration. The script does not enable fail-fast handling such as `set -euo pipefail` and does not verify the source file, copied file, owner, permissions, or cryptographic integrity. It may therefore continue to daemon startup after configuration-related errors. When the new Emacs daemon starts, Emacs loads `~/.emacs.d/init.el` and evaluates its Emacs Lisp code. Although persistence is involved, the root defect is an insecure relative-path resolution flaw in the Skill's bootstrap code. There is no evidence that the repository itself contains a malicious payload or intentionally installs a backdoor. ### Attack Path 1. The victim has Emacs installed and does not already have `~/.emacs.d/init.el`. 2. An attacker controls, or can write to, the victim's current working directory. 3. The attacker creates an `assets` subdirectory and places malic ...[truncated 1554 chars]
- Remediation
- ## Remediation Suggestions 1. Include the intended `agent-init.el` in the Skill package and resolve it relative to the script's own directory, never the caller's current working directory. 2. Enable strict shell error handling with `set -euo pipefail`. 3. Verify that the source is a regular file owned by an expected principal and is not a symbolic link. 4. Validate the configuration against a trusted checksum or package manifest before installation. 5. Require explicit user confirmation before installing persistent executable configuration under the user's home directory. 6. Install with restrictive permissions and use an atomic copy operation. 7. Abort before starting Emacs if any validation or installation step fails. 8. Prefer a dedicated, explicitly selected initialization file or isolated daemon configuration rather than modifying the user's general `~/.emacs.d/init.el`. 9. Detect the intended daemon by an exact socket or daemon name rather than the broad `pgrep -f "emacs --daemon"` expression. A hardened path-resolution pattern would begin with: ```bash #!/usr/bin/env bash set -euo pipefail SCRIPT_DIR="$(cd -- "$(dirname -- "${BASH_SOURCE[0]}")" && pwd)" SOURCE_INIT="$SCRIPT_DIR/../assets/agent-init.el" TARGET_DIR="$HOME/.emacs.d" TARGET_INIT="$TARGET_DIR/init.el" [[ -f "$SOURCE_INIT" && ! -L "$SOURCE_INIT" ]] || { echo "Error: trusted agent-init.el is missing or invalid." >&2 exit 1 } mkdir -p -- "$TARGET_DIR" chmod 700 -- "$TARGET_DIR" if [[ ! -e "$TARGET_INIT" ]]; then install -m 600 -- "$SOURCE_INIT" "$TARGET_INIT" fi ``` The script should then start the daemon only after all required configuration checks complete successfully.
