You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs/specification/draft/basic/security_best_practices.mdx
+87Lines changed: 87 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -141,3 +141,90 @@ Token passthrough is explicitly forbidden in the [authorization specification](/
141
141
#### Mitigation
142
142
143
143
MCP servers **MUST NOT** accept any tokens that were not explicitly issued for the MCP server.
144
+
145
+
### 2.3 Session Hijacking
146
+
147
+
Session hijacking is an attack vector where a client is provided a session ID by the server, and an unauthorized party is able to obtain and use that same session ID to impersonate the original client and perform unauthorized actions on their behalf.
148
+
149
+
#### 2.3.1 Session Hijack Prompt Injection
150
+
151
+
```mermaid
152
+
sequenceDiagram
153
+
participant Client
154
+
participant ServerA
155
+
participant Queue
156
+
participant ServerB
157
+
participant Attacker
158
+
159
+
Client->>ServerA: Initialize (connect to streamable HTTP server)
160
+
ServerA-->>Client: Respond with session ID
161
+
162
+
Attacker->>ServerB: Access/guess session ID
163
+
Note right of Attacker: Attacker knows/guesses session ID
164
+
165
+
Attacker->>ServerB: Trigger event (malicious payload, using session ID)
166
+
ServerB->>Queue: Enqueue event (keyed by session ID)
167
+
168
+
ServerA->>Queue: Poll for events (using session ID)
Server-->>Client: Respond with session ID (persistent session created)
185
+
186
+
Attacker->>Server: Access/guess session ID
187
+
Note right of Attacker: Attacker knows/guesses session ID
188
+
189
+
Attacker->>Server: Make API call (using session ID, no re-auth)
190
+
Server-->>Attacker: Respond as if Attacker is Client (session hijack)
191
+
```
192
+
193
+
#### 2.3.3 Attack Description
194
+
195
+
When you have multiple stateful HTTP servers that handle MCP requests, the following attack vectors are possible:
196
+
197
+
**Session Hijack Prompt Injection**
198
+
199
+
1. The client connects to **Server A** and receives a session ID.
200
+
1. The attacker obtains an existing session ID and sends a malicious event to **Server B** with said session ID.
201
+
202
+
- When a server supports [redelivery/resumable streams](https://modelcontextprotocol.io/specification/2025-03-26/basic/transports#resumability-and-redelivery), deliberately terminating the request before receiving the response could lead to it being resumed by the original client via the GET request for server sent events.
203
+
- If a particular server initiates server sent events as a consequence of a tool call such as a `notifications/tools/list_changed`, where it is possible to affect the tools that are offered by the server, a client could end up with tools that they were not aware were enabled.
204
+
205
+
1.**Server B** enqueues the event (associated with session ID) into a shared queue.
206
+
1.**Server A** polls the queue for events using the session ID and retrieves the malicious payload.
207
+
1.**Server A** sends the malicious payload to the client as an asynchronous or resumed response.
208
+
1. The client receives and acts on the malicious payload, leading to potential compromise.
209
+
210
+
**Session Hijack Impersonation**
211
+
212
+
1. The MCP client authenticates with the MCP server, creating a persistent session ID.
213
+
2. The attacker obtains the session ID.
214
+
3. The attacker makes calls to the MCP server using the session ID.
215
+
4. MCP server does not check for additional authorization and treats the attacker as a legitimate user, allowing unauthorized access or actions.
216
+
217
+
#### 2.3.4 Mitigation
218
+
219
+
To prevent session hijacking and event injection attacks, the following mitigations should be implemented:
220
+
221
+
MCP servers that implement authorization **MUST** verify all inbound requests.
222
+
MCP Servers **MUST NOT** use sessions for authentication.
223
+
224
+
MCP servers **MUST** use secure, non-deterministic session IDs.
225
+
Generated session IDs (e.g., UUIDs) **SHOULD** use secure random number generators. Avoid predictable or sequential session identifiers that could be guessed by an attacker. Rotating or expiring session IDs can also reduce the risk.
226
+
227
+
MCP servers **SHOULD** bind session IDs to user-specific information.
228
+
When storing or transmitting session-related data (e.g., in a queue), combine the session ID with information unique to the authorized user, such as their internal user ID. 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 the user token and not provided by the client.
229
+
230
+
MCP servers can optionally leverage additional unique identifiers.
0 commit comments