Skip to content

Commit c46073a

Browse files
committed
enforce PKCE for public clients, skip secret validation for public clients
1 parent 57660e0 commit c46073a

2 files changed

Lines changed: 10 additions & 0 deletions

File tree

connector/oauth/oauth.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import (
66
"encoding/json"
77
"errors"
88
"fmt"
9+
"io"
910
"log/slog"
1011
"net/http"
1112
"strings"

server/handlers.go

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -896,6 +896,8 @@ func (s *Server) withClientFromStorage(w http.ResponseWriter, r *http.Request, h
896896
s.tokenErrHelper(w, errInvalidClient, "Invalid client credentials.", http.StatusUnauthorized)
897897
return
898898
}
899+
} else if clientSecret != "" {
900+
s.logger.WarnContext(r.Context(), "public client sent client_secret, ignoring", "client_id", client.ID)
899901
}
900902

901903
handler(w, r, client)
@@ -995,6 +997,13 @@ func (s *Server) handleAuthCode(w http.ResponseWriter, r *http.Request, client s
995997
// Received PKCE request on /auth, but no code_verifier on /token
996998
s.tokenErrHelper(w, errInvalidGrant, "Expecting parameter code_verifier in PKCE flow.", http.StatusBadRequest)
997999
return
1000+
default:
1001+
// Neither code_challenge nor code_verifier present.
1002+
// Public clients MUST use PKCE — reject if not used.
1003+
if client.Public {
1004+
s.tokenErrHelper(w, errInvalidRequest, "Public clients must use PKCE (code_challenge and code_verifier).", http.StatusBadRequest)
1005+
return
1006+
}
9981007
}
9991008

10001009
if authCode.RedirectURI != redirectURI {

0 commit comments

Comments
 (0)