Skip to content

Commit 277b63c

Browse files
committed
Ignore Set-Cookie from token and introspection endpoint to fix caching
https://stackoverflow.com/a/9232739/2217862: > Make sure your backend does not return Set-Cookie header. If Nginx sees > it, it disables caching. > > proxy_ignore_header will ensure that the caching takes place. > proxy_hide_header will ensure the Cookie payload is not included in the > cached payload. This is important to avoid leaking cookies via the > NGINX cache.
1 parent ae531d7 commit 277b63c

File tree

1 file changed

+9
-2
lines changed

1 file changed

+9
-2
lines changed

conf/server.conf

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -68,8 +68,10 @@ location = /-/internal/request-token {
6868
# If the last request passed to the server has not completed for the specified time,
6969
# one more request may be passed.
7070
proxy_cache_lock_age 2s;
71-
# Ignore caching headers (OIDC Provider sends no-cache).
72-
proxy_ignore_headers Cache-Control Expires;
71+
# Ignore caching headers (OIDC Provider sends no-cache) and Set-Cookie.
72+
# If the OIDC server returns Set-Cookie, the response will not be cached,
73+
# so we must ignore it.
74+
proxy_ignore_headers Cache-Control Expires Set-Cookie;
7375
}
7476

7577
location = /-/internal/introspect-token {
@@ -93,4 +95,9 @@ location = /-/internal/introspect-token {
9395
proxy_cache_lock_age 2s;
9496
# Use stale responses if we cannot reach the server.
9597
proxy_cache_use_stale error timeout http_500 http_502 http_503 http_504;
98+
# If the OIDC server returns Set-Cookie, the response will not be cached,
99+
# so we must ignore it.
100+
proxy_ignore_headers Set-Cookie;
101+
# Don't include Set-Cookie in the cached payload.
102+
proxy_hide_header Set-Cookie;
96103
}

0 commit comments

Comments
 (0)