Blame SOURCES/0008-Set-SameSite-to-None-on-test-cookie.patch

7dc08b
From 7ef4ae72a8578475064eb66e3ed5703ccf6ee078 Mon Sep 17 00:00:00 2001
7dc08b
From: Ruediger Pluem <r.pluem@gmx.de>
7dc08b
Date: Thu, 30 Apr 2020 07:56:01 +0200
7dc08b
Subject: [PATCH] Set SameSite to None on test cookie
7dc08b
7dc08b
If the SameSite cookie attribute is to be set because
7dc08b
MellonCookieSameSite is configured and MELLON_DISABLE_SAMESITE not set
7dc08b
for this particular request set it to None for the test cookie.
7dc08b
This ensures that the test cookie with the static test content does not
7dc08b
get lost in the HTTP-POST binding request issued by the autosubmit form
7dc08b
returned by the IDP.
7dc08b
Addresses #20
7dc08b
7dc08b
* auth_mellon.h: Add AM_FORCE_SAMESITE_NONE_NOTE
7dc08b
7dc08b
* auth_mellon_handler.c (am_send_login_authn_request): Set request note
7dc08b
  to set SameSite to None if appropriate.
7dc08b
7dc08b
* auth_mellon_cookie.c (am_cookie_params): Set SameSite to None if
7dc08b
  requested via request note.
7dc08b
---
7dc08b
 auth_mellon.h         | 3 +++
7dc08b
 auth_mellon_cookie.c  | 6 +++++-
7dc08b
 auth_mellon_handler.c | 5 +++++
7dc08b
 3 files changed, 13 insertions(+), 1 deletion(-)
7dc08b
7dc08b
diff --git a/auth_mellon.h b/auth_mellon.h
7dc08b
index fd39b28..401ed9c 100644
7dc08b
--- a/auth_mellon.h
7dc08b
+++ b/auth_mellon.h
7dc08b
@@ -100,6 +100,9 @@ typedef enum {
7dc08b
 /* Disable SameSite Environment Value */
7dc08b
 #define AM_DISABLE_SAMESITE_ENV_VAR "MELLON_DISABLE_SAMESITE"
7dc08b
 
7dc08b
+/* Force setting SameSite to None */
7dc08b
+#define AM_FORCE_SAMESITE_NONE_NOTE "MELLON_FORCE_SAMESITE_NONE"
7dc08b
+
7dc08b
 
7dc08b
 /* This is the length of the id we use (for session IDs and
7dc08b
  * replaying POST data).
7dc08b
diff --git a/auth_mellon_cookie.c b/auth_mellon_cookie.c
7dc08b
index 55f77a5..6bff81e 100644
7dc08b
--- a/auth_mellon_cookie.c
7dc08b
+++ b/auth_mellon_cookie.c
7dc08b
@@ -78,7 +78,11 @@ static const char *am_cookie_params(request_rec *r)
7dc08b
     }
7dc08b
 
7dc08b
     if (env_var_value == NULL){
7dc08b
-        if (cfg->cookie_samesite == am_samesite_lax) {
7dc08b
+        if ((cfg->cookie_samesite != am_samesite_default) &&
7dc08b
+            (apr_table_get(r->notes, AM_FORCE_SAMESITE_NONE_NOTE) != NULL)) {
7dc08b
+            cookie_samesite = "; SameSite=None";
7dc08b
+        }
7dc08b
+        else if (cfg->cookie_samesite == am_samesite_lax) {
7dc08b
             cookie_samesite = "; SameSite=Lax";
7dc08b
         } else if (cfg->cookie_samesite == am_samesite_strict) {
7dc08b
             cookie_samesite = "; SameSite=Strict";
7dc08b
diff --git a/auth_mellon_handler.c b/auth_mellon_handler.c
7dc08b
index 395ee1d..40c9bcd 100644
7dc08b
--- a/auth_mellon_handler.c
7dc08b
+++ b/auth_mellon_handler.c
7dc08b
@@ -3261,8 +3261,13 @@ static int am_send_login_authn_request(request_rec *r, const char *idp,
7dc08b
     /* Add cookie for cookie test. We know that we should have
7dc08b
      * a valid cookie when we return from the IdP after SP-initiated
7dc08b
      * login.
7dc08b
+     * Ensure that SameSite is set to None for this cookie if SameSite
7dc08b
+     * is allowed to be set as the cookie otherwise gets lost on
7dc08b
+     * HTTP-POST binding messages.
7dc08b
      */
7dc08b
+    apr_table_setn(r->notes, AM_FORCE_SAMESITE_NONE_NOTE, "1");
7dc08b
     am_cookie_set(r, "cookietest");
7dc08b
+    apr_table_unset(r->notes, AM_FORCE_SAMESITE_NONE_NOTE);
7dc08b
 
7dc08b
     server = am_get_lasso_server(r);
7dc08b
     if(server == NULL) {
7dc08b
-- 
7dc08b
2.26.2
7dc08b