security: harden shellQuote and consolidate shell escaping in gcp.ts#2533
Merged
security: harden shellQuote and consolidate shell escaping in gcp.ts#2533
Conversation
- Add null-byte rejection to shellQuote (defense-in-depth) - Export shellQuote for testability - Refactor interactiveSession to use shellQuote instead of inline escaping - Add comprehensive test suite for shellQuote security properties Fixes #2529 Agent: security-auditor Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
louisgv
approved these changes
Mar 12, 2026
Member
louisgv
left a comment
There was a problem hiding this comment.
Security Review
Verdict: APPROVED ✅
Commit: eea7e9e
Summary
This PR significantly improves command injection protection in GCP SSH session handling by hardening and consolidating shell escaping through a dedicated shellQuote() function.
Security Findings
No vulnerabilities found. This PR introduces strong security improvements:
-
Enhanced Command Injection Protection (HIGH IMPACT)
- Consolidates shell escaping through hardened
shellQuote()function (line 1026) - POSIX single-quote escaping (
'\''technique) prevents all shell metacharacter expansion - Protects against:
$(),\`,${},|,;,&&`, and other injection vectors
- Consolidates shell escaping through hardened
-
Defense-in-Depth: Null Byte Validation (MEDIUM IMPACT)
- Added null byte check directly in
shellQuote()(line 1092-1094) - Complements existing validation in
interactiveSession()(line 1020) - Protects against C-level string truncation attacks
- Added null byte check directly in
-
Comprehensive Test Coverage (HIGH VALUE)
- 12 new tests covering all critical security scenarios
- Validates protection against command substitution, variable expansion, shell operators
- Tests edge cases: empty strings, consecutive quotes, newlines, tabs, backslashes
- Confirms null byte rejection
Tests
- ✅ bun test: 1400 pass / 0 fail (including 12 new shellQuote tests)
- ✅ biome lint: 0 errors
- ✅ macOS compat: POSIX single-quote escaping is portable
- ✅ curl|bash: N/A (TypeScript code, not shell script)
Version Management
- ✅ Version correctly bumped: 0.16.16 → 0.16.17
Code Quality
- Exported
shellQuoteenables reuse and testing - Clear JSDoc documentation
- No regressions introduced
-- security/pr-reviewer
la14-1
pushed a commit
that referenced
this pull request
Mar 12, 2026
PR #2533 hardened GCP with shellQuote() and null-byte rejection, but left Hetzner, DigitalOcean, AWS, and connect.ts using inline .replace(/'/g, "'\\''") without null-byte validation. - Move shellQuote to shared/ui.ts as the single source of truth - Add null-byte validation to runServer in Hetzner, DO, and AWS - Replace inline shell escaping with shellQuote in interactiveSession across all clouds, connect.ts, and agents.ts buildEnvBlock - Re-export shellQuote from gcp.ts for backwards compatibility Agent: security-auditor Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
louisgv
added a commit
that referenced
this pull request
Mar 12, 2026
PR #2533 hardened GCP with shellQuote() and null-byte rejection, but left Hetzner, DigitalOcean, AWS, and connect.ts using inline .replace(/'/g, "'\\''") without null-byte validation. - Move shellQuote to shared/ui.ts as the single source of truth - Add null-byte validation to runServer in Hetzner, DO, and AWS - Replace inline shell escaping with shellQuote in interactiveSession across all clouds, connect.ts, and agents.ts buildEnvBlock - Re-export shellQuote from gcp.ts for backwards compatibility Agent: security-auditor Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
louisgv
added a commit
that referenced
this pull request
Mar 12, 2026
…#2535) PR #2533 hardened GCP with shellQuote() and null-byte rejection, but left Hetzner, DigitalOcean, AWS, and connect.ts using inline .replace(/'/g, "'\\''") without null-byte validation. - Move shellQuote to shared/ui.ts as the single source of truth - Add null-byte validation to runServer in Hetzner, DO, and AWS - Replace inline shell escaping with shellQuote in interactiveSession across all clouds, connect.ts, and agents.ts buildEnvBlock - Re-export shellQuote from gcp.ts for backwards compatibility Agent: security-auditor Co-authored-by: B <6723574+louisgv@users.noreply.github.com> Co-authored-by: Claude Sonnet 4.5 <noreply@anthropic.com>
AhmedTMM
pushed a commit
to AhmedTMM/spawn
that referenced
this pull request
Mar 12, 2026
…penRouterTeam#2533) - Add null-byte rejection to shellQuote (defense-in-depth) - Export shellQuote for testability - Refactor interactiveSession to use shellQuote instead of inline escaping - Add comprehensive test suite for shellQuote security properties Fixes OpenRouterTeam#2529 Agent: security-auditor Co-authored-by: B <6723574+louisgv@users.noreply.github.com> Co-authored-by: Claude Sonnet 4.5 <noreply@anthropic.com>
AhmedTMM
pushed a commit
to AhmedTMM/spawn
that referenced
this pull request
Mar 12, 2026
…OpenRouterTeam#2535) PR OpenRouterTeam#2533 hardened GCP with shellQuote() and null-byte rejection, but left Hetzner, DigitalOcean, AWS, and connect.ts using inline .replace(/'/g, "'\\''") without null-byte validation. - Move shellQuote to shared/ui.ts as the single source of truth - Add null-byte validation to runServer in Hetzner, DO, and AWS - Replace inline shell escaping with shellQuote in interactiveSession across all clouds, connect.ts, and agents.ts buildEnvBlock - Re-export shellQuote from gcp.ts for backwards compatibility Agent: security-auditor Co-authored-by: B <6723574+louisgv@users.noreply.github.com> Co-authored-by: Claude Sonnet 4.5 <noreply@anthropic.com>
la14-1
pushed a commit
that referenced
this pull request
Mar 13, 2026
Dead backwards-compat re-export left over from the shellQuote consolidation (PRs #2533, #2535, #2546). Zero consumers import shellQuote from gcp/gcp.ts — all correctly import from shared/ui.ts. Per CLAUDE.md: avoid backwards-compatibility hacks; delete unused code. Agent: code-health Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
AhmedTMM
pushed a commit
to AhmedTMM/spawn
that referenced
this pull request
Mar 13, 2026
…penRouterTeam#2533) - Add null-byte rejection to shellQuote (defense-in-depth) - Export shellQuote for testability - Refactor interactiveSession to use shellQuote instead of inline escaping - Add comprehensive test suite for shellQuote security properties Fixes OpenRouterTeam#2529 Agent: security-auditor Co-authored-by: B <6723574+louisgv@users.noreply.github.com> Co-authored-by: Claude Sonnet 4.5 <noreply@anthropic.com>
AhmedTMM
pushed a commit
to AhmedTMM/spawn
that referenced
this pull request
Mar 13, 2026
…OpenRouterTeam#2535) PR OpenRouterTeam#2533 hardened GCP with shellQuote() and null-byte rejection, but left Hetzner, DigitalOcean, AWS, and connect.ts using inline .replace(/'/g, "'\\''") without null-byte validation. - Move shellQuote to shared/ui.ts as the single source of truth - Add null-byte validation to runServer in Hetzner, DO, and AWS - Replace inline shell escaping with shellQuote in interactiveSession across all clouds, connect.ts, and agents.ts buildEnvBlock - Re-export shellQuote from gcp.ts for backwards compatibility Agent: security-auditor Co-authored-by: B <6723574+louisgv@users.noreply.github.com> Co-authored-by: Claude Sonnet 4.5 <noreply@anthropic.com>
louisgv
added a commit
that referenced
this pull request
Mar 13, 2026
Dead backwards-compat re-export left over from the shellQuote consolidation (PRs #2533, #2535, #2546). Zero consumers import shellQuote from gcp/gcp.ts — all correctly import from shared/ui.ts. Per CLAUDE.md: avoid backwards-compatibility hacks; delete unused code. Agent: code-health Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
5 tasks
louisgv
added a commit
that referenced
this pull request
Mar 13, 2026
Dead backwards-compat re-export left over from the shellQuote consolidation (PRs #2533, #2535, #2546). Zero consumers import shellQuote from gcp/gcp.ts — all correctly import from shared/ui.ts. Per CLAUDE.md: avoid backwards-compatibility hacks; delete unused code. Agent: code-health Co-authored-by: B <6723574+louisgv@users.noreply.github.com> Co-authored-by: Claude Sonnet 4.5 <noreply@anthropic.com>
AhmedTMM
pushed a commit
to AhmedTMM/spawn
that referenced
this pull request
Mar 13, 2026
…penRouterTeam#2533) - Add null-byte rejection to shellQuote (defense-in-depth) - Export shellQuote for testability - Refactor interactiveSession to use shellQuote instead of inline escaping - Add comprehensive test suite for shellQuote security properties Fixes OpenRouterTeam#2529 Agent: security-auditor Co-authored-by: B <6723574+louisgv@users.noreply.github.com> Co-authored-by: Claude Sonnet 4.5 <noreply@anthropic.com>
AhmedTMM
pushed a commit
to AhmedTMM/spawn
that referenced
this pull request
Mar 13, 2026
…OpenRouterTeam#2535) PR OpenRouterTeam#2533 hardened GCP with shellQuote() and null-byte rejection, but left Hetzner, DigitalOcean, AWS, and connect.ts using inline .replace(/'/g, "'\\''") without null-byte validation. - Move shellQuote to shared/ui.ts as the single source of truth - Add null-byte validation to runServer in Hetzner, DO, and AWS - Replace inline shell escaping with shellQuote in interactiveSession across all clouds, connect.ts, and agents.ts buildEnvBlock - Re-export shellQuote from gcp.ts for backwards compatibility Agent: security-auditor Co-authored-by: B <6723574+louisgv@users.noreply.github.com> Co-authored-by: Claude Sonnet 4.5 <noreply@anthropic.com>
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: Eliminates inconsistent shell-escaping patterns in gcp.ts that could allow a null-byte truncation attack to bypass quoting, and reduces future regression risk by consolidating all escaping through a single hardened function.
Fixes #2529
Changes
shellQuote: Added null-byte rejection as defense-in-depth (callers already validate, but the function itself should be safe to call independently)shellQuote: Makes it testable and available for consistent use across GCP moduleinteractiveSession: Replaced inlinecmd.replace(/'/g, "'\\''")withshellQuote(cmd)— eliminates duplicate escaping logic that could drift out of syncSecurity Analysis
The
shellQuotefunction itself uses the correct POSIX single-quote escaping technique ('\''), which is the same approach as Python'sshlex.quote(). The real risks addressed:shellQuotelevel.interactiveSessionwas doing inlinereplace()instead of callingshellQuote, meaning any future hardening toshellQuotewouldn't propagate. Now consolidated.Test plan
bun test src/__tests__/gcp-shellquote.test.ts— 12/12 passbun test— 1408/1408 pass (0 regressions)bunx @biomejs/biome check src/— 0 errors-- refactor/security-auditor