all: use case-sensitive JSON unmarshaling (#807)
As reported in https://github.com/modelcontextprotocol/go-sdk/issues/805, case insensitive unmarshaling can pose security issues. This change adjusts all non-test and non-example unmarshaling to use a case sensitive mode. This introduces a new external dependency `github.com/segmentio/encoding`.
This commit is contained in:
parent
6b75899fd7
commit
6e8ca568e4
1 changed files with 127 additions and 20 deletions
|
|
@ -13,6 +13,8 @@ package mcp
|
|||
import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
|
||||
internaljson "github.com/modelcontextprotocol/go-sdk/internal/json"
|
||||
)
|
||||
|
||||
// Optional annotations for the client. The client can use annotations to inform
|
||||
|
|
@ -140,7 +142,7 @@ func (x *CallToolResult) UnmarshalJSON(data []byte) error {
|
|||
res
|
||||
Content []*wireContent `json:"content"`
|
||||
}
|
||||
if err := json.Unmarshal(data, &wire); err != nil {
|
||||
if err := internaljson.Unmarshal(data, &wire); err != nil {
|
||||
return err
|
||||
}
|
||||
var err error
|
||||
|
|
@ -286,7 +288,7 @@ type CompleteReference struct {
|
|||
func (r *CompleteReference) UnmarshalJSON(data []byte) error {
|
||||
type wireCompleteReference CompleteReference // for naive unmarshaling
|
||||
var r2 wireCompleteReference
|
||||
if err := json.Unmarshal(data, &r2); err != nil {
|
||||
if err := internaljson.Unmarshal(data, &r2); err != nil {
|
||||
return err
|
||||
}
|
||||
switch r2.Type {
|
||||
|
|
@ -402,7 +404,7 @@ func (r *CreateMessageResult) UnmarshalJSON(data []byte) error {
|
|||
result
|
||||
Content *wireContent `json:"content"`
|
||||
}
|
||||
if err := json.Unmarshal(data, &wire); err != nil {
|
||||
if err := internaljson.Unmarshal(data, &wire); err != nil {
|
||||
return err
|
||||
}
|
||||
var err error
|
||||
|
|
@ -838,7 +840,7 @@ func (m *PromptMessage) UnmarshalJSON(data []byte) error {
|
|||
msg
|
||||
Content *wireContent `json:"content"`
|
||||
}
|
||||
if err := json.Unmarshal(data, &wire); err != nil {
|
||||
if err := internaljson.Unmarshal(data, &wire); err != nil {
|
||||
return err
|
||||
}
|
||||
var err error
|
||||
|
|
@ -1014,7 +1016,7 @@ func (m *SamplingMessage) UnmarshalJSON(data []byte) error {
|
|||
msg
|
||||
Content *wireContent `json:"content"`
|
||||
}
|
||||
if err := json.Unmarshal(data, &wire); err != nil {
|
||||
if err := internaljson.Unmarshal(data, &wire); err != nil {
|
||||
return err
|
||||
}
|
||||
var err error
|
||||
|
|
|
|||
Loading…
Reference in a new issue