MCPcopy Create free account
hub / github.com/PerpetualSoftware/pad / refuseAPITokenForAdmin

Method refuseAPITokenForAdmin

internal/server/server.go:903–912  ·  view source on GitHub ↗

refuseAPITokenForAdmin guards every /api/v1/admin route (BUG-3361). An admin's PAT carries their identity, not their platform authority: one used to be enough to register an account, promote it to admin, sign in as it, and reset any password. A browser or `pad auth login` CLI session is required, th

(next http.Handler)

Source from the content-addressed store, hash-verified

901// required, the line BUG-2890 drew for token minting. The cloud sidecar
902// authenticates with the cloud secret, never a PAT, so it is unaffected.
903func (s *Server) refuseAPITokenForAdmin(next http.Handler) http.Handler {
904 return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
905 if isAPITokenAuth(r) && !s.adminAcceptsAPITokens() {
906 writeError(w, http.StatusForbidden, "session_required",
907 "Platform administration requires an interactive session, not an API token")
908 return
909 }
910 next.ServeHTTP(w, r)
911 })
912}
913
914// Init2FASecret loads the 2FA challenge signing key from platform_settings.
915// If no key exists (first run), a new random key is generated and persisted.

Callers

nothing calls this directly

Calls 4

adminAcceptsAPITokensMethod · 0.95
isAPITokenAuthFunction · 0.85
writeErrorFunction · 0.85
ServeHTTPMethod · 0.45

Tested by

no test coverage detected