Skip to content

🤖 feat: mux module — add per-workspace auth token for CSWSH protection#728

Merged
ibetitsmike merged 4 commits intomainfrom
mike/mux-auth-token
Feb 14, 2026
Merged

🤖 feat: mux module — add per-workspace auth token for CSWSH protection#728
ibetitsmike merged 4 commits intomainfrom
mike/mux-auth-token

Conversation

@ibetitsmike
Copy link
Contributor

@ibetitsmike ibetitsmike commented Feb 13, 2026

Summary

Add per-workspace authentication token wiring to the Mux Coder module, closing the last-mile deployment gap for cross-site WebSocket hijacking (CSWSH) protection identified in coder/security#120.

Background

When Mux runs as a Coder workspace app, it is accessible via Coder's subdomain proxy (e.g., mux--ws--user.apps.coder.com). Without an auth token, a malicious same-site origin (another user's workspace app on the same *.coder.com domain) can hijack the WebSocket session and execute arbitrary commands via the oRPC API.

The Mux application itself already implements:

What was missing was module-level token generation and browser/backend wiring.

Implementation

  • random_password.mux_auth_token generates a 64-character token per module instance.
  • Backend wiring: run.sh launches mux with a process-scoped MUX_SERVER_AUTH_TOKEN environment variable.
  • Frontend wiring: coder_app.mux.url includes ?token=<secret> so first launch from Coder passes the token to the browser for bootstrap/persistence.

To avoid cross-instance breakage, this change intentionally does not use a shared coder_env key. Multiple coder/mux module instances can target the same agent_id (different slug/port), and a single global env key would collide. Process-scoped env keeps each instance's backend token aligned with its app URL token.

Validation

  • terraform fmt -check -diff in registry/coder/modules/mux
  • terraform test in registry/coder/modules/mux (8 passed, 0 failed)
  • Updated tests now verify the URL token value (not just prefix) and verify the launch script sets MUX_SERVER_AUTH_TOKEN using the generated token.

Generated with mux • Model: anthropic:claude-opus-4-6 • Thinking: xhigh

Generate a random 64-char token per workspace via random_password.
Inject into the Mux server process as MUX_SERVER_AUTH_TOKEN (coder_env)
and into the browser via ?token= in coder_app.url. The frontend already
extracts this parameter and persists it to localStorage.

This closes the last-mile deployment gap for coder/security#120:
the origin-check + auth-token combination blocks cross-site WebSocket
hijacking from same-site origins (e.g. other workspace apps).

Bump module version references to 1.1.0.
Copy link

@chatgpt-codex-connector chatgpt-codex-connector bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 55be495ef4

ℹ️ About Codex in GitHub

Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

random_password.result is unknown during plan, causing 'Unknown condition
value' errors. Tests that check the URL or token value must use apply.
@ibetitsmike
Copy link
Contributor Author

@codex review

Copy link

@chatgpt-codex-connector chatgpt-codex-connector bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: f3af56b022

ℹ️ About Codex in GitHub

Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

Pass the generated auth token to each mux process via process-scoped
MUX_SERVER_AUTH_TOKEN in run.sh instead of creating a global coder_env
entry. This avoids collisions when multiple mux module instances target
the same agent.

Also tighten terraform tests to assert that the URL token value matches
the generated token, and update remaining README examples to 1.1.0.
@ibetitsmike
Copy link
Contributor Author

@codex review

@chatgpt-codex-connector
Copy link

Codex Review: Didn't find any major issues. 🎉

ℹ️ About Codex in GitHub

Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

@ibetitsmike
Copy link
Contributor Author

@codex review

Addressed prior feedback and resolved the related threads.

@chatgpt-codex-connector
Copy link

Codex Review: Didn't find any major issues. You're on a roll.

ℹ️ About Codex in GitHub

Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

@ibetitsmike ibetitsmike added the version:minor Add to PRs requiring a minor version upgrade label Feb 14, 2026
@ibetitsmike ibetitsmike merged commit 39fec7c into main Feb 14, 2026
5 checks passed
@ibetitsmike ibetitsmike deleted the mike/mux-auth-token branch February 14, 2026 22:08
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

version:minor Add to PRs requiring a minor version upgrade

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants