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

fix(gatsby-plugin-netlify): Add Referrer-Policy to security headers #13452

Conversation

browniebroke
Copy link
Contributor

@browniebroke browniebroke commented Apr 18, 2019

Description

Add 'Referrer-Policy: same-origin' to SECURITY_HEADERS.

This is one of the headers checked by securityheaders.com and currently it's not included by Gatsby by default. I was adding it to a few of my projects, but I realised it could probably be added upstream, so here it is.

Looking around, it seems that 'same-origin' is a good default, but I don't feel strongly about it. Would this be welcome?

Related Issues

Add 'Referrer-Policy: same-origin' to SECURITY_HEADERS.
@browniebroke browniebroke marked this pull request as ready for review April 18, 2019 14:33
Copy link
Contributor

@sidharthachatterjee sidharthachatterjee left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a welcome addition and same-origin is a good default to have! Thank you so much @browniebroke and congratulations on your first contribution! 🥇

@sidharthachatterjee sidharthachatterjee changed the title Add Referrer-Policy to security headers fix(gatsby-plugin-netlify): Add Referrer-Policy to security headers Apr 18, 2019
@sidharthachatterjee sidharthachatterjee merged commit 871923a into gatsbyjs:master Apr 18, 2019
@gatsbot
Copy link

gatsbot bot commented Apr 18, 2019

Holy buckets, @browniebroke — we just merged your PR to Gatsby! 💪💜

Gatsby is built by awesome people like you. Let us say “thanks” in two ways:

  1. We’d like to send you some Gatsby swag. As a token of our appreciation, you can go to the Gatsby Swag Store and log in with your GitHub account to get a coupon code good for one free piece of swag. (Currently we’ve got a couple t-shirts available, plus some socks that are really razzing our berries right now.)
  2. We just invited you to join the Gatsby organization on GitHub. This will add you to our team of maintainers. Accept the invite by visiting https://github.com/orgs/gatsbyjs/invitation. By joining the team, you’ll be able to label issues, review pull requests, and merge approved pull requests.

If there’s anything we can do to help, please don’t hesitate to reach out to us: tweet at @gatsbyjs and we’ll come a-runnin’.

Thanks again!

@sidharthachatterjee
Copy link
Contributor

Published in [email protected]

@browniebroke browniebroke deleted the security-headers/referrer-policy branch April 24, 2019 12:55
@rmehner
Copy link
Contributor

rmehner commented May 10, 2019

This is actually a breaking change for us and it took me a while to find this.

We use a map image provider who doesn't use an API key but the referrer to regulate access. This stopped working for us, as it's not same-origin and we'd need no-referrer-when-downgrade at minimum.

It's easy to fix by adjusting the gatsby-config:

{
  resolve: 'gatsby-plugin-netlify',
  options: {
    headers: {
      '/*': [`Referrer-Policy: no-referrer-when-downgrade`],
    },
  },
},

Should have checked the release notes more thoroughly before updating the package :)

@rmehner
Copy link
Contributor

rmehner commented May 10, 2019

Turns out my fix is wrong, as it will create the header as:

referrer-policy: no-referrer-when-downgrade, same-origin

I'll change it to this:

{
      resolve: 'gatsby-plugin-netlify',
      options: {
        mergeSecurityHeaders: false,
        headers: {
          '/*': [
            `X-Frame-Options: DENY`,
            `X-XSS-Protection: 1; mode=block`,
            `X-Content-Type-Options: nosniff`,
            `Referrer-Policy: no-referrer-when-downgrade`,
          ],
        },
      },
    },```

@jlev
Copy link

jlev commented Feb 6, 2023

This broke API access for me as well that relied on referer headers. Not a good default, would suggest origin-when-cross-origin instead

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants