fix: validate connection parameters to prevent command injection#1392
Merged
fix: validate connection parameters to prevent command injection#1392
Conversation
…, #1380) Add input validation for SSH connection parameters (IP, username, server_name) and server identifiers used in delete operations. This prevents command injection attacks if ~/.spawn/history.json is corrupted or tampered with. Changes: - Add validateConnectionIP() - validates IPv4/IPv6 addresses and sentinels - Add validateUsername() - validates Unix username format - Add validateServerIdentifier() - validates server names/IDs - Update cmdConnect() to validate all connection params before use - Update buildDeleteScript() to validate server IDs before interpolation - Update mergeLastConnection() to validate data from bash scripts - Add comprehensive test coverage for all validation functions - Bump CLI version to 0.3.3 (security patch) Security impact: - Prevents HIGH severity command injection via history.ip/user (issue #1381) - Prevents MEDIUM severity command injection via server_id (issue #1380) Agent: security-auditor Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
This was referenced Feb 17, 2026
louisgv
approved these changes
Feb 17, 2026
Member
louisgv
left a comment
There was a problem hiding this comment.
Security Review
Verdict: APPROVED
Summary
This PR adds critical input validation for connection parameters to prevent command injection via corrupted/tampered history files. Implementation is sound with defense-in-depth approach.
Findings
- LOW (cosmetic)
cli/src/security.ts:169-183— IPv4 validation accepts leading zeros (e.g., "01.1.1.1"). No security risk:parseInt(octet, 10)forces decimal interpretation, and IP is only used in SSH string interpolation already protected by validation.
Security Strengths
- Defense in depth — Validation at 3 layers: data merge, SSH connect, server delete
- Comprehensive allowlists — All validators block shell metacharacters, path traversal, command substitution
- Proper error handling — Graceful degradation on merge, hard fail before use with clear guidance
- Excellent test coverage — 23 tests covering edge cases and injection attempts
Tests
- bash -n: N/A (no shell scripts)
- bun test (security): PASS (23/23)
- bun test (all): Pre-existing failures unrelated to PR
- curl|bash: N/A (TypeScript only)
- macOS compat: N/A (TypeScript only)
- Edge cases: PASS (all injection attempts blocked)
Test Results
✓ IPv4 octet range validation (256.x.x.x rejected)
✓ Shell metacharacters blocked (;, &, |, $, backticks)
✓ Command substitution blocked ($(...), `...`)
✓ Path traversal blocked (.., /, \)
✓ Newlines/tabs/spaces blocked in usernames and IDs
✓ Empty/whitespace-only values rejected
✓ Length limits enforced (username: 32, server ID: 128)
✓ Special sentinels accepted (sprite-console, fly-ssh, daytona-sandbox)
-- security/pr-reviewer-1392
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Why: Prevents HIGH severity command injection vulnerability where malicious values in ~/.spawn/history.json could execute arbitrary commands when connecting to or deleting servers.
Summary
Security Impact
Attack Vector (Before Fix):
~/.spawn/history.jsongets corrupted or manually edited{"ip": "8.8.8.8; rm -rf /tmp/pwned", ...}spawn listand selects the recordAfter Fix:
Changes
New validation functions in
cli/src/security.ts:validateConnectionIP()- validates IPv4/IPv6 or sentinel values ("sprite-console", "fly-ssh", "daytona-sandbox")validateUsername()- validates Unix username pattern (lowercase, starts with letter/underscore)validateServerIdentifier()- validates server names/IDs (alphanumeric, hyphens, dots, underscores only)Updated functions:
cmdConnect()- validates all connection params before constructing SSH/sprite commandsbuildDeleteScript()- validates server IDs before shell interpolationmergeLastConnection()- validates data from bash scripts before saving to historyTest coverage:
security-connection-validation.test.tswith 23 test casesVersion Bump
spawnrunTesting
Verified no regressions in existing test suite (same failures as main branch).
-- refactor/security-auditor