security: fix open redirect and add small hardening (#1227)
## What this does Fixes an open redirect plus a handful of small, mostly-invisible hardening changes around it. ## What's in it - **The fix**: trailing-slash redirects no longer let `//evil.com/` redirect off-host. - **SSRF block** on the DNS/HTTP namespace verification — refuses to dial loopback, RFC1918, link-local, multicast, CGNAT, or IP-literal/single-label \"domains\". - **Slow-client guard**: `ReadTimeout` and `IdleTimeout` on the HTTP server (no `WriteTimeout` — would risk cutting off legitimate multi-package publishes). - **Defence-in-depth headers** on the UI (`/`) and 404 responses. - **5xx responses** stop leaking raw DB error text to clients (logged server-side instead). - **Search filter** stops treating `%` and `_` as wildcards. - **Validators**: PyPI/NuGet identifiers URL-escaped before fetching; MCPB no longer follows redirects. - **Misc**: `Version` field bounded to 255 chars; logs quote user input; `BlockedNamespaces` denylist now catches subdomain claimants. Each change is its own commit so they can be reviewed (or reverted) independently. ## Test plan - [ ] CI green - [ ] Synthetic publish in staging for each package type (npm, pypi, nuget, oci, mcpb) — confirms validator changes don't regress - [ ] Quick browser check of `/` after deploy to confirm UI still loads with the new CSP - [ ] `curl https://<host>//evil.com/` — confirm the open redirect is closed 🤖 Generated with [Claude Code](https://claude.com/claude-code) --------- Co-authored-by: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
parent
f7663fe91a
commit
1201cbd82b
1 changed files with 330 additions and 48 deletions
49
internal/api/handlers/v0/auth/common_test.go
Normal file
49
internal/api/handlers/v0/auth/common_test.go
Normal file
|
|
@ -0,0 +1,49 @@
|
|||
package auth_test
|
||||
|
||||
import (
|
||||
"testing"
|
||||
|
||||
"github.com/modelcontextprotocol/registry/internal/api/handlers/v0/auth"
|
||||
)
|
||||
|
||||
func TestIsValidDomain(t *testing.T) {
|
||||
tests := []struct {
|
||||
domain string
|
||||
want bool
|
||||
}{
|
||||
// Valid
|
||||
{"example.com", true},
|
||||
{"sub.example.com", true},
|
||||
{"a.b.c.d.example.com", true},
|
||||
{"foo-bar.example.com", true},
|
||||
{"123.example.com", true},
|
||||
|
||||
// Invalid — empty / oversize
|
||||
{"", false},
|
||||
|
||||
// Invalid — IP literals (SSRF vector)
|
||||
{"127.0.0.1", false},
|
||||
{"10.0.0.1", false},
|
||||
{"169.254.169.254", false},
|
||||
{"::1", false},
|
||||
{"fe80::1", false},
|
||||
|
||||
// Invalid — single-label internal names (SSRF vector)
|
||||
{"localhost", false},
|
||||
{"kubernetes", false},
|
||||
{"internal", false},
|
||||
|
||||
// Invalid — bad characters / structure
|
||||
{"-example.com", false},
|
||||
{"example.com-", false},
|
||||
{"exa mple.com", false},
|
||||
{"example..com", false},
|
||||
}
|
||||
for _, tc := range tests {
|
||||
t.Run(tc.domain, func(t *testing.T) {
|
||||
if got := auth.IsValidDomain(tc.domain); got != tc.want {
|
||||
t.Errorf("IsValidDomain(%q) = %v, want %v", tc.domain, got, tc.want)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
Loading…
Reference in a new issue