Skip to content

fix(api): an exec control message is checked flat before any transformation (closes #472) - #481

Merged
samuelmbabhazi merged 3 commits into
mainfrom
fix/472-exec-control-frames
Nov 25, 2026
Merged

samuelmbabhazi merged 3 commits into
mainfrom
fix/472-exec-control-frames

Conversation

@samuelmbabhazi

Copy link
Copy Markdown
Collaborator

Closes #472 (P1, from the 2026-11-25 security audit).

What was wrong

7dba097 (#457) validated the browser's control messages with class-validator DTOs. It called plainToInstance on the whole parsed object, so an unexpected field with deep nesting was walked recursively. An 18 KB message, well under the 64 KiB maxPayload, threw RangeError: Maximum call stack size exceeded (reproduced here). browserFrame caught only JSON.parse, and the WebSocket message listener had no boundary, so the error could escape to the process.

What changed

  • controlFrame checks the shape first, flat. A resize must have exactly type, cols and rows, a close exactly type and kill, each a primitive of the expected type. Only those values are copied into the DTO. The transformation therefore never sees anything the browser nested, and a message with an extra key is ignored like any other unknown one.
  • browserFrame wraps parsing and validation together: nesting past what the parser takes is no frame either.
  • The message listener has an exception boundary. If a message ever throws, it logs a warning naming the session only, never the message, and ends that session as failed. The process and the other sessions go on.
  • SPEC 3.1 describes the flat check and the boundary.

How it was tested

  • Unit: deeply nested extra fields on resize and close, 30 000 nested arrays, an extra flat key, and a constructor/prototype key. All are under 64 KiB and all are ignored without throwing. The existing malicious-input cases still pass.
  • Real WebSocket server (exec-socket.spec.ts): a session sends the nested message, then a valid resize. The resize reaches the agent, and a second session on another server instance still joins. Before this change, that test hung on the uncaught error and the unit test threw RangeError.
  • nx typecheck lint for the API.

Security considerations

This closes an authenticated availability hole: someone with container.exec and an open session could bring the shared control plane down. Nothing about the message or the session's credentials is logged.

@coderabbitai

coderabbitai Bot commented Nov 25, 2026 •

Copy link
Copy Markdown

Warning

Review limit reached

You've used all free OSS reviews for now. Wait for the free limit to reset to keep reviewing this public repository.

Next included review available in 4 minutes.

Check out review usage here.

View limit details

Limit details: You’ve used the included review currently available.

Learn how review limits work.

Review configuration:

Run configuration

Commits

Reviewing files that changed from the base of the PR and between e6f4db4 and c3fce27.

Files ignored due to path filters: 1

  • apps/api/tsconfig.tsbuildinfo is excluded by !**/*.tsbuildinfo
Files selected for processing: 4

  • apps/api/src/modules/deployments/interface/exec-socket.dto.ts
  • apps/api/src/modules/deployments/interface/exec-socket.spec.ts
  • apps/api/src/modules/deployments/interface/exec-socket.ts
  • docs/SPEC.md
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

Share

@samuelmbabhazi

Copy link
Copy Markdown
Collaborator Author

@coderabbitai review

@coderabbitai

coderabbitai Bot commented Nov 25, 2026 •

Copy link
Copy Markdown
Action not completed

Review rate limited.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

… the shape check is what guards

Review of #481: the catch around the control-frame check hid any throw
from it, so the SPEC's failed end never happened and the tests passed
without the flat check. Only JSON parsing is caught now; the tests call
the check directly, join a second session on the same server, and cover
the failed end.

Signed-off-by: samuel mbabhazi <[email protected]>
@samuelmbabhazi

Copy link
Copy Markdown
Collaborator Author

Code review (high), three findings, all fixed in 2cc2663:

  1. The SPEC's failed end never happened. The try/catch in browserFrame wrapped controlFrame, so any throw from it was swallowed and the message dropped with no log. Now only JSON.parse is caught. A throw from the check reaches the message handler, which logs it and ends that session alone as failed. A new test makes fromBrowser throw: the browser gets {"type":"end","reason":"failed"} and a second session on the same server still joins.
  2. The tests did not guard the shape check. The tests now call controlFrame(JSON.parse(text)) directly. Checked by removing the flat checks: three tests fail, including the WebSocket one.
  3. The follow-up connection used a new server. It now joins a second session on the same server.

Exec socket tests: 14/14 pass. tsc and eslint are clean.

@samuelmbabhazi
samuelmbabhazi merged commit 92437e7 into main Nov 25, 2026
25 of 27 checks passed
@samuelmbabhazi
samuelmbabhazi deleted the fix/472-exec-control-frames branch November 25, 2026 13:19
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.

Prevent malformed exec WebSocket control frames from crashing the API

1 participant