nuxt-modules / security

🛡 Automatically configure your app to follow OWASP security patterns and principles by using HTTP Headers and Middleware
https://nuxt-security.vercel.app/
MIT License
829 stars 60 forks source link

feat(core): crypto compatibility for Workers #547

Closed vejja closed 2 weeks ago

vejja commented 2 weeks ago

Resolves #541

Types of changes

Description

This PR replaces the NodeJS cryptographic primitives used in this codebase by their equivalents from the Javascript WebCrypto API.

The fundamental reason for this rewrite is to provide full compatibility with Worker-based environments, where Node's crypto module might not always be available.

The issue was first raised with Cloudflare's Workers. While manual configuration of Cloudflare worker settings (via their nodejs_compatibility flag) is possible, we believe it is better to offer a universal approach that will offer strong cryptographic guarantees in all environments.

Note: as part of this update, the NodeJS minimal version needs to be updated to v20. This is required to ensure that crypto is available in the global scope.

Checklist:

vercel[bot] commented 2 weeks ago

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

Name Status Preview Comments Updated (UTC)
nuxt-security ✅ Ready (Inspect) Visit Preview 💬 Add feedback Nov 11, 2024 5:35pm
vejja commented 2 weeks ago

@Baroshem for some reason I had troubles rebasing the branch onto 2.1.0 - sorrry the commit timeline looks awful, but actually the amount of changes is very small

vejja commented 2 weeks ago

Hey Jakub, I tested it on a private repo that @brewaa provided, and it works on Cloudflare. Will merge