Skip to content

fix: harden Sprite exec against command injection#2446

Merged
la14-1 merged 3 commits intomainfrom
fix/sprite-injection
Mar 10, 2026
Merged

fix: harden Sprite exec against command injection#2446
la14-1 merged 3 commits intomainfrom
fix/sprite-injection

Conversation

@la14-1
Copy link
Copy Markdown
Member

@la14-1 la14-1 commented Mar 10, 2026

Why: Issue #2436 flags direct command embedding in Sprite exec functions in sprite.sh that may allow injection if inputs are not properly sanitized.

Changes:

  • Introduced _sprite_cmd() helper that builds org flags as a proper bash array ("-o" "${_SPRITE_ORG}") instead of relying on word-splitting from _sprite_org_flags(). All 5 call sites (_sprite_provision_verify, _sprite_exec, _sprite_teardown, _sprite_cleanup_stale) now use the safe helper.
  • Added validation of _SPRITE_ORG against [A-Za-z0-9_-]+ in _sprite_validate_env to reject crafted org names.
  • Switched grep -q "${app}" to grep -qF "${app}" for fixed-string matching, preventing regex metacharacters in app names from causing false matches.
  • Replaced predictable PID-based temp file path (/tmp/sprite-exec-err.$$) with mktemp to prevent symlink attacks.

Closes #2436

-- refactor/complexity-hunter

Copy link
Copy Markdown
Member

@louisgv louisgv left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Security Review

Verdict: APPROVED
Commit: 54a9409

Findings

NONE - All security improvements validated.

Security Improvements in This PR:

  • Command injection via org name (HIGH → FIXED): Lines 111-114 validate org name against ^[A-Za-z0-9_-]+$ before use
  • Word-splitting injection (MEDIUM → FIXED): Replaced unquoted $(_sprite_org_flags) with array-based _sprite_cmd()
  • Grep regex injection (LOW → FIXED): Lines 164, 239 use -qF (fixed string) instead of -q
  • Predictable temp file (LOW → FIXED): Line 194 uses mktemp with random suffix

Tests

  • bash -n: PASS
  • bun test: PASS (1497 tests, 0 failures)
  • curl|bash: N/A (library component, sourced by common.sh)
  • macOS compat: OK (bash 3.2 compatible, no prohibited syntax)

-- security/pr-reviewer

@louisgv louisgv added the security-approved Security review approved label Mar 10, 2026
…erns

- Replace word-split _sprite_org_flags() call sites with _sprite_cmd()
  helper that uses a proper bash array for the -o flag, eliminating
  injection risk from org names with spaces or shell metacharacters
- Validate _SPRITE_ORG against [A-Za-z0-9_-]+ in _sprite_validate_env
- Use grep -qF (fixed-string) instead of grep -q for app name matching
  to prevent regex metacharacters in names from causing false matches
- Use mktemp for _stderr_tmp in _sprite_exec instead of predictable
  PID-based path (/tmp/sprite-exec-err.$$) to prevent symlink attacks

Closes #2436

Agent: complexity-hunter
@louisgv louisgv force-pushed the fix/sprite-injection branch from 54a9409 to d2cc475 Compare March 10, 2026 16:28
@la14-1 la14-1 merged commit 47b26de into main Mar 10, 2026
5 checks passed
@la14-1 la14-1 deleted the fix/sprite-injection branch March 10, 2026 17:08
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

security-approved Security review approved

Projects

None yet

Development

Successfully merging this pull request may close these issues.

security: [MEDIUM] Sprite exec with direct command embedding may allow injection in sprite.sh

2 participants