Erlang/OTP SSH Server CVE Fix
When to Use
- Fix Erlang/OTP SSH server remote code execution vulnerability
- Investigate which SSH message type causes the attack
- Patch source code to block unauthorized commands
Input
- Source code at
/app/workspace/otp_src_27.3.2/ - Affected version: Erlang/OTP SSH server
Vulnerability
Crafted SSH protocol messages allow:
- Arbitrary system command execution
- No authentication required
Fix Requirements
- Investigate which SSH message causes the attack
- Fix the bug in source code
- Server should maintain normal SSH behavior
- Block unauthorized message types
- Produce an actual source-code patch in the provided Erlang files; do not stop at analysis or a written report
- Verify the full exploit path from unauthenticated input to command execution before patching
- Keep the fix as narrow as the demonstrated vulnerable message/state combination while preserving normal authenticated SSH behavior
- Inspect edited Erlang control flow for syntax, clause ordering, fallback behavior, and return-shape consistency before finishing
Approach
- Trace the exploit path end-to-end before editing: identify the incoming SSH message type, follow decode/dispatch through the current connection state, queueing if any, and confirm exactly where unauthenticated handling reaches the sensitive operation
- Read the exact dispatch and handler branches you plan to modify before naming the vulnerable message or exploit mechanism; treat exploit chains as hypotheses until you inspect the downstream handler that performs the sensitive action
- Confirm the exact message and state combination that reaches command execution before choosing a fix
- If a file read is truncated or incomplete, continue reading until the full relevant function body, clauses, and called functions are visible
- Patch the minimal validated guard point in source code, typically by rejecting or deferring unauthorized message types until the connection is in the correct authenticated/connected state
- Prefer the narrowest evidence-backed enforcement point over broad repetitive blocking across many message types, and avoid unnecessary state-machine refactors when a local handler fix is sufficient
- Keep the result implementation-focused: investigation is intermediate work, not the deliverable
- No need to build or start server
- First, obey any task-specific execution/interface requirements exactly (for example mandated action formats, allowed tool names, JSON schemas, or exact completion tokens); do not substitute a different workflow
- Keep diagnosis claims provisional until you have read the full relevant handler/control-flow region and confirmed the unauthenticated path in code
- Do not commit to a root cause from search hits, isolated
ssh_connection:handle_msg/...clauses, partial snippets, or dangerous sink handlers alone; read the full relevant decode/dispatch or state-machine branch and the downstream server-side handler that performs the sensitive action before naming the vulnerable message/state pair - Trace from unauthenticated parser/state-machine entry through receive/decode, any event wrapping such as
{conn_msg, Msg}, queueing/deferred handling, dispatch, fallback, and into the exact privileged handler you plan to patch; do not treat packet decoding, internal wrapping, or postponement as proof of an auth bypass - Inspect the earliest shared connection/FSM dispatch boundary that admits the validated message path before patching individual
exec/shell/subsystem or other leaf handlers; check bothssh_connection_handler.erlandssh_connection.erl, plus any state-specific forwarding code, to prove whether pre-auth states delegate into generic privileged message handling - If your investigation produces conflicting conclusions, stop and resolve them by reading the specific dispatch, deferred-queue, fallback, channel-setup, and later handler code that distinguishes those cases before editing
- For channel-related hypotheses such as
SSH_MSG_CHANNEL_REQUEST/"exec", also verify prerequisites: whether unauthenticated code can create or reference the needed channel, how channel open and channel lookup/cache behave before authentication, and whether the request is rejected earlier for missing state - Before any structural edit to an Erlang handler or multi-clause function, read the entire target function/clause body plus enough surrounding clauses to see boundaries, guards, helper usage, fallthrough/default behavior, and module context; if output is truncated, continue reading until the whole region is visible
- Do not replace a critical clause from a partial glimpse such as only a function head,
case, or a few body lines; use precise observed edit anchors from the verified file path only after the exact existing text and boundaries are known - Patch only the validated message/state combination unless additional message types or a broader dispatcher path were separately traced end-to-end and shown to require changes while preserving normal SSH behavior
- When evidence shows a common pre-auth dispatch layer admits the exploit path and fans out to multiple downstream handlers, prefer the earliest validated shared dispatcher/state guard over scattered sink-level checks; otherwise keep the later narrower guard
- Reuse existing OTP authentication/connection-state predicates, macros, and nearby helpers instead of inventing parallel auth tracking, and verify the exact pre-auth versus post-auth state variants and transitions involved rather than relying on broad state names
- If a message is valid later in the session but unsafe before authentication, use postponement only when code shows the state machine actually drains that postponed message after the intended authenticated/connected transition; otherwise reject it at the validated guard point before any side-effecting handler runs
- When rejecting an unauthorized channel-style request, preserve existing protocol reply semantics: send the normal failure response only when the request expects a reply, otherwise reject/ignore without inventing a new response path
- Once the vulnerable guard point is confirmed, make an actual
.erlsource edit in the repository and then read back the modified region before describing the patch as applied
Tips
- Look at SSH message type handling in Erlang/OTP source
- Check for missing authentication checks
- Use git diff to verify changes
- Do not infer the vulnerability from isolated
ssh_connection:handle_msg/...clauses alone; verify how the surrounding state-machine code actually delivers those messages before authentication - Treat finding an
"exec"or similar dangerous handler as a lead, not proof of exploitability; verify earlier channel, state, and authentication requirements first - Distinguish reception/decoding or deferred handling of SSH messages from later authenticated processing; postponed or queued messages are not rejected and are not themselves proof of a vulnerability
- Prefer targeted guards on the evidenced message type or prerequisite state transition over broad protocol gating; when multiple downstream handlers share the same unsafe pre-auth entry path, a dispatcher-level connected/authenticated-state check is often the narrowest correct fix
- After identifying the bug, immediately edit the relevant
.erlfile; do not finish with only a vulnerability explanation - Before broadening a fix from one message type to many or patching a broad dispatcher, inspect accepted states, transition behavior, unmatched-message fallthrough, and later handling so normal SSH flows still work after the change
- Before finishing, confirm there is a concrete diff in the source tree
- Verify the forwarding path from state-specific handling into shared connection-message dispatch in
ssh_connection_handler.erl/ssh_connection.erlbefore editing leaf request handlers - If connection-protocol messages are wrapped, queued, or forwarded as a common work-item type before auth, inspect that admission point first; it is often the narrowest safe fix location
- If you suspect an unauthenticated channel-request exploit, inspect both the request handler and the code that establishes/looks up channels before auth; prove that the request can reach the dangerous branch with the required channel context
- Avoid introducing new helper functions or moving clauses unless necessary for the narrow fix; if you do, read back the full enclosing function and adjacent declarations after editing to confirm valid Erlang structure
- Do not assume similarly named states are equivalent for security decisions; read the concrete state values/tuples and confirm which ones occur before authentication versus after authentication or rekey
Final Check
- Confirm the patch blocks the identified unauthorized message path, not a guessed broader class of messages
- Confirm the complete modified region was read back in full after the final edit
- Confirm modified Erlang functions have valid clause grouping, guards, return shapes, fallback behavior, and terminators after the edit
- Use
git diffplus a surrounding code read to ensure the patch is coherent, narrowly scoped, and preserves normal SSH behavior outside the validated exploit path
Final Check
Final Check
- Confirm the patch blocks the identified unauthorized message path, not a guessed broader class of messages
- Confirm the chosen guard point lies on the real unauthenticated dispatch path, runs before any side-effecting handler is invoked, and that any existing authentication flag/state reused by the patch is set on normal successful login flow
- Confirm the named vulnerability root cause is backed by a verified end-to-end reachability trace from unauthenticated input through decode/dispatch/state handling, including any queueing or deferred handling, to the sensitive operation
- Confirm the chosen fix point is the earliest shared dispatch/state gate actually reached by the exploit when evidence shows multiple downstream handlers fan out from that path; if you instead patched later, verify that narrower guard is required and sufficient
- Confirm every modified message type or path was individually evidenced; avoid or revert speculative edits to adjacent handlers, broad protocol ranges, or generic pre-auth behavior that were not part of the demonstrated exploit path
- Confirm the final behavior for the unauthorized message is terminal for that pre-auth input unless postponement was explicitly validated from code: it must not be accidentally preserved, rerouted through fallback behavior, or replayed into the sensitive handler after authentication
- If you used postponement/deferal, confirm the message type is valid after the intended authenticated/connected transition, the postponed path is actually drained, and the return shape matches neighboring clauses
- Confirm the fix uses an existing source of truth for authentication/connection state and established local guard conventions where available, while still permitting legitimate post-authentication or transitional handling visible in adjacent code
- Confirm unauthorized requests now fail with protocol-consistent behavior while authenticated or otherwise valid connected-session handling remains on the original path
- Confirm at least one Erlang source file in
/app/workspace/otp_src_27.3.2was actually modified andgit diffshows the intended concrete patch hunk in the intended file path; if there is no diff, the task is not complete - Re-read the full edited function or clause group, including neighboring clauses, helper placement, delimiters, clause ordering, fallback/default branches, and surrounding module context; if output is truncated, continue until the whole modified region is visible
- Verify clause order, variable binding, matching, guard structure, separators,
end/terminator placement, helper-function placement, disconnect reason construction, return tuple shape, and surrounding fallthrough/fallback behavior are intact after the edit - Re-read your investigation notes for contradictions; if you have both "already gated by authenticated/connected state" and "unauthenticated path reaches command execution," do not finalize until one is disproven from code
- Confirm every tool/action used matched any explicitly required execution protocol, and if the task specifies an exact completion token or final-output format, emit it verbatim as the last line