Skip to content

Commit dc3c68d

Browse files
eurunuelaclaude
andcommitted
Fix: Command injection vulnerability in scripts/lint.sh
Convert shell string concatenation to bash array pattern to safely handle user-controlled arguments. This prevents shell metacharacters in the TARGET argument from being interpreted as commands. Changes: - Use bash array instead of string concatenation for building command - Expand array with "${CMD[@]}" to ensure proper quoting of each argument - Add comments documenting the security approach This follows the same safe pattern already applied to scripts/test.sh. Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
1 parent 18c6118 commit dc3c68d

2 files changed

Lines changed: 43 additions & 7 deletions

File tree

claude-progress.txt

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1623,6 +1623,42 @@ import { VERSION_DISPLAY } from "./constants/version";
16231623

16241624
---
16251625

1626+
## Session 13 - PR Review Fixes (2026-01-10)
1627+
1628+
### Goals
1629+
- Address PR review comments about command injection vulnerabilities in shell scripts
1630+
1631+
### PR Review Comments Addressed
1632+
1633+
#### 1. scripts/test.sh - Command Injection (Already Fixed)
1634+
- **Issue**: `eval $CMD` with user-controlled `TEST_FILE` argument allowed command injection
1635+
- **Status**: Already fixed in a previous commit using bash array (`ARGS=()`) with safe expansion (`"${ARGS[@]}"`)
1636+
1637+
#### 2. scripts/lint.sh - Command Injection (Fixed)
1638+
- **Issue**: String concatenation of `CMD` with unvalidated `TARGET` argument allowed injection
1639+
- **Fix**: Converted from string concatenation to bash array approach:
1640+
```bash
1641+
# Before (vulnerable)
1642+
CMD="npx eslint"
1643+
CMD="$CMD --ext .js,.jsx $TARGET"
1644+
$CMD
1645+
1646+
# After (safe)
1647+
CMD=(npx eslint)
1648+
CMD+=("--ext" ".js,.jsx" "$TARGET")
1649+
"${CMD[@]}"
1650+
```
1651+
1652+
### Files Modified
1653+
- `scripts/lint.sh` - Fixed command injection vulnerability using bash array
1654+
1655+
### Technical Details
1656+
- Using bash arrays prevents shell metacharacters in arguments from being interpreted
1657+
- Array expansion with `"${CMD[@]}"` ensures each element is treated as a separate, properly-quoted argument
1658+
- This is the standard pattern for safely building and executing commands with user input
1659+
1660+
---
1661+
16261662
## Template for Future Sessions
16271663

16281664
```

scripts/lint.sh

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -82,27 +82,27 @@ echo ""
8282
echo "Target: $TARGET"
8383
echo ""
8484

85-
# Build the command
86-
CMD="npx eslint"
85+
# Build the command arguments array (safe from injection)
86+
CMD=(npx eslint)
8787

8888
if [ "$FIX" = true ]; then
89-
CMD="$CMD --fix"
89+
CMD+=("--fix")
9090
echo "Mode: Fix"
9191
else
9292
echo "Mode: Check only (use --fix to auto-fix)"
9393
fi
9494

9595
if [ "$QUIET" = true ]; then
96-
CMD="$CMD --quiet"
96+
CMD+=("--quiet")
9797
fi
9898

9999
# Add file extensions and target
100-
CMD="$CMD --ext .js,.jsx $TARGET"
100+
CMD+=("--ext" ".js,.jsx" "$TARGET")
101101

102102
echo ""
103103

104-
# Run linter
105-
$CMD
104+
# Run linter (using array expansion to safely pass arguments)
105+
"${CMD[@]}"
106106

107107
LINT_EXIT=$?
108108

0 commit comments

Comments
 (0)