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

[Bug?]: createHandler context only called once, renders nonce useless #1441

Closed
2 tasks done
paularmstrong opened this issue Apr 8, 2024 · 1 comment
Closed
2 tasks done
Labels
bug Something isn't working

Comments

@paularmstrong
Copy link
Contributor

paularmstrong commented Apr 8, 2024

Duplicates

  • I have searched the existing issues

Latest version

  • I have tested the latest version

Current behavior 😯

Related to #1440

In production mode, the options object passed to createHandler is only ever evaluated once on startup (or maybe first request?). This renders setting a nonce in the context useless, because it will always be the same value.

Expected behavior 🤔

If the HandlerOptions is a function, it should be executed for every page event/request and not done on initial startup.

Steps to reproduce 🕹

Steps:

Create the entry-server with an function (async or not) that gets and returns a unique nonce value:

export default createHandler(
  (context) => {
    return <StartServer>{/* ... */}</StartServer>;
  },
  async (event: PageEvent) => {
    await getNonce(context);
    return { nonce };
  }
);

View page output and notice that the nonce never changes.

Important

This is only reproducible when the server is built and run – it does NOT reproduce in dev mode.

Context 🔦

https://content-security-policy.com/nonce/

Your environment 🌎

n/a
@paularmstrong paularmstrong added the bug Something isn't working label Apr 8, 2024
@paularmstrong
Copy link
Contributor Author

Thank you @ryansolid ! I was having a tough time tracking this down today

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

1 participant