T09 · Insecure Skill Coding Practices
- Location
scripts/configure.sh:30- Finding
Arbitrary Command Execution Through Unsafe Configuration Serialization
- Content
View full analysis
Vulnerability Details
File Location:
scripts/configure.sh:30-100; configuration is subsequently executed byscripts/flomo_send.sh:14-19
Vulnerability Type: Shell command injection through sourced configuration
Risk Level: HighVulnerable Code
scripts/configure.shaccepts a webhook value without validating or escaping shell metacharacters:bash read -rp "Webhook token (or full URL): " WEBHOOK_INPUT if [ -z "$WEBHOOK_INPUT" ]; then echo "⚠️ No webhook provided. You can configure it later by running this script again." exit 0 fi # Detect if user pasted full URL or just token if echo "$WEBHOOK_INPUT" | grep -q "^https://flomoapp.com/iwh/"; then # Full URL provided WEBHOOK_URL="$WEBHOOK_INPUT" WEBHOOK_TOKEN=$(echo "$WEBHOOK_URL" | sed 's|https://flomoapp.com/iwh/||') else # Just token provided WEBHOOK_TOKEN="$WEBHOOK_INPUT" WEBHOOK_URL="https://flomoapp.com/iwh/$WEBHOOK_TOKEN" fiThe unescaped value is written as executable shell syntax to either a shell startup file:
bash echo "" >> "$SHELL_CONFIG" echo "# Flomo Skill Configuration" >> "$SHELL_CONFIG" echo "export FLOMO_WEBHOOK_TOKEN=$WEBHOOK_TOKEN" >> "$SHELL_CONFIG"Or to the local
.envfile:bash ENV_FILE="$(dirname "$0")/../.env" echo "# Flomo Skill Configuration" > "$ENV_FILE" echo "FLOMO_WEBHOOK_TOKEN=$WEBHOOK_TOKEN" >> "$ENV_FILE" echo "# FLOMO_WEBHOOK_URL=$WEBHOOK_URL" >> "$ENV_FILE" chmod 600 "$ENV_FILE"scripts/flomo_send.shlater executes the generated.envfile as shell code:bash ENV_FILE="$(dirname "$0")/../.env" if [ -f "$ENV_FILE" ]; then set -o allexport # shellcheck disable=SC1090 source "$ENV_FILE" set +o allexport fiTechnical Analysis
The webhook token crosses a trust boundary from interactive user input into a shell program. It is serialized by concatenating it directly into an ...[truncated 2187 chars]
- Remediation
View remediation
Remediation Suggestions
-
Validate token-only input against the exact character set and length allowed by flomo. Reject whitespace, control characters, shell metacharacters, and unexpected URL syntax.
-
Prefer accepting only a token and constructing the fixed webhook URL internally. Do not accept arbitrary shell expressions or unrestricted URLs.
-
Do not load data files with
source. Store configuration in a non-executable format, such as JSON, and parse the required field with a data parser. -
If shell-compatible output is unavoidable, serialize values safely with
printf '%q'rather than string concatenation:bash { printf '%s\n' '# Flomo Skill Configuration' printf 'FLOMO_WEBHOOK_TOKEN=%q\n' "$WEBHOOK_TOKEN" } > "$ENV_FILE" chmod 600 "$ENV_FILE" -
Avoid writing credentials to shell startup files. Use the permission-restricted, non-executable application configuration file instead.
-
Write configuration atomically using a securely created temporary file, set restrictive permissions before adding the secret, and then rename it into place.
-
Add regression tests using values containing semicolons, command substitutions, quotes, backticks, spaces, and redirection operators. All malformed values should be rejected without executing any command.
-
