File tree Expand file tree Collapse file tree 2 files changed +24
-6
lines changed
Expand file tree Collapse file tree 2 files changed +24
-6
lines changed Original file line number Diff line number Diff line change @@ -343,9 +343,18 @@ If you create your own with
343343If you are using Go 1.24 or above,
344344we recommend using [ ` crypto/rand.Text ` ] ( https://pkg.go.dev/crypto/rand#Text )
345345
346- - _ Binding session IDs to user information_ . This is an application requirement, out of scope
347- for the SDK. You can create your own session IDs by setting
348- [ ` ServerOptions.GetSessionID ` ] ( https://pkg.go.dev/github.com/modelcontextprotocol/go-sdk/mcp#ServerOptions.GetSessionID ) .
346+ - _ Binding session IDs to user information_ . The SDK supports this mitigation through
347+ [ ` TokenInfo.UserID ` ] ( https://pkg.go.dev/github.com/modelcontextprotocol/go-sdk/auth#TokenInfo.UserID ) .
348+ When a [ ` TokenVerifier ` ] ( https://pkg.go.dev/github.com/modelcontextprotocol/go-sdk/auth#TokenVerifier )
349+ sets ` UserID ` on the returned ` TokenInfo ` , the streamable transport will:
350+ 1 . Store the user ID when a new session is created.
351+ 2 . Verify that subsequent requests to that session include a token with the same ` UserID ` .
352+ 3 . Reject requests with a 403 Forbidden if the user ID doesn't match.
353+
354+ ** Recommendation** : If your ` TokenVerifier ` can extract a user identifier from the token
355+ (such as a ` sub ` claim in a JWT, or a user ID associated with an API key), set
356+ ` TokenInfo.UserID ` to enable this protection. This prevents an attacker with a valid
357+ token from hijacking another user's session by guessing or obtaining their session ID.
349358
350359## Utilities
351360
Original file line number Diff line number Diff line change @@ -269,9 +269,18 @@ If you create your own with
269269If you are using Go 1.24 or above,
270270we recommend using [ ` crypto/rand.Text ` ] ( https://pkg.go.dev/crypto/rand#Text )
271271
272- - _ Binding session IDs to user information_ . This is an application requirement, out of scope
273- for the SDK. You can create your own session IDs by setting
274- [ ` ServerOptions.GetSessionID ` ] ( https://pkg.go.dev/github.com/modelcontextprotocol/go-sdk/mcp#ServerOptions.GetSessionID ) .
272+ - _ Binding session IDs to user information_ . The SDK supports this mitigation through
273+ [ ` TokenInfo.UserID ` ] ( https://pkg.go.dev/github.com/modelcontextprotocol/go-sdk/auth#TokenInfo.UserID ) .
274+ When a [ ` TokenVerifier ` ] ( https://pkg.go.dev/github.com/modelcontextprotocol/go-sdk/auth#TokenVerifier )
275+ sets ` UserID ` on the returned ` TokenInfo ` , the streamable transport will:
276+ 1 . Store the user ID when a new session is created.
277+ 2 . Verify that subsequent requests to that session include a token with the same ` UserID ` .
278+ 3 . Reject requests with a 403 Forbidden if the user ID doesn't match.
279+
280+ ** Recommendation** : If your ` TokenVerifier ` can extract a user identifier from the token
281+ (such as a ` sub ` claim in a JWT, or a user ID associated with an API key), set
282+ ` TokenInfo.UserID ` to enable this protection. This prevents an attacker with a valid
283+ token from hijacking another user's session by guessing or obtaining their session ID.
275284
276285## Utilities
277286
You can’t perform that action at this time.
0 commit comments