auth: Add HTTP-based authentication support to validate domain ownership (#282)

Add HTTP-based authentication to prove domain ownership, similar to
https://github.com/modelcontextprotocol/registry/pull/238's DNS
authentication but using HTTPS well-known URIs instead of DNS TXT
records.

Fixes #280

## Motivation and Context

Some organizations don't have easy access to DNS records, but can easily
deploy web assets. They would therefore prefer to be able to complete a
HTTP challenge rather than a DNS one to authenticate to the registry.

This would in some way mirror ACME challenges: where you can do a DNS-01
or a HTTP-01 challenge.

## How Has This Been Tested?

- Tested locally by stubbing out the HTTP getter
- Added unit tests

## Breaking Changes

None

## Types of changes
<!-- What types of changes does your code introduce? Put an `x` in all
the boxes that apply: -->
- [ ] Bug fix (non-breaking change which fixes an issue)
- [x] New feature (non-breaking change which adds functionality)
- [ ] Breaking change (fix or feature that would cause existing
functionality to change)
- [ ] Documentation update

## Checklist
<!-- Go over all the following points, and put an `x` in all the boxes
that apply. -->
- [x] I have read the [MCP
Documentation](https://modelcontextprotocol.io)
- [x] My code follows the repository's style guidelines
- [x] New and existing tests pass locally
- [x] I have added appropriate error handling
- [x] I have added or updated documentation as needed

## Additional context

I concern I had when building this that it might expose us to SSRF
attacks.

I think on reflection this is not a significant problem:
- We only GET a fixed file `.well-known/mcp-registry-auth` (redirects
disallowed) after sanitizing the domain, and then also don't expose the
response to the user. This means the user shouldn't be able to hit
anything very interesting.
- The information they might get is what domains/servers exist in the
network. Our infrastructure is already all open-source, so attackers
aren't getting any additional real info by prodding at the environment
this way.
This commit is contained in:
adam jones 2025-08-21 23:13:09 +01:00 • committed by GitHub
commit ee910ca286
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -99,6 +99,8 @@ func publishCommand() error {
var authMethod string
var dnsDomain string
var dnsPrivateKey string
var httpDomain string
var httpPrivateKey string
// Command-line flags for configuration
publishFlags.StringVar(&registryURL, "registry-url", "", "URL of the registry (required)")
@ -107,6 +109,8 @@ func publishCommand() error {
publishFlags.StringVar(&authMethod, "auth-method", "github-at", "authentication method (default: github-at)")
publishFlags.StringVar(&dnsDomain, "dns-domain", "", "domain name for DNS authentication (required for dns auth method)")
publishFlags.StringVar(&dnsPrivateKey, "dns-private-key", "", "64-character hex seed for DNS authentication (required for dns auth method)")
publishFlags.StringVar(&httpDomain, "http-domain", "", "domain name for HTTP authentication (required for http auth method)")
publishFlags.StringVar(&httpPrivateKey, "http-private-key", "", "64-character hex seed for HTTP authentication (required for http auth method)")
// Set custom usage function
publishFlags.Usage = func() {
@ -121,6 +125,8 @@ func publishCommand() error {
fmt.Fprint(os.Stdout, " --auth-method string authentication method (default: github-at)\n")
fmt.Fprint(os.Stdout, " --dns-domain string domain name for DNS authentication\n")
fmt.Fprint(os.Stdout, " --dns-private-key string 64-character hex seed for DNS authentication\n")
fmt.Fprint(os.Stdout, " --http-domain string domain name for HTTP authentication\n")
fmt.Fprint(os.Stdout, " --http-private-key string 64-character hex seed for HTTP authentication\n")
}
if err := publishFlags.Parse(os.Args[2:]); err != nil {
@ -149,6 +155,9 @@ func publishCommand() error {
case "dns":
log.Println("Using DNS-based authentication")
authProvider = auth.NewDNSProvider(registryURL, dnsDomain, dnsPrivateKey)
case "http":
log.Println("Using HTTP-based authentication")
authProvider = auth.NewHTTPProvider(registryURL, httpDomain, httpPrivateKey)
case "none":
log.Println("Using anonymous authentication")
authProvider = auth.NewNoneProvider(registryURL)