CVE-2026–39987: Marimo Pre-Authentication Remote Code Execution
Marimo's /terminal/ws WebSocket endpoint lacked authentication, allowing an unauthenticated attacker to obtain an interactive terminal shell and execute arbitrary system commands. The vulnerability is tracked as CWE-306 with a CVSS score of 9.8.
medium.com
Published on medium.com
Cve 2026
The full write-up lives on its author's site
It belongs to its author, so we link to it rather than copy it. The other two tabs are our own rewrites, checked against it.
Context
CVE-2026-39987 is a pre-authentication remote code execution vulnerability in Marimo, an open-source reactive Python notebook platform aimed at developers, data scientists, researchers and machine-learning engineers. A notebook workflow in Marimo looks roughly like this:
Python Code ->Marimo Notebook -> Execute Python -> Analyze Data / ML / Visualization -> Interactive Results -> Optional Web Application
Notebooks can be served through a web interface, so teams can reach them remotely from a browser. That web-facing mode is what matters here: the Marimo server exposes HTTP and WebSocket endpoints to talk to the browser.
Marimo also ships an integrated terminal. A developer working in a notebook may need to inspect files, run commands or install dependencies in the underlying environment, so the server connects a browser session to a PTY (pseudo-terminal) on the host:
Browser | | WebSocket ↓ ┌─────────────────┐ │ Marimo Server │ └─────────────────┘ | ↓ Terminal / PTY | ↓ Operating System
The security question that follows is simple: what happens if the server does not verify who is connecting to that terminal? That is the problem behind CVE-2026-39987. The vulnerable endpoint is /terminal/ws, and the flaw is classified as CWE-306 (Missing Authentication for Critical Function), with a CVSS 3.1 score of 9.8 (Critical).
Setup
The testing was done manually in an authorised lab environment rather than with an existing exploitation framework. The researcher wrote a Python proof of concept using only standard libraries:
socketsslbase64structostimere
The script builds the whole stack itself: TCP, then TLS, then the WebSocket handshake, then frames. The flow the script implements is:
Python Script ↓TCP Connection ↓TLS Connection ↓WebSocket Handshake ↓/terminal/ws ↓WebSocket Frame ↓Terminal Input ↓Server Response ↓Frame Parsing ↓Output
No credentials, accounts or roles were needed, which is the whole point: the endpoint is supposed to sit behind authentication and did not enforce it.
Finding it
The observation is structural rather than subtle. The browser reaches the terminal through a WebSocket endpoint, and that WebSocket is a communication channel to a server-side terminal:
Browser ↓WebSocket ↓Marimo Server ↓Terminal / PTY ↓Operating System
A sensitive function like that must enforce authentication and authorisation. The intended flow is:
Client ↓/terminal/ws ↓Authentication ↓Authorization ↓Terminal
The flow that was actually reachable was:
Attacker ↓/terminal/ws ↓Missing Authentication ↓Terminal
The WebSocket protocol itself is not at fault. The problem is that a critical function was reachable through a WebSocket endpoint without the authentication boundary being enforced, and because that endpoint talks to a PTY, crossing the boundary means command execution on the host.
Exploitation
Step 1: open a TCP connection and wrap it in TLS
The script starts with a plain TCP connection to the target:
raw = socket.create_connection((TARGET_IP, 443), timeout=10)
Because the target serves HTTPS, the socket is then wrapped with TLS:
sock = context.wrap_socket(raw, server_hostname=HOST)
At this point there is a TLS-protected connection to the server, and the next layer to build is HTTP.
Step 2: perform the WebSocket handshake
A WebSocket connection begins life as an HTTP request that asks the server to upgrade the connection. The script generates a random value for Sec-WebSocket-Key:
key = base64.b64encode(os.urandom(16)).decode()
This value is part of the handshake protocol. It is not an authentication credential or a password, and it grants nothing on its own. The upgrade request is then written to the socket:
GET /terminal/ws HTTP/1.1Host: <target>Upgrade: websocketConnection: UpgradeSec-WebSocket-Key: <random-value>Sec-WebSocket-Version: 13Origin: https://<target>
The endpoint that matters is:
/terminal/ws
The request is sent directly through the socket and the script waits for the server's answer. If the response contains:
HTTP/1.1 101 Switching Protocols
the handshake has succeeded and the HTTP connection has been upgraded to a WebSocket. From that point both sides can exchange data continuously.

Step 3: build a client-to-server WebSocket frame
After the upgrade, data cannot be sent as raw text. It has to be placed inside a WebSocket frame. The script converts the test command into bytes:
data = (command + "\n").encode()
It then computes the payload length and creates a random 4-byte masking key:
length = len(data)mask = os.urandom(4)
The payload is masked with XOR against the key:
masked = bytes([ data[i] ^ mask[i % 4] for i in range(length)])
Conceptually:
Original Payload +4-byte Masking Key ↓ XOR ↓Masked Payload
Masking is mandatory for client-to-server frames in the WebSocket protocol, but it is not encryption. It is simply part of the WebSocket protocol.
Step 4: build the frame header and send
The frame header is packed with struct:
header = struct.pack("!BB", 0x81, 0x80 | length)
The first byte, 0x81, carries two fields:
FIN = 1Opcode = 1
FIN = 1 marks this as the final frame of the message, and Opcode = 1 marks it as a text frame. The second byte holds the payload length together with the MASK bit. The resulting frame on the wire looks like:
┌─────────────────────┐│ Frame Header │├─────────────────────┤│ 4-byte Mask │├─────────────────────┤│ Masked Payload │└─────────────────────┘
The complete frame is then written to the WebSocket connection.
Step 5: send test commands
For the lab reproduction the researcher used simple commands to verify the execution context:
commands = ["id", "whoami", "hostname"]
Each one answers a different question. id shows the identity and privileges of the process:
whoami shows the operating-system user running the process:
whoami
and hostname identifies the host:
hostname
They provide basic information about the process and host without performing destructive actions. The path the data takes is:
Python PoC ↓WebSocket Frame ↓/terminal/ws ↓Marimo Server ↓Terminal / PTY ↓Operating System ↓Command Output
Step 6: receive and parse the server's frames
Sending is only half of the exchange. The server replies in WebSocket frames too, so the PoC has a receive function that reads raw bytes from the socket:
chunk = sock.recv(4096)
It then reads the second byte of the frame header to work out the payload length:
second_byte = buffer[1]payload_len = second_byte & 0x7F
The script also handles extended payload lengths when the frame requires them. Once the full frame is available, the payload is sliced out:
payload = buffer[offset:offset + payload_len]
and decoded and printed as text. Because terminal applications can return ANSI escape sequences and other control characters, the script removes some of them to make the output easier to read. That cleaning step is not part of the vulnerability; it is just processing the terminal response.

Step 7: the full sequence
The whole proof of concept reduces to seven stages:
1. Connect ↓2. Establish TLS ↓3. Perform WebSocket Handshake ↓4. Construct WebSocket Frame ↓5. Send Data ↓6. Receive and Parse Response ↓7. Display Output
The key result from the lab was that the terminal WebSocket endpoint could be reached without the authentication barrier that should have protected it. That is the core issue behind CVE-2026-39987, and it is not a flaw in WebSockets themselves: a sensitive WebSocket endpoint was exposed without properly enforcing authentication.
Root cause
The mistake is a missing authentication check on the /terminal/ws WebSocket endpoint. The server should establish who the user is and then decide whether that user may reach the terminal; instead the endpoint handed the connection through to the PTY. Because the endpoint's purpose is to bridge a browser session to a shell on the host, skipping the identity check turns an unauthenticated HTTP upgrade request into an interactive terminal.
Why the existing boundary did not stop it is not described in the report beyond the missing check itself.
Impact
The impact depends on the privileges and environment in which Marimo is running. The general attack path is:
Unauthenticated Access ↓Terminal Access ↓Command Execution ↓Access Based on Marimo
The lab showed the terminal WebSocket endpoint could be reached without the authentication barrier. If Marimo runs with access to sensitive files, credentials, environment variables, internal services or other resources, those could potentially become accessible to the attacker. The security impact should therefore not be judged at the application level alone: the privileges of the underlying Marimo process matter just as much.
Fix
The most important mitigation is to upgrade Marimo to a fixed version. Beyond patching, administrators should consider the following controls:
- Upgrade Marimo to the fixed release or a later version.
- Avoid exposing Marimo directly to the public Internet unless required.
- Restrict access to trusted networks or users.
- Use appropriate authentication and authorisation controls at the application or reverse-proxy layer.
- Run Marimo with the least privileges necessary.
- Review logs for unexpected access to the
/terminal/wsendpoint. - Investigate exposed or potentially compromised instances.
- Rotate credentials or secrets if there is evidence that a vulnerable instance was compromised.
The aim is not only to protect the WebSocket endpoint. The whole deployment should be treated as a potentially sensitive system, because the terminal functionality can interact with the underlying operating system.
Variants to test
- Other WebSocket routes on the same product. Enumerate every
*/wspath the application exposes and attempt the upgrade without a session cookie. A positive result is a101 Switching Protocolsfollowed by data frames that reflect server-side state. - Terminal or shell endpoints behind a reverse proxy. Send the upgrade request directly to the backend port, bypassing proxy rules that only cover HTTP paths. A positive result is a working PTY session where the proxy should have blocked it.
- Authentication enforced on HTTP but not on upgrade. Compare an unauthenticated
GETto the notebook page (expect a redirect or 401/403) with an unauthenticated upgrade to the same route's WebSocket sibling. A positive result is a rejection on the first and a101on the second. - Origin checking. Repeat the handshake with an
Originheader pointing at an unrelated site. A positive result is that the server still upgrades, which would also make cross-site WebSocket hijacking feasible if a victim's browser is used. - Privilege of the service account. Once a shell is obtained in a lab, run
idandwhoamito record the process identity. A positive result is a non-restricted user with read access to configuration, environment variables or credentials. - Log review for prior exposure. Search access logs for upgrade requests to the terminal endpoint from unexpected sources. A positive result is
101responses to clients that never authenticated.
What happened, in plain words
A piece of software called Marimo had a serious security hole. Marimo is a tool that lets people write and run Python code in a notebook, a bit like a digital exercise book where each page can run code and show results. Teams can put their notebooks on a web server so colleagues can open them in a browser.
Marimo also includes a built-in terminal. A terminal is the plain text window where you type commands and the computer runs them. It is a powerful thing to have, because commands typed there run directly on the machine that hosts Marimo.
The hole was that the part of Marimo that serves this terminal over the web did not check who was connecting. The part of Marimo that serves this terminal over the web did not check who was connecting, so the terminal could be reached without a username, password or account. Security people call this kind of flaw a pre-authentication remote code execution: pre-authentication because it happens before any login, remote because it is done over a network, and code execution because the attacker can make the server run their own commands.
The flaw is tracked as CVE-2026-39987. A CVE is a public catalogue number given to a known security problem so everyone can refer to the same thing. It is classified as CWE-306, Missing Authentication for Critical Function, which is a formal way of saying: an important feature was left without a login check. It has a CVSS 3.1 score of 9.8, marked Critical. CVSS is a standard scoring system for how bad a security flaw is, from 0 to 10, and 9.8 is near the top.
What Marimo is
Marimo is an open-source reactive Python notebook. Open source means the code is public and anyone can use or inspect it. Marimo is described as a reactive Python notebook with a strong focus on reactive execution.
It is built for developers, data scientists, researchers and machine-learning engineers. A typical workflow looks like this:
Python Code ->Marimo Notebook -> Execute Python -> Analyze Data / ML / Visualization -> Interactive Results -> Optional Web Application
Read that left to right: you write Python code, put it in a Marimo notebook, run it, use the result to analyse data or build charts and machine-learning models, get interactive results, and optionally turn the whole thing into a small web application.
Notebooks can be served through a web interface, so a team can reach them remotely from a browser instead of everyone installing the software locally. That web mode is the part that matters here. To talk to the browser, the Marimo server exposes HTTP and WebSocket endpoints.
An endpoint is simply a specific address on a server that accepts a particular kind of request, like a service counter in a building: each counter does one job, and you have to go to the right one. HTTP is the ordinary language browsers and servers use to exchange pages and data. WebSocket is a related technology we will explain shortly.
Why Marimo has a terminal at all
Marimo is not just showing Python code on a screen. Someone working in a notebook often needs to interact with the machine underneath: look at files, run commands, install extra software packages, or do other development chores.
So Marimo ships an integrated terminal. The architecture looks like this:
Browser | | WebSocket ↓ ┌─────────────────┐ │ Marimo Server │ └─────────────────┘ | ↓ Terminal / PTY | ↓ Operating System
In words: the browser talks to the Marimo server over a WebSocket, the server connects that session to a PTY on the host, and the PTY is connected to the operating system. A PTY, or pseudo-terminal, is the software version of a physical terminal: it is the channel through which typed commands reach the operating system and output comes back.
A legitimate, logged-in user can therefore use a terminal through their browser. That is a convenient feature. It is also a very sensitive one, because anything that reaches the operating system can do whatever the Marimo process is allowed to do.
The security question that follows is simple: what happens if the server does not verify who is connecting to that terminal? That is exactly the problem behind CVE-2026-39987. The vulnerable endpoint is /terminal/ws, and the flaw is classified as CWE-306 (Missing Authentication for Critical Function), with a CVSS 3.1 score of 9.8 (Critical).
What a WebSocket is
Before going further we need WebSockets, because Marimo's terminal communicates through one.
A WebSocket lets a client and a server keep a persistent, two-way connection open. Compare the two technologies:
| Type | How it works | Example |
|---|---|---|
| HTTP | Request, response, connection ends | Opening a webpage |
| WebSocket | Connect once, keep communicating | Chat, games, terminals |
A useful everyday comparison: HTTP is like sending text messages, where you send one and get a reply. A WebSocket is like a phone call: once the line is open, both sides can keep talking without redialling.
How a WebSocket connection starts
A WebSocket connection begins life as an ordinary HTTP request. The client asks the server to upgrade the connection:
GET /terminal/ws HTTP/1.1Host: example.comUpgrade: websocketConnection: UpgradeSec-WebSocket-Key: random-valueSec-WebSocket-Version: 13
Line by line:
GET /terminal/ws HTTP/1.1is the request line.GETis the method, meaning "give me this"./terminal/wsis the path being asked for, the terminal endpoint.HTTP/1.1is the version of the protocol.Host: example.comsays which website or server the request is aimed at. One server can host many names, so this tells it which one you want.Upgrade: websocketis the actual request to switch protocols: we would like to stop speaking HTTP and start speaking WebSocket.Connection: Upgradetells the server that this connection is meant to be upgraded, not kept as a normal HTTP connection.Sec-WebSocket-Key: random-valueis a random value the client makes up for this handshake. It is part of the protocol, not a password.Sec-WebSocket-Version: 13states which version of the WebSocket protocol is being used.
If the server accepts, it answers:
HTTP/1.1 101 Switching ProtocolsUpgrade: websocketConnection: Upgrade
HTTP/1.1 101 Switching Protocolsis the status line.101is a special code meaning the server agrees to switch protocols.Upgrade: websocketandConnection: Upgradeconfirm what the connection is being switched to.
The 101 Switching Protocols response means the HTTP connection has now been upgraded to a WebSocket connection. From this point, both sides can continuously exchange data:
Client ←────────────────→ Server WebSocket Connection
How data is sent
After the upgrade, WebSocket uses frames to transfer data rather than normal HTTP requests. A frame is a small package with a header and a payload. A simplified frame looks like:
┌──────────────────┐│ Frame Header │├──────────────────┤│ Masking Key │├──────────────────┤│ Payload / Data │└──────────────────┘
The payload contains the actual message. For client-to-server communication, the payload is masked using a 4-byte masking key, as required by the WebSocket protocol. Masking means scrambling the bytes with a key so they look different on the wire. It is not encryption: anyone who knows the key can undo it, and the key travels with the frame. It is simply part of the WebSocket protocol.
Why this matters for CVE-2026-39987
In Marimo, the browser communicates with the terminal through a WebSocket endpoint:
Browser ↓WebSocket ↓Marimo Server ↓Terminal / PTY ↓Operating System
So the WebSocket is a communication channel to a server-side terminal. A sensitive function like that must enforce authentication and authorisation. Authentication means proving who you are, like showing a passport at a border. Authorisation means deciding what you are allowed to do once you are known, like a passport not granting you the right to enter every room.
The intended flow is:
Client ↓/terminal/ws ↓Authentication ↓Authorization ↓Terminal
In words: the client asks for the terminal endpoint, the server first works out who the user is, then checks whether that user may use the terminal, and only then hands over the terminal.
The flow that was actually reachable was:
Attacker ↓/terminal/ws ↓Missing Authentication ↓Terminal
In words: the attacker asks for the terminal endpoint and is taken straight to the terminal, with no identity check in between.
The WebSocket protocol itself is not at fault. The problem is that a critical function was reachable through a WebSocket endpoint without the authentication boundary being enforced, and because that endpoint talks to a PTY, crossing the boundary means command execution on the host.
Building a proof of concept in Python
After understanding the root cause, the researcher wanted to reproduce the vulnerability manually in an authorised lab environment rather than relying on an existing exploitation framework. A lab environment is a test setup the researcher controls and is allowed to attack. A proof of concept, or PoC, is a small script that demonstrates a flaw really exists, without doing harm.
The script was written in Python using only standard libraries:
socketsslbase64structostimere
These are the names of built-in Python modules, run together in the report's diagram. Each one provides a tool:
socketopens network connections.ssladds TLS, the encryption layer behind HTTPS.base64encodes binary data as text.structpacks numbers into exact byte layouts.osprovides random bytes and other operating-system helpers.timehandles pauses and timing.rehandles pattern matching in text.
The script had to build the whole stack itself: TCP, then TLS, then the WebSocket handshake, then frames. A port is a numbered door on a server; 443 is the standard door for HTTPS. TCP is the basic reliable connection layer underneath, TLS is the encryption wrapped around it, and HTTPS is HTTP carried inside TLS.
The flow the script implements is:
Python Script ↓TCP Connection ↓TLS Connection ↓WebSocket Handshake ↓/terminal/ws ↓WebSocket Frame ↓Terminal Input ↓Server Response ↓Frame Parsing ↓Output
Read top to bottom: the script opens a TCP connection, secures it with TLS, performs the WebSocket handshake, reaches /terminal/ws, sends a WebSocket frame containing terminal input, receives the server's response, parses the frames, and displays the output.
No credentials, accounts or roles were needed, which is the whole point: the endpoint is supposed to sit behind authentication and did not enforce it.
Step 1: open a TCP connection and wrap it in TLS
The script starts with a plain TCP connection to the target:
raw = socket.create_connection((TARGET_IP, 443), timeout=10)
Line by line:
socket.create_connectionasks Python's socket module to open a network connection.(TARGET_IP, 443)is the address to connect to: the target's IP address and port 443, the HTTPS door.timeout=10means give up after ten seconds rather than waiting forever.raw =stores the resulting connection in a variable calledraw.
Because the target serves HTTPS, the socket is then wrapped with TLS:
sock = context.wrap_socket(raw, server_hostname=HOST)
Line by line:
context.wrap_sockettakes the plain connection and layers TLS encryption on top of it.rawis the connection from the previous line.server_hostname=HOSTtells TLS which hostname is being contacted, so the server can present the right certificate and the client can check it.sock =stores the encrypted connection for later use.
At this point there is a TLS-protected connection to the server, and the next layer to build is HTTP.
Step 2: perform the WebSocket handshake
A WebSocket connection begins life as an HTTP request that asks the server to upgrade the connection. The script generates a random value for Sec-WebSocket-Key:
key = base64.b64encode(os.urandom(16)).decode()
Line by line:
os.urandom(16)produces 16 random bytes.base64.b64encode(...)turns those bytes into plain text characters, because headers can only carry text..decode()converts the result into an ordinary Python string.key =stores it.
This value is part of the handshake protocol. It is not an authentication credential or a password, and it grants nothing on its own. The upgrade request is then written to the socket:
GET /terminal/ws HTTP/1.1Host: <target>Upgrade: websocketConnection: UpgradeSec-WebSocket-Key: <random-value>Sec-WebSocket-Version: 13Origin: https://<target>
Line by line:
GET /terminal/ws HTTP/1.1asks for the terminal endpoint using HTTP version 1.1.Host: <target>names the server being contacted.Upgrade: websocketandConnection: Upgraderequest the protocol switch.Sec-WebSocket-Key: <random-value>carries the random value generated above.Sec-WebSocket-Version: 13states the WebSocket protocol version.Origin: https://<target>tells the server which site the request claims to come from. Browsers set this automatically; a script can set it to anything.
The endpoint that matters is:
/terminal/ws
The request is sent directly through the socket and the script waits for the server's answer. If the response contains:
HTTP/1.1 101 Switching Protocols
the handshake has succeeded and the HTTP connection has been upgraded to a WebSocket. From that point both sides can exchange data continuously.

Step 3: build a client-to-server WebSocket frame
After the upgrade, data cannot be sent as raw text. It has to be placed inside a WebSocket frame. The script converts the test command into bytes:
data = (command + "\n").encode()
Line by line:
commandis the text of the command to run.+ "\n"adds a newline character at the end, which is what pressing Enter does in a terminal. Without it the terminal would sit waiting for the rest of the line..encode()converts the text into bytes, because the network carries bytes, not text.data =stores the result.
It then computes the payload length and creates a random 4-byte masking key:
length = len(data)mask = os.urandom(4)
Line by line:
len(data)counts how many bytes the payload has.mask = os.urandom(4)creates four random bytes to use as the masking key.
The payload is masked with XOR against the key:
masked = bytes([ data[i] ^ mask[i % 4] for i in range(length)])
Line by line:
for i in range(length)walks through every byte position of the payload.data[i]is the byte at that position.mask[i % 4]picks one of the four mask bytes, cycling through them over and over. The%operator gives the remainder of a division, so the index wraps around 0, 1, 2, 3, 0, 1 and so on.^is XOR, a bit operation that combines the two bytes. Applying the same XOR again with the same key reverses it, which is why it is easy to undo.bytes([...])collects the results back into a byte sequence.masked =stores the scrambled payload.
Conceptually:
Original Payload +4-byte Masking Key ↓ XOR ↓Masked Payload
Masking is mandatory for client-to-server frames in the WebSocket protocol, but it is not encryption. It exists to make protocol behaviour predictable for intermediaries, nothing more.
Step 4: build the frame header and send
The frame header is packed with struct:
header = struct.pack("!BB", 0x81, 0x80 | length)
Line by line:
struct.packbuilds a sequence of bytes from values according to a format."!BB"is the format:!means network byte order, the agreed order for sending numbers over a network, andBBmeans two unsigned one-byte values.0x81is the first byte. In hexadecimal,0x81is 129.0x80 | lengthis the second byte.|is bitwise OR, which sets the top bit of the byte to 1 and leaves the rest as the length. That top bit is the MASK flag, telling the server the payload is masked.header =stores the two bytes.
The first byte, 0x81, carries two fields:
FIN = 1Opcode = 1
FIN = 1marks this as the final frame of the message.Opcode = 1marks it as a text frame, as opposed to binary data or a control message.
The second byte holds the payload length together with the MASK bit. The resulting frame on the wire looks like:
┌─────────────────────┐│ Frame Header │├─────────────────────┤│ 4-byte Mask │├─────────────────────┤│ Masked Payload │└─────────────────────┘
The complete frame is then written to the WebSocket connection.
Step 5: send test commands
For the lab reproduction the researcher used simple commands to verify the execution context:
commands = ["id", "whoami", "hostname"]
Line by line:
commands =is a list of three command strings."id"asks the system to print the current user's identity and group memberships."whoami"asks which user account is running the process."hostname"asks for the machine's name.
Each one answers a different question. id shows the identity and privileges of the process:
whoami shows the operating-system user running the process:
whoami
and hostname identifies the host:
hostname
They provide basic information about the process and host without performing destructive actions. The path the data takes is:
Python PoC ↓WebSocket Frame ↓/terminal/ws ↓Marimo Server ↓Terminal / PTY ↓Operating System ↓Command Output
In words: the Python script puts the command in a WebSocket frame, sends it to /terminal/ws, the Marimo server passes it to the PTY, the operating system runs it, and the output comes back the same way.
Step 6: receive and parse the server's frames
Sending is only half of the exchange. The server replies in WebSocket frames too, so the PoC has a receive function that reads raw bytes from the socket:
chunk = sock.recv(4096)
Line by line:
sock.recv(4096)reads up to 4096 bytes that have arrived on the connection. It returns whatever is available, which may be less than a full frame.chunk =stores those bytes.
It then reads the second byte of the frame header to work out the payload length:
second_byte = buffer[1]payload_len = second_byte & 0x7F
Line by line:
buffer[1]takes the second byte of the received data, counting from zero. That byte holds the length information.second_byte & 0x7Fuses bitwise AND with0x7F, which is 127 in decimal, to keep only the bottom seven bits. The top bit is the MASK flag, which the server does not set, so this strips it and leaves the length.payload_len =stores the resulting length.
The script also handles extended payload lengths when the frame requires them. Once the full frame is available, the payload is sliced out:
payload = buffer[offset:offset + payload_len]
Line by line:
offsetis where the payload starts in the buffer, after the header and any mask.offset + payload_lenis where it ends.buffer[offset:offset + payload_len]takes that slice of bytes.payload =stores it.
and decoded and printed as text. Because terminal applications can return ANSI escape sequences and other control characters, the script removes some of them to make the output easier to read. ANSI escape sequences are invisible instructions that tell a terminal to change colour or move the cursor; they look like gibberish in plain text. That cleaning step is not part of the vulnerability; it is just processing the terminal response.

Step 7: the full sequence
The whole proof of concept reduces to seven stages:
1. Connect ↓2. Establish TLS ↓3. Perform WebSocket Handshake ↓4. Construct WebSocket Frame ↓5. Send Data ↓6. Receive and Parse Response ↓7. Display Output
In words: connect to the server, secure the connection, upgrade it to a WebSocket, build a frame, send the command, read and parse the reply, and show the output.
The key result from the lab was that the terminal WebSocket endpoint could be reached without the authentication barrier that should have protected it. That is the core issue behind CVE-2026-39987, and it is not a flaw in WebSockets themselves: a sensitive WebSocket endpoint was exposed without properly enforcing authentication.
Root cause
The mistake is a missing authentication check on the /terminal/ws WebSocket endpoint. The server should establish who the user is and then decide whether that user may reach the terminal; instead the endpoint handed the connection through to the PTY. Because the endpoint's purpose is to bridge a browser session to a shell on the host, skipping the identity check turns an unauthenticated HTTP upgrade request into an interactive terminal.
Why the existing boundary did not stop it is not described in the report beyond the missing check itself.
Impact
The impact depends on the privileges and environment in which Marimo is running. The general attack path is:
Unauthenticated Access ↓Terminal Access ↓Command Execution ↓Access Based on Marimo
In words: someone with no account gets in, reaches the terminal, runs commands, and gains whatever access the Marimo process itself has.
The lab showed the terminal WebSocket endpoint could be reached without the authentication barrier. A shell here means a live command prompt on the server, where each command is answered immediately. If Marimo runs with access to sensitive files, credentials, environment variables, internal services or other resources, those could potentially become accessible to the attacker. The security impact should therefore not be judged at the application level alone: the privileges of the underlying Marimo process matter just as much.
Fix
The most important mitigation is to upgrade Marimo to a fixed version. Beyond patching, administrators should consider the following controls:
- Upgrade Marimo to the fixed release or a later version.
- Avoid exposing Marimo directly to the public Internet unless required.
- Restrict access to trusted networks or users.
- Use appropriate authentication and authorisation controls at the application or reverse-proxy layer.
- Run Marimo with the least privileges necessary.
- Review logs for unexpected access to the
/terminal/wsendpoint. - Investigate exposed or potentially compromised instances.
- Rotate credentials or secrets if there is evidence that a vulnerable instance was compromised.
A reverse proxy is a server that sits in front of the real application and forwards requests to it, like a receptionist who decides who gets through to the office. Running with least privileges means giving the software only the permissions it actually needs, so a compromise does less damage. Rotating credentials means replacing passwords and keys with new ones, in case the old ones leaked.
The aim is not only to protect the WebSocket endpoint. The whole deployment should be treated as a potentially sensitive system, because the terminal functionality can interact with the underlying operating system.
Variants to test
- Other WebSocket routes on the same product. Enumerate every
*/wspath the application exposes and attempt the upgrade without a session cookie. A positive result is a101 Switching Protocolsfollowed by data frames that reflect server-side state. A session cookie is a small piece of data the browser stores after you log in, so the server can recognise you on later requests; trying without one tests whether the check is really there. - Terminal or shell endpoints behind a reverse proxy. Send the upgrade request directly to the backend port, bypassing proxy rules that only cover HTTP paths. A positive result is a working PTY session where the proxy should have blocked it.
- Authentication enforced on HTTP but not on upgrade. Compare an unauthenticated
GETto the notebook page (expect a redirect or 401/403) with an unauthenticated upgrade to the same route's WebSocket sibling. A positive result is a rejection on the first and a101on the second. Status codes 401 and 403 mean "not logged in" and "not allowed" respectively. - Origin checking. Repeat the handshake with an
Originheader pointing at an unrelated site. A positive result is that the server still upgrades, which would also make cross-site WebSocket hijacking feasible if a victim's browser is used. Cross-site WebSocket hijacking is when a malicious site uses a logged-in visitor's browser to open a WebSocket to another site on their behalf. - Privilege of the service account. Once a shell is obtained in a lab, run
idandwhoamito record the process identity. A positive result is a non-restricted user with read access to configuration, environment variables or credentials. - Log review for prior exposure. Search access logs for upgrade requests to the terminal endpoint from unexpected sources. A positive result is
101responses to clients that never authenticated.
Glossary
- ANSI escape sequence: an invisible instruction in terminal output that changes colour or moves the cursor.
- Authentication: proving who you are, like showing a passport.
- Authorisation: deciding what a known user is allowed to do.
- Base64: a way of writing binary data using ordinary text characters.
- Bitwise AND / OR / XOR: operations that combine individual bits of numbers; XOR with the same key twice restores the original.
- CVE: a public catalogue number for a known security vulnerability.
- CVSS: a standard 0 to 10 score for the severity of a vulnerability.
- CWE-306: the classification "Missing Authentication for Critical Function".
- Endpoint: a specific address on a server that accepts a particular kind of request.
- Frame: a small package of data with a header and a payload, used by WebSocket.
- HTTP: the ordinary request-and-response language of the web.
- HTTPS: HTTP carried inside TLS encryption.
- Least privileges: giving software only the permissions it actually needs.
- Masking: scrambling WebSocket payload bytes with a key; not encryption.
- Notebook: an interactive document that mixes code, output and notes.
- Open source: software whose code is public and can be used and inspected by anyone.
- Origin header: a header telling the server which site a request claims to come from.
- Payload: the actual data carried inside a frame or request.
- Port: a numbered door on a server; 443 is the standard HTTPS port.
- Pre-authentication: happening before any login check.
- Proof of concept (PoC): a small script that demonstrates a flaw really exists.
- PTY (pseudo-terminal): the software version of a terminal, connecting commands to the operating system.
- Reactive: recalculating dependent parts automatically when one part changes.
- Remote code execution (RCE): making a remote server run commands chosen by an attacker.
- Reverse proxy: a server in front of an application that forwards requests to it.
- Rotate credentials: replace passwords and keys with new ones.
- Session cookie: a small piece of data stored by the browser after login so the server recognises you.
- Shell: a live command prompt on a server.
- Status code 101: the HTTP answer meaning the connection is being switched to another protocol.
- Status codes 401 / 403: "not logged in" and "not allowed".
- TCP: the basic reliable connection layer underneath network traffic.
- Terminal: the plain text window where you type commands and the computer runs them.
- TLS: the encryption layer that secures connections such as HTTPS.
- WebSocket: a persistent two-way connection between client and server, like a phone call.
- WebSocket handshake: the initial HTTP request and response that upgrades a connection to WebSocket.