Skip to content

The CSRF cookie is not set when opening a page through an iframe #1523

Closed
@pr0head

Description

@pr0head

Issue Description

There is no way to change SameSite mode when setting CSRF cookies.

Checklist

  • Dependencies installed
  • No typos
  • Searched existing issues and docs

Expected behaviour

Successfully setting CSRF cookie when opening a page through an iframe.

Actual behaviour

Cannot install CSRF via iframe. The browser reports an error:
This set-cookie didn't specify a SameSite attribute and was defaulted to SameSite=Lax and broke the same rules specified in the SameSiteLax value.

Steps to reproduce

Activate the SameSite experimental mode in Google Chrome (which will be turned on by default soon) and try to open the page through the iframe.

How to enable: https://www.chromium.org/updates/same-site/test-debug
What is a problem: https://web.dev/samesite-cookies-explained/

Working code to debug

server.Echo.Use(middleware.CSRFWithConfig(middleware.CSRFConfig{
	TokenLookup: "header:X-XSRF-TOKEN",
	CookieName:  "_csrf",
}))

Version/commit

v4.1.15

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions