Skip to content

Commit c52a9d8

Browse files
chore: create a section on session hijack
1 parent d095ba6 commit c52a9d8

File tree

1 file changed

+79
-0
lines changed

1 file changed

+79
-0
lines changed

docs/specification/draft/basic/security_best_practices.mdx

Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -139,3 +139,82 @@ Token passthrough is explicitly forbidden in the [authorization specification](/
139139
#### 2.2.2 Mitigation
140140

141141
MCP servers **MUST NOT** accept any tokens that were not explicitly issued for the MCP server.
142+
143+
### 2.3 Session Hijacking
144+
145+
#### 2.3.1 Session Highjack Prompt Injection
146+
147+
```mermaid
148+
sequenceDiagram
149+
participant Client
150+
participant ServerA
151+
participant Queue
152+
participant ServerB
153+
participant Attacker
154+
155+
Client->>ServerA: Initialize (connect to streamable HTTP server)
156+
ServerA-->>Client: Respond with session ID
157+
158+
Attacker->>ServerB: Access/guess session ID
159+
Note right of Attacker: Attacker knows/guesses session ID
160+
161+
Attacker->>ServerB: Trigger event (malicious payload, using session ID)
162+
ServerB->>Queue: Enqueue event (keyed by session ID)
163+
164+
ServerA->>Queue: Poll for events (using session ID)
165+
Queue-->>ServerA: Event data (malicious payload)
166+
167+
ServerA-->>Client: Async response (malicious payload)
168+
Client->>Client: Acts based on malicious payload
169+
```
170+
171+
#### 2.3.2 Session Highjack Impersonation
172+
173+
```mermaid
174+
sequenceDiagram
175+
participant Client
176+
participant Server
177+
participant Attacker
178+
179+
Client->>Server: Initialize (login/authenticate)
180+
Server-->>Client: Respond with session ID (persistent session created)
181+
182+
Attacker->>Server: Access/guess session ID
183+
Note right of Attacker: Attacker knows/guesses session ID
184+
185+
Attacker->>Server: Make API call (using session ID, no re-auth)
186+
Server-->>Attacker: Respond as if Attacker is Client (session hijack)
187+
```
188+
189+
#### 2.3.3 Attack Description
190+
191+
In horizontally scaled stateful streamable HTTP servers, the following are possible:
192+
193+
1. Session Highjack Prompt Injection
194+
1. The client connects to Server A and receives a session ID.
195+
2. The attacker guesses or accesses the session ID and sends a malicious event to Server B, using the session ID.
196+
3. Server B enqueues the event (keyed by session ID) into a shared queue.
197+
4. Server A polls the queue for events using the session ID and retrieves the malicious payload.
198+
5. Server A sends the malicious payload to the client as an asynchronous response.
199+
6. The client receives and acts on the malicious payload, potentially leading to compromise.
200+
2. Session Impersonation Hijack
201+
1. The client authenticates with the server, which creates a persistent session and returns a session ID.
202+
2. The attacker guesses or accesses the session ID.
203+
3. The attacker makes API calls to the server using the stolen session ID.
204+
4. The server does not re-authenticate the request and treats the attacker as the legitimate user, allowing unauthorized access or actions.
205+
206+
#### 2.3.4 Mitigation
207+
208+
To prevent session hijacking and event injection attacks, the following mitigations should be implemented:
209+
210+
HTTP servers **MUST** authenticate All Requests.
211+
Ensure that every request is authenticated. HTTP MCP Servers **MUST NOT** use sessions for authentication.
212+
213+
HTTP servers **MUST** use secure, unpredictable session IDs.
214+
Generate session IDs using secure random generators, such as cryptographically secure UUIDs. Avoid predictable or sequential session identifiers that could be guessed by an attacker.
215+
216+
HTTP servers **SHOULD** bind session keys to user-specific information.
217+
When storing or transmitting session-related data (e.g., in a queue), combine the session ID with information unique to the authenticated user, such as their internal user ID. For example, use a key format like `<user_id>:<session_id>`. This ensures that even if an attacker guesses a session ID, they cannot impersonate another user as the user ID is derived from authentication of the user token, and not provided by the client.
218+
219+
HTTP servers can optionally leverage additional unique identifiers.
220+
Consider incorporating other unique attributes, such as the source IP address, into the session key. This adds another layer of defense, making it more difficult for attackers to hijack sessions from different locations.

0 commit comments

Comments
 (0)