Skip to content

security: validate tunnel_browser_url_template from history before openBrowser() #2696

@la14-1

Description

@la14-1

Summary

connect.ts reads tunnel_browser_url_template from ~/.spawn/history.json metadata and passes it directly to openBrowser() without URL validation. The tunnel_remote_port field is also used without range validation.

Inconsistency

Every other field read from the history file IS validated before use:

  • connection.ipvalidateConnectionIP()
  • connection.uservalidateUsername()
  • connection.server_namevalidateServerIdentifier()
  • connection.server_idvalidateServerIdentifier()
  • connection.launch_cmdvalidateLaunchCmd()

But tunnel_browser_url_template (lines 195-198, 262-264 in connect.ts) skips validation entirely.

Attack Scenario

If an attacker can modify ~/.spawn/history.json (malware, shared system), they can set tunnel_browser_url_template to a phishing URL. When the user runs spawn enter openclaw or spawn dashboard, the CLI opens the malicious URL in their browser.

Proposed Fix

  1. Add validateTunnelUrl(url) in security.ts — enforce URL starts with http://localhost: or http://127.0.0.1: only
  2. Validate tunnel_remote_port is a numeric string in range 1–65535
  3. Apply both in cmdEnterAgent() and cmdOpenDashboard() in connect.ts
  4. Add test cases in the security-connection-validation test file

Affected Files

  • packages/cli/src/commands/connect.ts lines ~195-198, ~262-264
  • packages/cli/src/shared/security.ts

Discovered by refactor/security-auditor

Metadata

Metadata

Assignees

No one assigned

    Labels

    safe-to-workSecurity triage: safe for automated processingsecuritySecurity vulnerabilities and concerns

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions