MCPcopy Create free account
hub / github.com/danielmiessler/Fabric / requireAPIKeyForBind

Function requireAPIKeyForBind

internal/server/auth.go:104–116  ·  view source on GitHub ↗

requireAPIKeyForBind rejects a non-loopback bind address that has no API key. An empty or unspecified host binds each interface, and that counts as non-loopback. It warns when the key is short.

(address, apiKey string)

Source from the content-addressed store, hash-verified

102// API key. An empty or unspecified host binds each interface, and that
103// counts as non-loopback. It warns when the key is short.
104func requireAPIKeyForBind(address, apiKey string) error {
105 if apiKey != "" && len(apiKey) < minAPIKeyLength {
106 slog.Warn("API key is short: use a random key of 16 or more characters", "length", len(apiKey))
107 }
108 // Only the exact name "localhost" or a loopback IP is accepted. A name
109 // such as "app.localhost" goes to DNS on some systems, and the server
110 // can then listen on a public interface with no key.
111 host := hostOnly(address)
112 if apiKey != "" || host == "localhost" || net.ParseIP(host).IsLoopback() {
113 return nil
114 }
115 return fmt.Errorf(i18n.T("server_api_key_required"), address)
116}
117
118// APIKeyMiddleware validates API key for protected endpoints.
119// Swagger documentation endpoints (/swagger/*) are exempt from authentication

Callers 3

TestRequireAPIKeyForBindFunction · 0.85
ServeOllamaFunction · 0.85
ServeFunction · 0.85

Calls 2

TFunction · 0.92
hostOnlyFunction · 0.85

Tested by 1

TestRequireAPIKeyForBindFunction · 0.68