MCPcopy Create free account
hub / github.com/modelcontextprotocol/go-sdk / validateAuthServerMetaURLs

Function validateAuthServerMetaURLs

oauthex/auth_meta.go:169–208  ·  view source on GitHub ↗

validateAuthServerMetaURLs validates all URL fields in AuthServerMeta to ensure they don't use dangerous schemes that could enable XSS attacks. It also validates that URLs likely to be called by the client use HTTPS or are loopback addresses.

(asm *AuthServerMeta)

Source from the content-addressed store, hash-verified

167// It also validates that URLs likely to be called by the client use
168// HTTPS or are loopback addresses.
169func validateAuthServerMetaURLs(asm *AuthServerMeta) error {
170 urls := []struct {
171 name string
172 value string
173 }{
174 {"authorization_endpoint", asm.AuthorizationEndpoint},
175 {"token_endpoint", asm.TokenEndpoint},
176 {"jwks_uri", asm.JWKSURI},
177 {"registration_endpoint", asm.RegistrationEndpoint},
178 {"service_documentation", asm.ServiceDocumentation},
179 {"op_policy_uri", asm.OpPolicyURI},
180 {"op_tos_uri", asm.OpTOSURI},
181 {"revocation_endpoint", asm.RevocationEndpoint},
182 {"introspection_endpoint", asm.IntrospectionEndpoint},
183 }
184
185 for _, u := range urls {
186 if err := checkURLScheme(u.value); err != nil {
187 return fmt.Errorf("%s: %w", u.name, err)
188 }
189 }
190
191 urls = []struct {
192 name string
193 value string
194 }{
195 {"authorization_endpoint", asm.AuthorizationEndpoint},
196 {"token_endpoint", asm.TokenEndpoint},
197 {"registration_endpoint", asm.RegistrationEndpoint},
198 {"introspection_endpoint", asm.IntrospectionEndpoint},
199 }
200
201 for _, u := range urls {
202 if err := checkHTTPSOrLoopback(u.value); err != nil {
203 return fmt.Errorf("%s: %w", u.name, err)
204 }
205 }
206
207 return nil
208}

Callers 2

GetAuthServerMetaFunction · 0.85

Calls 2

checkHTTPSOrLoopbackFunction · 0.85
checkURLSchemeFunction · 0.70

Tested by 1

Used in the wild real call sites across dependent graphs

searching dependent graphs…