Skip to content

fix: validate custom install path in install.sh to prevent path traversal#83

Open
xiaolai wants to merge 1 commit intomuratcankoylan:mainfrom
xiaolai:fix/nlpm-sanitize-install-path
Open

fix: validate custom install path in install.sh to prevent path traversal#83
xiaolai wants to merge 1 commit intomuratcankoylan:mainfrom
xiaolai:fix/nlpm-sanitize-install-path

Conversation

@xiaolai
Copy link
Copy Markdown

@xiaolai xiaolai commented Apr 26, 2026

Automated audit: This PR was generated by NLPM, a natural language programming linter, running via claude-code-action. Please evaluate the diff on its merits.

Security Fix (Low)

In examples/digital-brain-skill/scripts/install.sh, when the user selects option 3 (custom location), the input is read via read -p and passed directly to mkdir -p and cp -r without any validation:

read -p "Enter custom path: " custom_path
TARGET_DIR="$custom_path/$SKILL_NAME"

A user or script that passes a path containing .. segments could write files outside the intended directory. A path containing shell metacharacters could cause unexpected shell behavior depending on how the variable is expanded downstream.

Fix

Added validation after the read -p call that:

  1. Rejects empty input
  2. Rejects paths containing .. (traversal sequences)
  3. Restricts characters to a safe allowlist: letters, numbers, /, _, ., -, ~, and spaces
  4. Canonicalizes the path with realpath --canonicalize-missing to resolve any remaining traversal via symlinks or relative segments
if [[ -z "$custom_path" ]] || [[ "$custom_path" == *".."* ]] || [[ "$custom_path" =~ [^a-zA-Z0-9/_.\-\ ~] ]]; then
    echo "Invalid path. Use only letters, numbers, /, _, ., -, ~, and spaces."
    exit 1
fi
custom_path="$(realpath --canonicalize-missing -- "$custom_path")"

The built-in installation paths (options 1 and 2) are not affected since they are constructed from $HOME and . respectively, which are trusted values.

The custom path entered by the user was passed directly to mkdir -p and
cp -r without sanitization. A value containing '..' could write files
outside intended directories; a value with shell metacharacters could
cause unexpected behaviour. Added rejection of '..' and metacharacters,
then canonicalization via realpath before use.

Co-Authored-By: Claude Code <noreply@anthropic.com>
@xiaolai xiaolai force-pushed the fix/nlpm-sanitize-install-path branch from c46615a to 325c5c2 Compare April 26, 2026 06:54
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants