summaryrefslogtreecommitdiff
path: root/internal
diff options
context:
space:
mode:
authorjwijenbergh <jeroenwijenbergh@protonmail.com>2023-09-27 16:36:51 +0200
committerJeroen Wijenbergh <46386452+jwijenbergh@users.noreply.github.com>2023-09-29 13:31:43 +0200
commitb4f04a2cd7162b3c88f9ac28d5a19d56bbe626aa (patch)
tree759e2ad99f7abb6850ff05209426abbf32f77f4e /internal
parentcf7935585c2176a164883224dbf2aa5904637a29 (diff)
OAuth: Check for error parameter in authorization response
Diffstat (limited to 'internal')
-rw-r--r--internal/oauth/oauth.go13
1 files changed, 12 insertions, 1 deletions
diff --git a/internal/oauth/oauth.go b/internal/oauth/oauth.go
index 3d5930b..f1cc9fe 100644
--- a/internal/oauth/oauth.go
+++ b/internal/oauth/oauth.go
@@ -366,11 +366,12 @@ func writeResponseHTML(w http.ResponseWriter, title string, message string) erro
func (s *exchangeSession) Authcode(url *url.URL) (string, error) {
// ISS: https://www.rfc-editor.org/rfc/rfc9207.html
q := url.Query()
+
+ // first check ISS
iss := q.Get("iss")
if s.ISS != iss {
return "", errors.Errorf("failed matching ISS; expected '%s' got '%s'", s.ISS, iss)
}
-
// Make sure the state is present and matches to protect against cross-site request forgeries
// https://datatracker.ietf.org/doc/html/draft-ietf-oauth-v2-1-04#section-7.15
state := q.Get("state")
@@ -382,6 +383,16 @@ func (s *exchangeSession) Authcode(url *url.URL) (string, error) {
return "", errors.Errorf("failed matching state; expected '%s' got '%s'", s.State, state)
}
+ // check if an error is present
+ // https://datatracker.ietf.org/doc/html/draft-ietf-oauth-v2-1-09#name-authorization-response (error response)
+ errc := q.Get("error")
+ if errc != "" {
+ // these are optional but let's include them
+ errdesc := q.Get("error_description")
+ erruri := q.Get("error_uri")
+ return "", errors.Errorf("failed obtaining oauthorization code, error code '%s', error description '%s', error uri '%s'", errc, errdesc, erruri)
+ }
+
// No authorization code
code := q.Get("code")
if code == "" {