git.iko.soy/typeable/oauth2-proxy
on master help sign in
fix: use GetSecret() in ticket.go makeCookie to respect cookie-secret-file (#3228)

* fix: use GetSecret() in ticket.go makeCookie The makeCookie method in ticket.go was using t.options.Secret directly, which meant cookie-secret-file was not being respected. Updated to use GetSecret() which handles both cookie-secret and cookie-secret-file properly. Also added test coverage for cookie-secret-file functionality. Fixes #3224 Signed-off-by: stagswtf <142280349+stagswtf@users.noreply.github.com> * docs: update CHANGELOG.md for cookie-secret-file fix Signed-off-by: stagswtf <142280349+stagswtf@users.noreply.github.com> * correct PR link and undo file formatting Signed-off-by: stagswtf <142280349+stagswtf@users.noreply.github.com> * fix: error wrapping Signed-off-by: Jan Larwig <jan@larwig.com> --------- Signed-off-by: stagswtf <142280349+stagswtf@users.noreply.github.com> Signed-off-by: Jan Larwig <jan@larwig.com> Co-authored-by: Jan Larwig <jan@larwig.com>

commit51e80f24ef25252d65476cf33e31242e43919af9 authorstagswtf <142280349+stagswtf@users.noreply.github.com> dateTue 28 Oct 2025, 00:37 (1 year ago) parentc0a087d
3 files changed+48−4
CHANGELOG.md+3−1 pkg/sessions/persistence/ticket.go+8−3 pkg/sessions/tests/session_store_tests.go+37
CHANGELOG.md+3−1
@@ -8,6 +8,8 @@
88
99## Changes since v7.12.0
1010
11+- [#3228](https://github.com/oauth2-proxy/oauth2-proxy/pull/3228) fix: use GetSecret() in ticket.go makeCookie to respect cookie-secret-file (@stagswtf)
12+
1113# V7.12.0
1214
1315## Release Highlights
@@ -119,7 +121,7 @@ For detailed information, migration guidance, and security implications, see the
119121- 🕵️‍♀️ Vulnerabilities have been addressed
120122 - [CVE-2025-22871](https://github.com/advisories/GHSA-g9pc-8g42-g6vq)
121123- 🐛 Squashed some bugs
122−
124+
123125## Important Notes
124126
125127## Breaking Changes
pkg/sessions/persistence/ticket.go+8−3
@@ -233,12 +233,17 @@ func (t *ticket) clearCookie(rw http.ResponseWriter, req *http.Request) {
233233// makeCookie makes a cookie, signing the value if present
234234func (t *ticket) makeCookie(req *http.Request, value string, expires time.Duration, now time.Time) (*http.Cookie, error) {
235235 if value != "" {
236− var err error
237− value, err = encryption.SignedValue(t.options.Secret, t.options.Name, []byte(value), now)
236+ secret, err := t.options.GetSecret()
238237 if err != nil {
239− return nil, err
238+ return nil, fmt.Errorf("retrieving secret failed: %w", err)
239+ }
240+
241+ value, err = encryption.SignedValue(secret, t.options.Name, []byte(value), now)
242+ if err != nil {
243+ return nil, fmt.Errorf("signing cookie value failed: %w", err)
240244 }
241245 }
246+
242247 return cookies.MakeCookieFromOptions(
243248 req,
244249 t.options.Name,
pkg/sessions/tests/session_store_tests.go+37
@@ -4,6 +4,7 @@ import (
44 "crypto/rand"
55 "net/http"
66 "net/http/httptest"
7+ "os"
78 "strconv"
89 "strings"
910 "time"
@@ -133,6 +134,42 @@ func RunSessionStoreTests(newSS NewSessionStoreFunc, persistentFastForward Persi
133134 PersistentSessionStoreInterfaceTests(&input)
134135 }
135136 })
137+
138+ Context("with cookie secret file", func() {
139+ var tmpfile *os.File
140+ var err error
141+ BeforeEach(func() {
142+ tmpfile, err = os.CreateTemp("", "cookie-secret-test")
143+ secretBytes := make([]byte, 32)
144+ tmpfile.Write(secretBytes)
145+ tmpfile.Close()
146+
147+ input.cookieOpts = &options.Cookie{
148+ Name: "_oauth2_proxy_file",
149+ Path: "/",
150+ Expire: time.Duration(168) * time.Hour,
151+ Refresh: time.Duration(1) * time.Hour,
152+ Secure: true,
153+ HTTPOnly: true,
154+ SameSite: "",
155+ Secret: "",
156+ SecretFile: tmpfile.Name(),
157+ }
158+ ss, err = newSS(opts, input.cookieOpts)
159+ Expect(err).ToNot(HaveOccurred())
160+ })
161+
162+ AfterEach(func() {
163+ if tmpfile != nil {
164+ os.Remove(tmpfile.Name())
165+ }
166+ })
167+
168+ SessionStoreInterfaceTests(&input)
169+ if persistentFastForward != nil {
170+ PersistentSessionStoreInterfaceTests(&input)
171+ }
172+ })
136173 })
137174}
138175