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: strict-dynamic not working on Next 12.2 - internal redesign #38

Merged
merged 7 commits into from
Jul 7, 2022

Conversation

nibtime
Copy link
Owner

@nibtime nibtime commented Jul 6, 2022

Fixes #37

@vercel
Copy link

vercel bot commented Jul 6, 2022

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Updated
next-safe-middleware ✅ Ready (Inspect) Visit Preview Jul 7, 2022 at 6:00PM (UTC)

@changeset-bot
Copy link

changeset-bot bot commented Jul 6, 2022

🦋 Changeset detected

Latest commit: d683cd1

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 2 packages
Name Type
@next-safe/middleware Minor
e2e Minor

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@nibtime nibtime changed the title strict-dynamic not working on Next 12.2 fix: strict-dynamic not working on Next 12.2 Jul 6, 2022
@vercel vercel bot temporarily deployed to Preview July 6, 2022 09:28 Inactive
@philhack
Copy link

philhack commented Jul 7, 2022

Fixes #37

Huge thank you for implementing this @nibtime !!!
I'm wondering when it will be merged and if you need any assistance?

Thanks!

Commit generated via `yarn stage`
Commit generated via `yarn stage`
Next 12.2 single middleware runs on everything, so the `chainMatch`
abstraction with bailout from requests by predicate is necessary
to run CSP/Security middleware on page request only.

`continued` function can turn a regular middleware into a chainable
to continue its response in another middleware chain
`req.page.name` ist deprecated, so there is no longer a way to access
the file system route name in middleware (was not 100% reliable anyway).
There is no replacement, so a redesign was necessary

shift towards a single, "Static CSP Manifest" design, where all
CSP sources (hashes) are collected and cached into single file(s).

writing CSP sources (hashes) to txt at build time is done with lockfile semaphore,
like it should have been from the beginning, as multiple workers have to
write to the same file.

The change should be non-breaking for versions < 12.2, as interfaces
stayed the same, just the underlying way the hashes get into the CSP
has changed

Nonce-based is now completely handled in `getCspInitialProps` for dynamic pages
adapt to updated recommendation of `next/script` usage.
Scripts with `beforeInteractive` have to be placed in `_document` now:
https://nextjs.org/docs/basic-features/script#beforeinteractive

For inline scripts that need to load beforeInteractive, can be put
as directly as children of `<Head>` in _document and will automatically
hashed/nonced
update infos in package.json
@nibtime nibtime changed the title fix: strict-dynamic not working on Next 12.2 fix: strict-dynamic not working on Next 12.2 - internal redesign Jul 7, 2022
@vercel vercel bot temporarily deployed to Preview July 7, 2022 18:00 Inactive
@nibtime nibtime merged commit b4a6e11 into main Jul 7, 2022
@nibtime nibtime deleted the nibtime/issue37 branch July 7, 2022 18:09
@github-actions github-actions bot mentioned this pull request Jul 7, 2022
@nibtime
Copy link
Owner Author

nibtime commented Jul 9, 2022

Hi @philhack

thanks for the offer to help out! I released 0.8.0 to NPM yesterday that works for 12.2.

Currently, I am trying to shift code out of the PoC state bit by bit towards the first major version, which only now makes sense, that middleware itself is stable. I also didn't think that there would be people who like to use this :D

Very essential is also #42, any good ideas there are most welcome.

Cheers!

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.

strict-dynamic not working on Next 12.2
2 participants