Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support SameSite parameter for the persistence cookie #361

Closed
haraldschilly opened this issue Nov 13, 2019 · 18 comments
Closed

Support SameSite parameter for the persistence cookie #361

haraldschilly opened this issue Nov 13, 2019 · 18 comments
Labels
type: feature This issue describes a feature request / wishlist.

Comments

@haraldschilly
Copy link

Output of haproxy -vv and uname -a

# haproxy -vv
HA-Proxy version 1.8.8-1ubuntu0.4 2019/01/24
Copyright 2000-2018 Willy Tarreau <willy@haproxy.org>

Build options :
  TARGET  = linux2628
  CPU     = generic
  CC      = gcc
  CFLAGS  = -g -O2 -fdebug-prefix-map=/build/haproxy-Mxbbv4/haproxy-1.8.8=. -fstack-protector-strong -Wformat -Werror=format-security -Wdate-time -D_FORTIFY_SOURCE
=2
  OPTIONS = USE_GETADDRINFO=1 USE_ZLIB=1 USE_REGPARM=1 USE_OPENSSL=1 USE_LUA=1 USE_SYSTEMD=1 USE_PCRE=1 USE_PCRE_JIT=1 USE_NS=1

Default settings :
  maxconn = 2000, bufsize = 16384, maxrewrite = 1024, maxpollevents = 200

Built with OpenSSL version : OpenSSL 1.1.0g  2 Nov 2017
Running on OpenSSL version : OpenSSL 1.1.1  11 Sep 2018 (VERSIONS DIFFER!)
OpenSSL library supports TLS extensions : yes
OpenSSL library supports SNI : yes
OpenSSL library supports : TLSv1.0 TLSv1.1 TLSv1.2
Built with Lua version : Lua 5.3.3
Built with transparent proxy support using: IP_TRANSPARENT IPV6_TRANSPARENT IP_FREEBIND
Encrypted password support via crypt(3): yes
Built with multi-threading support.
Built with PCRE version : 8.39 2016-06-14
Running on PCRE version : 8.39 2016-06-14
PCRE library supports JIT : yes
Built with zlib version : 1.2.11
Running on zlib version : 1.2.11
Compression algorithms supported : identity("identity"), deflate("deflate"), raw-deflate("deflate"), gzip("gzip")
Built with network namespace support.

Available polling systems :
      epoll : pref=300,  test result OK
       poll : pref=200,  test result OK
     select : pref=150,  test result OK
Total: 3 (3 usable), will use epoll.

Available filters :
        [SPOE] spoe
        [COMP] compression
        [TRACE] trace

# uname -a
Linux proxy-795c7fbfd9-rbvcg 4.15.0-1037-gcp #39-Ubuntu SMP Wed Jul 3 06:28:59 UTC 2019 x86_64 x86_64 x86_64 GNU/Linux

What should haproxy do differently? Which functionality do you think we should add?

There is a "cookie" within HAproxy, which makes connections stick to specific services.
This cookie doesn't support setting the samesite paramter, with values like lax|strict|none.

What are you trying to do?

My use case is a service, which is embedded into an IFrame by others.
This means, any cookies by that service count as "third party cookies".

Discourse discussion: https://discourse.haproxy.org/t/set-samesite-none-for-haproxies-cookie/4483/5

The more general background is an upcoming change in Chrome and other browsers.
They're going to handle such cookies differently.

https://web.dev/samesite-cookie-recipes/

Any cookies used by that site will be considered as third-party cookies when the site is displayed within the frame.

and

For cookies needed in a third-party context, you will need to ensure they are marked as SameSite=None; Secure.

@haraldschilly haraldschilly added the type: feature This issue describes a feature request / wishlist. label Nov 13, 2019
@lukastribus
Copy link
Member

Let's also discuss:

Should we implement a samesite option specifically or a rather generic option so that users can add whatever parameter they require?

I'd personally opt for the latter, which makes this more flexible.

@haraldschilly
Copy link
Author

Well, if you ask me, a generic option with more flexibility sounds great.

@wtarreau
Copy link
Member

wtarreau commented Nov 13, 2019 via email

@gonmf
Copy link

gonmf commented Jan 15, 2020

Hello everyone.

For the more general background, version 80 of Chrome is scheduled to be rolled out on February 6. This will mean a lot of users will suddenly start different connections for requests to the same HA instance.

@mbride
Copy link

mbride commented Jan 20, 2020

Hello, any update planned for this point? Sticky cookies will not be sent anymore for sites embedded in iframe or in other browser tab if they are not on same domain. This will be blocking for many usecases.
Thank you

@capflam
Copy link
Member

capflam commented Jan 21, 2020

I submitted a patch on the mailing list to solve this issue. Idea is to add an attr option to add any attribute to the cookie:

   cookie SRV insert secure attr "SameSite=Strict"

Of course, the attr option may be repeated to add several attributes. It is simple and generic. It should do the trick. Any comments ?

haproxy-mirror pushed a commit that referenced this issue Jan 22, 2020
… directive

It is now possible to insert any attribute when a cookie is inserted by
HAProxy. Any value may be set, no check is performed except the syntax validity
(CTRL chars and ';' are forbidden). For instance, it may be used to add the
SameSite attribute:

    cookie SRV insert attr "SameSite=Strict"

The attr option may be repeated to add several attributes.

This patch should fix the issue #361.
@capflam
Copy link
Member

capflam commented Jan 23, 2020

I backported the feature as far as 1.8.

@capflam capflam closed this as completed Jan 23, 2020
@svjacob
Copy link

svjacob commented Jan 28, 2020

@capflam thanks for the commit! I've got a noob question, when you say you backported it to 1.8, that means I can modify the build before compiling haproxy on 1.8 and it should work? Or does that mean that the actual src download from http://www.haproxy.org/ for 1.8 will include the fix, because it doesn't seem like the changes are in the 1.8 src there.

@haproxy-mirror
Copy link

haproxy-mirror commented Jan 28, 2020 via email

@lukastribus
Copy link
Member

So in the meantime you can (links are for 1.8):

  • pull from git (git clone http://git.haproxy.org/git/haproxy-1.8.git/)
  • get a snapshot 20200124 or newer
  • apply the patch manually

FireBurn pushed a commit to FireBurn/haproxy that referenced this issue Jan 29, 2020
… directive

It is now possible to insert any attribute when a cookie is inserted by
HAProxy. Any value may be set, no check is performed except the syntax validity
(CTRL chars and ';' are forbidden). For instance, it may be used to add the
SameSite attribute:

    cookie SRV insert attr "SameSite=Strict"

The attr option may be repeated to add several attributes.

This patch should fix the issue haproxy#361.

(cherry picked from commit 2f53390)
Signed-off-by: Christopher Faulet <cfaulet@haproxy.com>
(cherry picked from commit fac5082)
Signed-off-by: Christopher Faulet <cfaulet@haproxy.com>
(cherry picked from commit db2cdbb)
Signed-off-by: Christopher Faulet <cfaulet@haproxy.com>
(cherry picked from commit d76877d)
Signed-off-by: Christopher Faulet <cfaulet@haproxy.com>
FireBurn pushed a commit to FireBurn/haproxy that referenced this issue Jan 29, 2020
… directive

It is now possible to insert any attribute when a cookie is inserted by
HAProxy. Any value may be set, no check is performed except the syntax validity
(CTRL chars and ';' are forbidden). For instance, it may be used to add the
SameSite attribute:

    cookie SRV insert attr "SameSite=Strict"

The attr option may be repeated to add several attributes.

This patch should fix the issue haproxy#361.

(cherry picked from commit 2f53390)
Signed-off-by: Christopher Faulet <cfaulet@haproxy.com>
(cherry picked from commit fac5082)
Signed-off-by: Christopher Faulet <cfaulet@haproxy.com>
FireBurn pushed a commit to FireBurn/haproxy that referenced this issue Jan 29, 2020
… directive

It is now possible to insert any attribute when a cookie is inserted by
HAProxy. Any value may be set, no check is performed except the syntax validity
(CTRL chars and ';' are forbidden). For instance, it may be used to add the
SameSite attribute:

    cookie SRV insert attr "SameSite=Strict"

The attr option may be repeated to add several attributes.

This patch should fix the issue haproxy#361.

(cherry picked from commit 2f53390)
Signed-off-by: Christopher Faulet <cfaulet@haproxy.com>
(cherry picked from commit fac5082)
Signed-off-by: Christopher Faulet <cfaulet@haproxy.com>
(cherry picked from commit db2cdbb)
Signed-off-by: Christopher Faulet <cfaulet@haproxy.com>
FireBurn pushed a commit to FireBurn/haproxy that referenced this issue Jan 29, 2020
… directive

It is now possible to insert any attribute when a cookie is inserted by
HAProxy. Any value may be set, no check is performed except the syntax validity
(CTRL chars and ';' are forbidden). For instance, it may be used to add the
SameSite attribute:

    cookie SRV insert attr "SameSite=Strict"

The attr option may be repeated to add several attributes.

This patch should fix the issue haproxy#361.

(cherry picked from commit 2f53390)
Signed-off-by: Christopher Faulet <cfaulet@haproxy.com>
@dmazurek
Copy link

dmazurek commented Feb 3, 2020

Here's a workaround if you can't upgrade: add a new frontend and backend in front of your listener that uses http-response replace-header to add the SameSite directive. For example:

frontend fe-samesite
    bind localhost:8080
    default_backend be-samesite

backend be-samesite
    server fe:8081 localhost:8081
    http-response replace-header Set-Cookie ^(sticky_cookie=.*) \1;\ SameSite=None

frontend fe
    bind localhost:8081
    default_backend be
    [...]

backend be
    server [...] cookie server1
    server [...] cookie server2
    cookie sticky_cookie insert secure
    [...]

This worked like a charm for me.

FireBurn pushed a commit to FireBurn/haproxy that referenced this issue Feb 4, 2020
… directive

It is now possible to insert any attribute when a cookie is inserted by
HAProxy. Any value may be set, no check is performed except the syntax validity
(CTRL chars and ';' are forbidden). For instance, it may be used to add the
SameSite attribute:

    cookie SRV insert attr "SameSite=Strict"

The attr option may be repeated to add several attributes.

This patch should fix the issue haproxy#361.

(cherry picked from commit 2f53390)
Signed-off-by: Christopher Faulet <cfaulet@haproxy.com>
(cherry picked from commit fac5082)
Signed-off-by: Christopher Faulet <cfaulet@haproxy.com>
(cherry picked from commit db2cdbb)
Signed-off-by: Christopher Faulet <cfaulet@haproxy.com>
(cherry picked from commit d76877d)
Signed-off-by: Christopher Faulet <cfaulet@haproxy.com>
(cherry picked from commit 1df4039)
[wt: adjusted context]
Signed-off-by: Willy Tarreau <w@1wt.eu>
(cherry picked from commit 7f31d8c)
Signed-off-by: Willy Tarreau <w@1wt.eu>
FireBurn pushed a commit to FireBurn/haproxy that referenced this issue Feb 4, 2020
… directive

It is now possible to insert any attribute when a cookie is inserted by
HAProxy. Any value may be set, no check is performed except the syntax validity
(CTRL chars and ';' are forbidden). For instance, it may be used to add the
SameSite attribute:

    cookie SRV insert attr "SameSite=Strict"

The attr option may be repeated to add several attributes.

This patch should fix the issue haproxy#361.

(cherry picked from commit 2f53390)
Signed-off-by: Christopher Faulet <cfaulet@haproxy.com>
(cherry picked from commit fac5082)
Signed-off-by: Christopher Faulet <cfaulet@haproxy.com>
(cherry picked from commit db2cdbb)
Signed-off-by: Christopher Faulet <cfaulet@haproxy.com>
(cherry picked from commit d76877d)
Signed-off-by: Christopher Faulet <cfaulet@haproxy.com>
(cherry picked from commit 1df4039)
[wt: adjusted context]
Signed-off-by: Willy Tarreau <w@1wt.eu>
@mathieu-veron
Copy link

quick question for you @dmazurek , why a new front and back is needed, from my understanding, replace-header could have been on existing backend. no ?

@panosziogas
Copy link

panosziogas commented Mar 19, 2020

Same question for me as @mathieu-veron above. Why can't we use the existing backend;

@lukastribus
Copy link
Member

@mathieu-veron @panosziogas no, you cannot use the existing backend, because http-response replace-header works for headers that come from a backend's response, not for locally emitted headers like cookies that haproxy emits.

@anne01-code
Copy link

We running still haproxy 1.8.23 and are not able to use
cookie SRV insert secure attr "SameSite=Strict".

Is it also possible meanwhile to use in the backend:

rspirep ^(set-cookie:.*) \1;\ SameSite=None\ Secure

and is it syntax correct??

@anne01-code
Copy link

For the backend I used the following syntax

rspirep ^(set-cookie:.*) \1;\ SameSite=None;Secure

and this works fine to me.

In the meantime we need to upgrade to vs 1.8.24. So we can use the cookie option

@vpnsecure
Copy link

Chrome DevTools shows the following is working when inserting a new cookie.
cookie SRV insert secure attr "SameSite=None"
How do I add secure SameSite=None to all of the cookies emitted by the back-end server?

@Artemiy555
Copy link

Hi. Can add attr and domain?
So that there is no rewriting.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type: feature This issue describes a feature request / wishlist.
Projects
None yet
Development

No branches or pull requests