fix(32.2): WR-02 refuse a ConsentPath that is not a same-origin path
Add wristband.CheckConsentPath (additive, for hosts to call at boot) and make Authorize answer 500 before storing a pending request while the configured path fails it, so the handoff can never leave the issuer's origin.
This commit is contained in:
@@ -241,3 +241,60 @@ func TestAuthorizeDefaultScopes(t *testing.T) {
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
// TestCheckConsentPath locks the WR-02 guard: Options.ConsentPath is
|
||||
// appended to Issuer as given, so only a plain same-origin absolute path is
|
||||
// accepted, and Authorize answers 500 without storing a pending request or
|
||||
// sending a Location while the configured path fails it.
|
||||
func TestCheckConsentPath(t *testing.T) {
|
||||
for _, ok := range []string{"", "/connect", "/backend/connect", "/gfadmin/mcp/connect", "/a%20b"} {
|
||||
if err := CheckConsentPath(ok); err != nil {
|
||||
t.Fatalf("CheckConsentPath(%q) = %v, want nil", ok, err)
|
||||
}
|
||||
}
|
||||
for _, bad := range []string{
|
||||
"@evil.example/connect",
|
||||
"backend/connect",
|
||||
"//evil.example/connect",
|
||||
"/\\evil.example",
|
||||
"/connect?x=1",
|
||||
"/connect#frag",
|
||||
"/user@evil.example",
|
||||
"/con nect",
|
||||
"/connect\n",
|
||||
"/connect\x7f",
|
||||
} {
|
||||
if err := CheckConsentPath(bad); err == nil {
|
||||
t.Fatalf("CheckConsentPath(%q) = nil, want an error", bad)
|
||||
}
|
||||
}
|
||||
|
||||
t.Run("authorize refuses an invalid path without a handoff", func(t *testing.T) {
|
||||
backend := newMemoryBackend()
|
||||
opts := DefaultOptions()
|
||||
opts.Issuer = "https://app.example"
|
||||
opts.Resource = opts.Issuer + "/mcp"
|
||||
opts.ConsentPath = "@evil.example/connect"
|
||||
srv := NewServer(opts)
|
||||
srv.SetBackend(backend)
|
||||
insertAuthorizeTestClient(backend, "cli", []string{authorizeTestRedirect}, nil)
|
||||
_, challenge := s256Pair(t)
|
||||
q := url.Values{}
|
||||
q.Set("client_id", "cli")
|
||||
q.Set("redirect_uri", authorizeTestRedirect)
|
||||
q.Set("response_type", "code")
|
||||
q.Set("code_challenge", challenge)
|
||||
q.Set("code_challenge_method", "S256")
|
||||
q.Set("scope", "read")
|
||||
rec := httptest.NewRecorder()
|
||||
srv.Authorize(rec, httptest.NewRequest(http.MethodGet, "/oauth/mcp/authorize?"+q.Encode(), nil))
|
||||
if rec.Code != http.StatusInternalServerError || rec.Header().Get("Location") != "" {
|
||||
t.Fatalf("authorize = %d Location %q, want 500 and no Location", rec.Code, rec.Header().Get("Location"))
|
||||
}
|
||||
backend.mu.Lock()
|
||||
defer backend.mu.Unlock()
|
||||
if len(backend.codes) != 0 {
|
||||
t.Fatalf("authorize stored %d pending requests, want none", len(backend.codes))
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user