mcp: reject requests with bad IDs (#202)
Add an isRequest field to methodInfo, used it to reject non-notification requests that lack a valid ID. Furthermore, lift this validation to the transport layer for HTTP server transports, so that we can preemptively reject bad HTTP requests. Fixes #194 Fixes #197
This commit is contained in:
parent
3ac4ca9c5b
commit
64493be392
1 changed files with 178 additions and 39 deletions
|
|
@ -129,6 +129,12 @@ func (t *SSEServerTransport) ServeHTTP(w http.ResponseWriter, req *http.Request)
|
|||
http.Error(w, "failed to parse body", http.StatusBadRequest)
|
||||
return
|
||||
}
|
||||
if req, ok := msg.(*jsonrpc.Request); ok {
|
||||
if _, err := checkRequest(req, serverMethodInfos); err != nil {
|
||||
http.Error(w, err.Error(), http.StatusBadRequest)
|
||||
return
|
||||
}
|
||||
}
|
||||
select {
|
||||
case t.incoming <- msg:
|
||||
w.WriteHeader(http.StatusAccepted)
|
||||
|
|
|
|||
Loading…
Reference in a new issue