T09 · Insecure Skill Coding Practices
- Location
scripts/script.sh:133- Finding
Configuration Injection Through Unescaped sed and Regular Expression Input
- Content
View full analysis
Vulnerability Details
File Location:
scripts/script.sh, lines 133-145
Vulnerability Type: Configuration command and regular-expression injection
Risk Level: HighVulnerable Code
bash cmd_config() { local key="${1:-}" val="${2:-}" local cfg="$DATA_DIR/config.txt" if [ -z "$key" ]; then echo "=== Config ===" if [ -f "$cfg" ]; then while IFS="=" read -r k v; do echo " $k=$v"; done < "$cfg" else echo " (empty — use config <key> <value>)"; fi elif [ -z "$val" ]; then grep "^${key}=" "$cfg" 2>/dev/null | cut -d= -f2- || echo "(not set)" else if [ -f "$cfg" ] && grep -q "^${key}=" "$cfg" 2>/dev/null; then sed -i "s|^${key}=.*|${key}=${val}|" "$cfg" else echo "${key}=${val}" >> "$cfg" fi echo "Set: $key=$val" fi }Technical Analysis
The
keyandvalcommand-line arguments are inserted directly intogrepregular expressions and a dynamically constructedsedprogram. Neither input is validated nor escaped for its syntactic context.A key containing regular-expression metacharacters can match configuration entries other than the intended literal key. A value containing the
|delimiter, replacement backreferences, newlines, or othersedsyntax can alter or invalidate the generated substitution program. Newline-bearing arguments can potentially introduce additionalsedcommands. The exact escalation potential depends on the installedsedimplementation and supported extensions, but unintended configuration modification and denial of service are directly reachable.Attack Path
- An attacker gains the ability to invoke the Skill with attacker-controlled
configarguments. - The attacker supplies a key containing regular-expression syntax, causing
grepto identify an unintended configuration entry ...[truncated 813 chars]
- An attacker gains the ability to invoke the Skill with attacker-controlled
- Remediation
View remediation
Remediation Suggestions
- Enforce a strict configuration-key format, such as
^[A-Za-z_][A-Za-z0-9_]*$. - Do not construct
greporsedprograms by interpolating untrusted input. - Replace the update operation with a structured implementation that compares keys literally.
- If
awkis used, pass values through-vvariables and compare parsed fields rather than embedding input into source code. - Reject carriage returns, line feeds, NUL bytes, and other control characters in keys and values.
- Write updates to a securely created temporary file in the same directory, set restrictive permissions, validate the result, and atomically rename it into place.
- Add tests for keys and values containing regex metacharacters,
seddelimiters, backslashes, ampersands, and newlines.
- Enforce a strict configuration-key format, such as
