Skip to content

Commit fd64ece

Browse files
committed
Avoid setting duplicate set-cookie headers
Especially helpful for healthcheck requests that are continuously and with short interval checking an endpoint while never completing a flow thus not having the state cleared. Signed-off-by: Ivan Kanakarakis <[email protected]>
1 parent c0a7f22 commit fd64ece

File tree

1 file changed

+13
-2
lines changed

1 file changed

+13
-2
lines changed

src/satosa/base.py

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -219,8 +219,19 @@ def _save_state(self, resp, context):
219219
:param context: Session context
220220
"""
221221

222-
cookie = state_to_cookie(context.state, self.config["COOKIE_STATE_NAME"], "/",
223-
self.config["STATE_ENCRYPTION_KEY"])
222+
cookie_name = self.config["COOKIE_STATE_NAME"]
223+
cookie = state_to_cookie(
224+
context.state,
225+
name=cookie_name,
226+
path="/",
227+
encryption_key=self.config["STATE_ENCRYPTION_KEY"],
228+
)
229+
resp.headers = [
230+
(name, value)
231+
for (name, value) in resp.headers
232+
if name != "Set-Cookie"
233+
or not value.startswith(f"{cookie_name}=")
234+
]
224235
resp.headers.append(tuple(cookie.output().split(": ", 1)))
225236

226237
def run(self, context):

0 commit comments

Comments
 (0)