git.iko.soy/typeable/oauth2-proxy
on master help sign in
Merge commit from fork

* fix: clear session cookie at beginning of signinpage handler Co-authored-by: Christopher Schrewing <christopher.schrewing@weidmueller.com> Signed-off-by: Michael Bella <michael.bella@weidmueller.com> Signed-off-by: Jan Larwig <jan@larwig.com> * test: clear session cookie at beginning of signinpage handler Signed-off-by: Jan Larwig <jan@larwig.com> * doc: changelog entry for GHSA-f24x-5g9q-753f Signed-off-by: Jan Larwig <jan@larwig.com> --------- Signed-off-by: Michael Bella <michael.bella@weidmueller.com> Signed-off-by: Jan Larwig <jan@larwig.com> Co-authored-by: Christopher Schrewing <christopher.schrewing@weidmueller.com>

commit0337a95fc6bb4c2798e555b28ae61500b30a6b9b authorJan Larwig <jan@larwig.com> dateMon 13 Apr 2026, 18:17 (6 months ago) parent2e1261c
3 files changed+49−4
CHANGELOG.md+1 oauthproxy.go+4−4 oauthproxy_test.go+44
CHANGELOG.md+1
@@ -10,6 +10,7 @@
1010
1111- [#3411](https://github.com/oauth2-proxy/oauth2-proxy/pull/3411) chore(deps): update gomod dependencies (@tuunit)
1212- [#3333](https://github.com/oauth2-proxy/oauth2-proxy/pull/3333) fix: invalidate session on fatal OAuth2 refresh errors (@frhack)
13+- [GHSA-f24x-5g9q-753f](https://github.com/oauth2-proxy/oauth2-proxy/security/advisories/GHSA-f24x-5g9q-753f) fix: clear session cookie at beginning of signinpage handler (@fnoehWM / @bella-WI / @tuunit)
1314
1415# V7.15.1
1516
oauthproxy.go+4−4
@@ -634,6 +634,10 @@ func (p *OAuthProxy) isTrustedIP(req *http.Request) bool {
634634// SignInPage writes the sign in template to the response
635635func (p *OAuthProxy) SignInPage(rw http.ResponseWriter, req *http.Request, code int) {
636636 prepareNoCache(rw)
637+
638+ if err := p.ClearSessionCookie(rw, req); err != nil {
639+ logger.Printf("Error clearing session cookie: %v", err)
640+ }
637641 rw.WriteHeader(code)
638642
639643 redirectURL, err := p.appDirector.GetRedirect(req)
@@ -647,10 +651,6 @@ func (p *OAuthProxy) SignInPage(rw http.ResponseWriter, req *http.Request, code
647651 redirectURL = "/"
648652 }
649653
650− if err := p.ClearSessionCookie(rw, req); err != nil {
651− logger.Printf("Error clearing session cookie: %v", err)
652− }
653−
654654 p.pageWriter.WriteSignInPage(rw, req, redirectURL, code)
655655}
656656
oauthproxy_test.go+44
@@ -713,6 +713,50 @@ func TestManualSignInCorrectCredentials(t *testing.T) {
713713 assert.Equal(t, http.StatusFound, statusCode)
714714}
715715
716+func TestSignInPageClearsExistingSessionCookie(t *testing.T) {
717+ opts := baseTestOptions()
718+ err := validation.Validate(opts)
719+ require.NoError(t, err)
720+
721+ proxy, err := NewOAuthProxy(opts, func(string) bool {
722+ return true
723+ })
724+ require.NoError(t, err)
725+
726+ // Create a real session cookie using the actual session store.
727+ saveRW := httptest.NewRecorder()
728+ saveReq := httptest.NewRequest(http.MethodGet, "/", nil)
729+ err = proxy.sessionStore.Save(saveRW, saveReq, &sessions.SessionState{
730+ Email: "john.doe@example.com",
731+ })
732+ require.NoError(t, err)
733+
734+ cookies := saveRW.Result().Cookies()
735+ require.NotEmpty(t, cookies)
736+
737+ // Send that cookie to the sign-in page.
738+ req := httptest.NewRequest(http.MethodGet, "/oauth2/sign_in", nil)
739+ for _, c := range cookies {
740+ req.AddCookie(c)
741+ }
742+
743+ rw := httptest.NewRecorder()
744+ proxy.ServeHTTP(rw, req)
745+
746+ assert.Equal(t, http.StatusOK, rw.Code)
747+
748+ cleared := false
749+ for _, c := range rw.Result().Cookies() {
750+ if c.Name == proxy.CookieOptions.Name {
751+ cleared = true
752+ assert.Equal(t, "", c.Value)
753+ assert.Less(t, c.MaxAge, 0)
754+ }
755+ }
756+
757+ assert.True(t, cleared, "expected sign-in page to clear existing session cookie")
758+}
759+
716760func TestSignInPageIncludesTargetRedirect(t *testing.T) {
717761 sipTest, err := NewSignInPageTest(false)
718762 if err != nil {