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

Generated nonce for secure headers middleware uses NodeJS Buffer API #2725

Closed
rmarscher opened this issue May 19, 2024 · 1 comment · Fixed by #2761
Closed

Generated nonce for secure headers middleware uses NodeJS Buffer API #2725

rmarscher opened this issue May 19, 2024 · 1 comment · Fixed by #2761
Labels
enhancement New feature or request. v4.4

Comments

@rmarscher
Copy link

rmarscher commented May 19, 2024

What is the feature you are proposing?

I would like to use the secure headers NONCE value using only web platform APIs. It currently uses Buffer.from() to convert the data to base64.

With Cloudflare Workers, that requires enabling nodejs_compat.

oslo.js contains an alternate implementation that does not require NodeJS APIs. It works for me, but I can understand you might not want to add a new dependency.

import { base64 } from "oslo/encoding"

const generateNonce = () => {
  const buffer = new Uint8Array(16)
  crypto.getRandomValues(buffer)
  return base64.encode(buffer)
}

It may be possible to use a different Buffer or base64 polyfill.

@rmarscher rmarscher added the enhancement New feature or request. label May 19, 2024
@yusukebe
Copy link
Member

yusukebe commented May 19, 2024

Hi @rmarscher

Thanks. This will be fixed in the next minor release. Please wait a bit.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request. v4.4
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants