Skip to content

fix: runCommand returns correct success status and remove credentials…#156

Open
SARAMALI15792 wants to merge 1 commit intoFullAgent:mainfrom
SARAMALI15792:fix/run-command-exit-code
Open

fix: runCommand returns correct success status and remove credentials…#156
SARAMALI15792 wants to merge 1 commit intoFullAgent:mainfrom
SARAMALI15792:fix/run-command-exit-code

Conversation

@SARAMALI15792
Copy link
Copy Markdown


Bug Fixes — Command Failure Detection & Terminal Credential Security

This PR fixes two bugs discovered during a code review of the sandbox
execution and terminal connection layer.


Bug 1 — Commands Were Always Reported as Successful Even on Failure

How to Reproduce

  1. Open any project in the app
  2. Trigger a command that is guaranteed to fail, such as exit 1
  3. Observe the response — it incorrectly returns success: true
  4. Expected: success: false | Actual: success: true

Root Cause

execCommand in lib/util/ttyd-exec.ts was silently discarding
the shell exit code and returning only the raw output text.
As a result, runCommand in lib/actions/sandbox.ts had no way
to distinguish a successful command from a failed one — it blindly
returned { success: true } every single time.

Fix

  • Updated execCommand to return { output, exitCode } instead
    of just a plain string
  • Added an exit code check inside runCommand
    • exitCode !== 0 → returns { success: false, error: "Command failed with exit code X" }
    • exitCode === 0 → returns { success: true, output } as intended

Outcome

Failed commands are now correctly reported as success: false.
AI agents and other callers can reliably detect failures and handle
them properly instead of silently building on a broken state.

Future Recommendation

Consider exposing the raw exitCode value inside the ExecResult
type so callers have full visibility into what the command returned,
not just a boolean success flag.


Bug 2 — Terminal Credentials Were Being Leaked Into Server Logs

How to Reproduce

  1. Open any running project and navigate to the terminal
  2. Open browser DevTools → Network tab → filter by ws
  3. Refresh the page and click on the WebSocket connection
  4. Inspect the request URL — it contains ?authorization=dXNlcjpwYXNz
  5. That value is the base64 encoded username and password
    of the terminal session, visible in plain sight

Root Cause

The buildWsUrl function in lib/util/ttyd-exec.ts was appending
the authorization credential as a URL query parameter on every
WebSocket connection. This meant the credential was being written
into every Kubernetes, nginx, and server access log entry on each
terminal session — a significant security exposure.

Fix

  • Removed authorization from the URL query params inside buildWsUrl
  • Stripped authorization from the final WebSocket URL inside
    xterm-terminal.tsx before the connection is established
  • The credentials were already being transmitted securely inside
    the WebSocket init message — removing them from the URL does not
    affect authentication or terminal functionality in any way

Outcome

Terminal credentials no longer appear in any server access logs.
The terminal connects and operates exactly as before — the only
difference is that sensitive credentials are no longer exposed.

Future Recommendation

Consider storing the ttyd URL in the database without the
authorization query param embedded inside it. Keeping credentials
completely separate from URLs at the storage level would eliminate
this class of issue entirely going forward.


… from WebSocket URL

- execCommand now returns { output, exitCode } instead of just output string
- runCommand checks exitCode and returns success:false when command fails
- Remove authorization credentials from WebSocket URL query params
- Credentials are already sent securely in WebSocket init message
@github-actions
Copy link
Copy Markdown

❌ PR Check Results: Failed

Build Checks

Check Status
Lint & Build ❌ Failed
Docker Build ❌ Failed

⚠️ Action Required

Some checks failed. Please review the errors and update your PR.

Lint/Build Issues:

  • Check the "Lint and Build Check" job for details
  • Fix linting errors with pnpm run lint:fix
  • Ensure the project builds locally with pnpm run build

Docker Build Issues:

  • Check the "Docker Build Test" job for details
  • Verify Dockerfile changes
  • Test Docker build locally

Commit: 22a6cabf4ee1f884db2bcfa0d0a2885eb1b44f87
Branch: fix/run-command-exit-code

🔗 View Details:

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant