mcp: verify 'Origin' and 'Content-Type' headers (#842)

This PR introduces protection against cross-origin requests by
installing `http.CrossOriginProtection`.
By default, the zero value is used which does not contain any trusted
origins or bypass patterns.
The protection can be customized by providing a custom
`http.CrossOriginProtection` in `mcp.StreamableHTTPOptions`. Currently,
the deny handler set on the protection is ignored.
This default has an MCPGODEBUG option (`disableoriginverification`) to
disable the default protection.
It will be available until `v1.6.0` of the SDK.
We also increase the Go version required by the SDK to 1.25, since this
is the version that introduced `http.CrossOriginProtection`. This is in
line with the SDK's policy of supporting two newest Go versions (1.26
was released in February 2026).

Additionally, we start validating if the `Content-Type` header for
`POST` requests is set to `application/json` to avoid accepting
CORS-safelisted requests.
This commit is contained in:
Maciej Kisiel 2026-03-13 11:36:41 +01:00 • committed by GitHub
commit a433a831d6
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
5 changed files with 252 additions and 11 deletions

View file

@ -8,6 +8,9 @@ on:
schedule:
- cron: '31 9 * * 4'
# Declare default permissions as read only.
permissions: read-all
jobs:
analyze:
name: Analyze (${{ matrix.language }})

View file

@ -22,7 +22,7 @@ jobs:
- name: Set up Go
uses: actions/setup-go@4b73464bb391d4059bd26b0524d20df3927bd417 # v6.3.0
with:
go-version: "^1.25"
go-version: "^1.26"
- name: Start everything-server
run: |
go run ./conformance/everything-server/main.go -http=":3001" &
@ -45,7 +45,7 @@ jobs:
- name: Set up Go
uses: actions/setup-go@4b73464bb391d4059bd26b0524d20df3927bd417 # v6.3.0
with:
go-version: "^1.25"
go-version: "^1.26"
- name: "Run conformance tests"
uses: modelcontextprotocol/conformance@a2855b03582a6c0b31065ad4d9af248316ce61a3 # v0.1.15
with:

View file

@ -17,6 +17,8 @@ jobs:
steps:
- name: Set up Go
uses: actions/setup-go@4b73464bb391d4059bd26b0524d20df3927bd417 # v6.3.0
with:
go-version: "^1.26"
- name: Check out code
uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
- name: Check docs are up-to-date

View file

@ -27,7 +27,7 @@ jobs:
- name: Set up Go
uses: actions/setup-go@4b73464bb391d4059bd26b0524d20df3927bd417 # v6.3.0
with:
go-version: "^1.25"
go-version: "^1.26"
- name: Set up Node.js
uses: actions/setup-node@6044e13b5dc448c55e2357c09f80417699197238 # v6.2.0
with:

View file

@ -40,7 +40,7 @@ jobs:
runs-on: ubuntu-latest
strategy:
matrix:
go: ["1.24", "1.25"]
go: ["1.25", "1.26"]
steps:
- name: Check out code
uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
@ -52,6 +52,8 @@ jobs:
run: go test -v ./...
race-test:
# Temporarily disable until fixes are prepared.
if: false
runs-on: ubuntu-latest
steps:
- name: Check out code
@ -59,6 +61,6 @@ jobs:
- name: Set up Go
uses: actions/setup-go@4b73464bb391d4059bd26b0524d20df3927bd417 # v6.3.0
with:
go-version: "1.24"
go-version: "1.25"
- name: Test with -race
run: go test -v -race ./...