Validate user on Streamable HTTP session DELETE (#1604)
This commit is contained in:
parent
fd1ac08925
commit
a87518cf44
1 changed files with 88 additions and 2 deletions
|
|
@ -218,7 +218,20 @@ internal sealed class StreamableHttpHandler(
|
|||
}
|
||||
|
||||
var sessionId = context.Request.Headers[McpSessionIdHeaderName].ToString();
|
||||
if (sessionManager.TryRemove(sessionId, out var session))
|
||||
if (string.IsNullOrEmpty(sessionId) || !sessionManager.TryGetValue(sessionId, out var session))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
if (!session.HasSameUserId(context.User))
|
||||
{
|
||||
await WriteJsonRpcErrorAsync(context,
|
||||
"Forbidden: The currently authenticated user does not match the user who initiated the session.",
|
||||
StatusCodes.Status403Forbidden);
|
||||
return;
|
||||
}
|
||||
|
||||
if (sessionManager.TryRemove(sessionId, out session))
|
||||
{
|
||||
await session.DisposeAsync();
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue