Skip to content

fix(security): add session key auth to TUI mode TCP listener#207

Closed
Mike-7777777 wants to merge 1 commit into
psmux:masterfrom
Mike-7777777:fix/tui-auth-206
Closed

fix(security): add session key auth to TUI mode TCP listener#207
Mike-7777777 wants to merge 1 commit into
psmux:masterfrom
Mike-7777777:fix/tui-auth-206

Conversation

@Mike-7777777

@Mike-7777777 Mike-7777777 commented Apr 12, 2026

Copy link
Copy Markdown

Summary

Adds session key authentication to the TUI (interactive) mode TCP control listener, which was missed when auth was introduced for server (detached) mode in #5.

Fixes #206

What Changed

src/app.rs — single file, 53 lines added:

Change Mirrors
Generate random session key at startup server/mod.rs:334-342
Store key on AppState (used by keybinding send_control_to_port() calls) server/mod.rs:344
Write key to ~/.psmux/<session>.key server/mod.rs:348-349
#[cfg(windows)] file permission hardening server/mod.rs:357-366
Require AUTH <key> on every TCP connection; reject invalid/missing auth server/connection.rs:38-57

Every change directly mirrors existing server mode code. No new patterns introduced.

Why

The TCP listener in TUI mode accepted commands like new-window and split-window (which spawn arbitrary processes) without authentication. Any local process that could read the .port file could execute commands as the psmux user. See #206 for full analysis, PoC, and scope.

Test plan

  • cargo check — zero errors, zero warnings
  • cargo test — 2568 tests passed, 0 failed (7 test suites)
  • Manual: start psmux in TUI mode → verify ~/.psmux/<session>.key is created
  • Manual: psmux send-keys from another terminal → works (client reads .key, sends AUTH)
  • Manual: raw TCP connection without AUTH → rejected with "Authentication required"
  • Manual: keybindings (Prefix+c for new-window, Prefix+% for split) still work

🤖 Generated with Claude Code

The session key authentication introduced in psmux#5 was only applied to
server (detached) mode. TUI (interactive) mode accepted TCP commands
without authentication, allowing any local process to execute arbitrary
commands via new-window, split-window, or source-file.

This commit mirrors the server mode auth pattern in app.rs:

- Generate a random session key at TUI startup (server/mod.rs:334-342)
- Store it on AppState so keybindings using send_control_to_port() can
  authenticate back to the TCP listener (server/mod.rs:344)
- Write the key to ~/.psmux/<session>.key (server/mod.rs:348-349)
- Apply Windows file permission hardening (server/mod.rs:357-366)
- Require AUTH <key> as the first line of every TCP connection, reject
  unauthenticated or invalid connections (server/connection.rs:38-57)

Fixes psmux#206

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@psmux

psmux commented Apr 13, 2026

Copy link
Copy Markdown
Owner

Closing this PR. The issue it addresses (#206) is not reproducible. The code path in app.rs that this PR modifies is dead code that is never executed. All TCP connections already go through handle_connection() in connection.rs with full auth enforcement. See the detailed analysis on issue #206.

@psmux psmux closed this Apr 13, 2026
psmux added a commit that referenced this pull request Apr 26, 2026
…imination

Named Buffers (-b name):
- set-buffer -b name, show-buffer -b name, delete-buffer -b name, paste-buffer -b name
- Independent HashMap storage separate from positional buffer stack
- list-buffers shows both positional and named buffers
- Format variables (buffer_name, buffer_size, buffer_sample) support named buffer override

libtmux Native API Compatibility:
- Handle \ session ID targets (e.g. -t \) — treat as current session
- Handle @n window ID targets via FocusWindowById/FocusWindowByIdTemp
- list-panes -t @n now correctly lists panes of the targeted window
- list-windows -t \ works (session ID ignored, uses current session)
- Enables libtmux Server.sessions, .windows, .panes to work natively

PR #207 Workaround Elimination (all 6 workarounds proven unnecessary):
- WA1: list-sessions -F format flag works correctly
- WA2: Concatenated -Fformat syntax works
- WA3: has-session with = prefix for exact matching
- WA4: Environment variable propagation via set-environment
- WA5: Named buffers for concurrent buffer operations
- WA6: Bracketed paste mode support

Tests:
- 22 Rust unit tests for named buffers
- 11 Rust unit tests for PR207 compat
- 12 E2E PowerShell tests for named buffers
- 22 E2E PowerShell tests for PR207 compat
- 26 E2E workaround elimination tests
- 33 Python tests (25 subprocess + 8 libtmux native API)
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.

Security: TUI mode TCP listener bypasses session key authentication (incomplete fix for #5)

2 participants