T09 · Insecure Skill Coding Practices
- Location
scripts/bootstrap.sh:7- Finding
Persistent Emacs Lisp Code Execution Through Working-Directory Path Injection
- Content
View full analysis
Vulnerability Details
File Location:
scripts/bootstrap.sh, lines 7–14
Vulnerability Type: Relative-path configuration injection with persistent code execution
Risk Level: Highbash 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; thenThe daemon is subsequently started at lines 15–17:
bash if ! pgrep -f "emacs --daemon" > /dev/null; then emacs --daemon fiTechnical Analysis
The source path
assets/agent-init.elis resolved relative to the caller's current working directory rather than relative to the location ofbootstrap.sh. The audited project does not contain the referencedassets/agent-init.elfile.Consequently, when the user does not already have
~/.emacs.d/init.el, executing the bootstrap script from an attacker-controlled directory containingassets/agent-init.elcauses 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 pipefailand 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.eland 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
- The victim has Emacs installed and does not already have
~/.emacs.d/init.el. - An attacker controls, or can write to, the victim's current working directory.
- The attacker creates an
assetssubdirectory and places malic ...[truncated 1554 chars]
- The victim has Emacs installed and does not already have
- Remediation
View remediation
Remediation Suggestions
- Include the intended
agent-init.elin the Skill package and resolve it relative to the script's own directory, never the caller's current working directory. - Enable strict shell error handling with
set -euo pipefail. - Verify that the source is a regular file owned by an expected principal and is not a symbolic link.
- Validate the configuration against a trusted checksum or package manifest before installation.
- Require explicit user confirmation before installing persistent executable configuration under the user's home directory.
- Install with restrictive permissions and use an atomic copy operation.
- Abort before starting Emacs if any validation or installation step fails.
- Prefer a dedicated, explicitly selected initialization file or isolated daemon configuration rather than modifying the user's general
~/.emacs.d/init.el. - 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" fiThe script should then start the daemon only after all required configuration checks complete successfully.
- Include the intended
