Why AI tools produce this: AI coding tools produce this regularly, typically when prompted for a shortcut or a quick fix.
Why this matters
Authorization codes, client_secret, access/refresh tokens, and the code_verifier then travel unencrypted. A network attacker can read or rewrite them and take over the flow.
RFC 6749 §3.1 / §10.9 require TLS for the authorization and token endpoints. Use https:// for every authorize, token, and userinfo URL (including oauth2.Endpoint{AuthURL, TokenURL}). http://localhost is fine for local development and is not flagged.
package mainimport ( "net/http" "golang.org/x/oauth2")// Safe: every OAuth endpoint uses https://.func secureConfig() *oauth2.Config { return &oauth2.Config{ ClientID: "client", // ok: auth.go.oauth.insecure-token-endpoint Endpoint: oauth2.Endpoint{ AuthURL: "https://issuer.example.com/oauth/authorize", TokenURL: "https://issuer.example.com/oauth/token", }, }}// Safe: localhost over http is allowed for local development.func localDevToken() (*http.Response, error) { // ok: auth.go.oauth.insecure-token-endpoint return http.Post("http://localhost:8080/oauth/token", "application/x-www-form-urlencoded", nil)}// Safe trap: a generic cleartext http URL with no OAuth marker is not an// OAuth endpoint and must not be flagged.func fetchHealth() (*http.Response, error) { // ok: auth.go.oauth.insecure-token-endpoint return http.Get("http://issuer.example.com/healthz")}func main() {}
Suppressing this rule
If a finding is a genuine false positive, scope the suppression to the exact line and leave a reason, never disable the rule project-wide. Disable directives are line-scoped by design.