T09 · Insecure Skill Coding Practices
- Location
scripts/glab-mr-await.sh:18- Finding
Command Injection Through Unvalidated MR Wait Timeout
- Content
View full analysis
Vulnerability Details
File Location:
scripts/glab-mr-await.sh, lines 18-30 and 99
Vulnerability Type: Unvalidated input evaluated in a Bash arithmetic context
Risk Level: HighVulnerable Code
bash TIMEOUT="${TIMEOUT:-3600}" # Default 1 hour # Parse args shift || true while [[ $# -gt 0 ]]; do case $1 in --timeout|-t) TIMEOUT="$2" shift 2 ;;bash if [[ $ELAPSED -ge $TIMEOUT ]]; then echo "⏰ Timeout after ${TIMEOUT}s" exit 1 fiTechnical Analysis
TIMEOUTcan originate from either the process environment or the--timeoutcommand-line argument. The script does not verify that it contains only a non-negative integer before using it as an operand in a Bash arithmetic comparison.Bash recursively evaluates variable contents in arithmetic contexts. Crafted arithmetic expressions can therefore cause expansions, including command substitutions embedded in array-index expressions, to be evaluated. If an attacker can influence the script environment or the argument passed by an automation agent, the comparison can become a command-execution sink.
The use of quotation marks around the initial assignments does not mitigate this issue because the dangerous interpretation occurs later, inside the arithmetic comparison.
Attack Path
- An attacker influences a workflow, prompt, configuration, or wrapper that supplies
TIMEOUTor--timeout. - The attacker supplies a value constructed as a Bash arithmetic expression containing a command substitution.
- The script stores that value without validation.
- Execution reaches
[[ $ELAPSED -ge $TIMEOUT ]]. - Bash evaluates the attacker-controlled arithmetic expression and executes the embedded command.
- The command runs with the operating-system privileges and accessible credentials of the user or automation account running the skill.
Impact Assess
...[truncated 510 chars]
- An attacker influences a workflow, prompt, configuration, or wrapper that supplies
- Remediation
View remediation
Remediation Suggestions
Validate all numeric settings immediately after argument parsing and before any arithmetic operation:
bash if [[ ! "$TIMEOUT" =~ ^[0-9]+$ ]]; then echo "Error: timeout must be a non-negative integer" >&2 exit 2 fiAdditional hardening should include:
- Check that
--timeouthas a following value before reading$2. - Impose a reasonable upper bound to prevent excessive execution time.
- Validate
MR_NUMBERas an integer before passing it toglab. - Validate every environment-derived value before using it in arithmetic or command construction.
- Avoid passing arguments generated directly from untrusted issue, merge-request, or prompt content.
- Check that
