Skip to content

fix(security): validate script templates before base64 encoding#3132

Merged
louisgv merged 1 commit intomainfrom
fix/issue-3130
Apr 1, 2026
Merged

fix(security): validate script templates before base64 encoding#3132
louisgv merged 1 commit intomainfrom
fix/issue-3130

Conversation

@la14-1
Copy link
Copy Markdown
Member

@la14-1 la14-1 commented Apr 1, 2026

Why: Prevents future regression where template variable interpolation before base64 encoding could allow command injection in systemd services running with root privileges on remote VMs.

Fixes #3130

Changes

  • Add pre-encoding validation in startGateway() (agent-setup.ts)
  • Add pre-encoding validation in setupAutoUpdate() (agent-setup.ts)
  • Add pre-encoding validation in injectSpawnSkill() (spawn-skill.ts)

The validation checks that script templates don't contain ${ interpolation patterns before base64 encoding, as defense-in-depth against future changes that might add template variable interpolation.

-- refactor/security-auditor

@la14-1 la14-1 marked this pull request as ready for review April 1, 2026 02:03
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: 7a257c3

Summary

This PR adds defense-in-depth validation to prevent accidental JS template literal interpolation in script templates before base64 encoding. The implementation is sound and improves security posture.

Changes Reviewed

  • packages/cli/src/shared/agent-setup.ts: Added validateScriptTemplate() function and applied it to gateway/auto-update systemd units
  • packages/cli/src/shared/spawn-skill.ts: Applied validation to spawn skill content
  • packages/cli/package.json: Version bump 0.30.1 → 0.30.2

Security Findings

None — No security issues identified.

Positive Security Aspects

  • ✅ Prevents template literal interpolation before encoding (defense-in-depth)
  • ✅ Regex pattern /\$\{/ is precise and appropriate
  • ✅ Error messages are clear without leaking sensitive data
  • ✅ Validation placement is correct (before encoding)
  • ✅ Existing base64 validation remains intact
  • ✅ No command injection vectors
  • ✅ No credential exposure risks
  • ✅ Proper ESM conventions

Tests

  • TypeScript tests: ✅ PASS (2023/2023 tests passed)
  • Shell scripts: N/A (no .sh files modified)

-- security/pr-reviewer

@louisgv louisgv added the security-approved Security review approved label Apr 1, 2026
Add pre-encoding validation to reject ${} interpolation patterns in
script template strings before they are base64-encoded and injected
into systemd services running with root privileges on remote VMs.

Defense-in-depth against future regressions where template variable
interpolation before encoding could allow command injection.

Fixes #3130

Agent: security-auditor
Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
@louisgv louisgv merged commit 3b61c22 into main Apr 1, 2026
5 checks passed
@louisgv louisgv deleted the fix/issue-3130 branch April 1, 2026 03:15
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.

[HIGH] Command injection risk in systemd service file generation

2 participants