summaryrefslogtreecommitdiff
path: root/app
diff options
context:
space:
mode:
authormo khan <mo@mokhan.ca>2025-04-30 12:02:14 -0600
committermo khan <mo@mokhan.ca>2025-04-30 12:02:14 -0600
commit197ef4ee79e7c4881c5c612115326f4e874c9415 (patch)
tree3d79d3556124ffee07a9d4f3791a81cd915f733b /app
parentb992722e806e45ac3ade8ced829d939299c37c41 (diff)
fix: the CSRF cookie needs to have a same site lax mode
Diffstat (limited to 'app')
-rw-r--r--app/controllers/sessions/controller.go5
-rw-r--r--app/controllers/sessions/service.go3
2 files changed, 6 insertions, 2 deletions
diff --git a/app/controllers/sessions/controller.go b/app/controllers/sessions/controller.go
index 8d0e858..5babe7d 100644
--- a/app/controllers/sessions/controller.go
+++ b/app/controllers/sessions/controller.go
@@ -33,7 +33,10 @@ func (c *Controller) New(w http.ResponseWriter, r *http.Request) {
}
url, nonce := c.svc.GenerateRedirectURL()
- http.SetCookie(w, cookie.New("oauth_state", nonce, time.Now().Add(10*time.Minute)))
+ cookie := cookie.New("oauth_state", nonce, time.Now().Add(10*time.Minute))
+ // This cookie must be sent as part of a redirect that originates from the OIDC Provider
+ cookie.SameSite = http.SameSiteLaxMode
+ http.SetCookie(w, cookie)
http.Redirect(w, r, url, http.StatusFound)
}
diff --git a/app/controllers/sessions/service.go b/app/controllers/sessions/service.go
index 0ee692a..0fd7692 100644
--- a/app/controllers/sessions/service.go
+++ b/app/controllers/sessions/service.go
@@ -3,6 +3,7 @@ package sessions
import (
"context"
"errors"
+ "fmt"
"net/http"
"gitlab.com/gitlab-org/software-supply-chain-security/authorization/sparkled/pkg/oidc"
@@ -34,7 +35,7 @@ func (svc *Service) GenerateRedirectURL() (string, string) {
func (svc *Service) Exchange(r *http.Request) (*oidc.Tokens, error) {
cookies := r.CookiesNamed("oauth_state")
if len(cookies) != 1 {
- return nil, errors.New("Missing CSRF token")
+ return nil, errors.New(fmt.Sprintf("Missing CSRF token: %v, cookies: %v", len(cookies), r.Cookies()))
}
state := r.URL.Query().Get("state")