-
Notifications
You must be signed in to change notification settings - Fork 65
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
feat(core): Security Headers for Pre-rendered Routes #441
Conversation
- are now available in SSR - are also avaiable for Nitro preset deployments
The latest updates on your projects. Learn more about Vercel for Git ↗︎
|
Hi @vejja Thanks for this amazing PR! I needed to first release your other PR with SRI fix and it caused the conflicts in this PR. Could you please rebase it? :) Also, regarding the release of this feature, I would aim for 1.5.0 next week probably if that is ok with you? :) I will also review it in the upcoming days to give you some feedback. |
1.5.0 sounds good |
I'm also closing #434 with this PR |
- Delivers eligible security headers for all resources when possible - Fix unbuild configuration to allow shared utils between module.ts and runtime
@Baroshem |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Two small nitpicks, overall really great work!
Amazing work @vejja ! I will merge it to the 2.0.0-rc.1 branch where we can do some additional testing and prepare a big release soon :) |
Types of changes
Description
With this PR, security headers
Previously, when a route was pre-rendered via
routeRules
, the Nuxt application could not deliver the Security Headers. This is because the HTML page is served directly as a pre-built static asset, and we could not intercept the headers in that case to modify them.This PR proposes a modification of the core engine of Nuxt Security, whereby we now record all pre-rendered pages at build time, and then intercept all requests to verify whether they correspond to a pre-rendered page.
As a consequence of this core upgrade, we now deliver five additional features:
meta
tag. This addresses the issue where some security scanners are complaining about CSP compliance because they do not check themeta
tag.meta
tag, but now all other policies (e.g. COEP, STS, etc...) can also be delivered via headers for pre-rendered pages in Hybrid Mode.cspSsgPresets
feature, which had to be deactivated after the upgrade to Nuxt 3.9.3 caused issue "This module cannot be imported in server runtime" error on fresh Nuxt install #348. With this feature, we now generate aheaders.json
file that is used by Nitro in static presets. For instance, a static website deployed on Vercel or Netlify now has security headers natively on all pages, even without a server runtime !nuxt-security:prerenderedHeaders
build-time hook, which allows to further extend the previous feature when there is no Nitro preset available. This hook can be used to manually generate a headers configuration file for any custom static deployment..js
or.css
files, api requests, etc. The following headers are now delivered on all resources:referrerPolicy
,strictTransportSecurity
,xContentTypeOptions
,xDownloadOptions
,xFrameOptions
,xPermittedCrossDomainPolicies
, andxXSSProtection
.Please note that :
ssg: nitroHeaders
option (defaulttrue
). This option is modifiable both globally and at route-level.ssg: exportToPresets
option (defaulttrue
). This option is only available globally.Closes #386
Closes #409
Closes #434
Checklist: