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

[WIP] Update secure-headers align with best current practice #2543

Open
wants to merge 5 commits into
base: main
Choose a base branch
from

Conversation

Jxck
Copy link
Contributor

@Jxck Jxck commented Apr 23, 2024

closes: #2540

update headers in secure-headers middleware align with best practices.

  1. Referrer-Policy to strict-origin-when-cross-origin
    as I filed default referrer-policy for secure-headers middleware #2540 , no-referer also make origin header to null.
    origin header is important for avoid unexpected api call from browser (which includes CSRF).
    there are no reason to hide referrer from same-origin, so change it to reasonable setting.
    strict-origin-when-cross-origin is currently default for modern browsers, but explicitly set it is fine.

see also: https://cheatsheetseries.owasp.org/cheatsheets/HTTP_Headers_Cheat_Sheet.html#referrer-policy

  1. don't use x-xss-protection
     
    x-xss-protection is not fully standardized, deprecated, not recommended header. xss filter is depreacted on all browser so there are no reason to serve it even if it intends to disable since there is no guarantee 0 behaves as expected. use CSP instead.

see also: https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/X-XSS-Protection

  1. user QPAC registered value. it compress this header field in 1byte on QUIC

there are no reason to shorten Strict-Transport-Security 's max-age.
so what is the appropriate value ? => anything long value is fine basically.
in this case you can see the QPACK static table.
https://www.rfc-editor.org/rfc/rfc9204.html#name-static-table-2
the basic values are defined in this table, and qpack will compress it in 1byte on quic transport.

56	strict-transport-security	max-age=31536000
57	strict-transport-security	max-age=31536000; includesubdomains
58	strict-transport-security	max-age=31536000; includesubdomains; preload

57 is fine here.

  1. X-Frame-Options are replaced by frame-ancestors in CSP.

it's widely supported in browsers and allow more appropriate directive to customize.

And more.

Basically, "kichen-sink" headers are kind of bad practice.
From point of view of that, the headers below are also ignorable for me.
since only for old browser, or the Risks are not clear (secure for who ?).

X-Download-Options: noopen: it's for deprecated IE
X-Permitted-Cross-Domain-Policies: none': it's for deprecated Flash / Silverlight

I don't know it's really required. but don't have strong opinion to delete thought.

Author should do the followings, if applicable

  • Add tests
  • Run tests
  • yarn denoify to generate files for Deno

…ed header. xss filter is depreacted on all browser so there are no reason to serve it even if it intends to disable since there is no guarantee `0` behaves as expected. use in CSP
… with compatible status among browsers and allow more appropriate directive to customise
@watany-dev
Copy link
Contributor

watany-dev commented Apr 23, 2024

This is just an idea, but to avoid breaking changes, it might be good to create and operate options like "useHelmetDefault" or "useHonoDefault".

  • v4.x
// To select a default value that includes this change
app.use(
  '*',
  secureHeaders({
    useHonoDefault: true // Experimental and deprecate v5.0 
  })
)
  • 5.x
// To select a current default value
app.use(
  '*',
  secureHeaders({
    useHelmetDefault: true
  })
)

or

import { honoHelmet } from 'hono/secure-headers'
app.use(honoHelmet())

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.

default referrer-policy for secure-headers middleware
2 participants