fix(root): generate encryption envs in scripts#10449
fix(root): generate encryption envs in scripts#10449VitorPorf wants to merge 6 commits intonovuhq:nextfrom
Conversation
👷 Deploy request for dashboard-v2-novu-staging pending review.Visit the deploys page to approve it
|
📝 WalkthroughWalkthroughThe setup script now generates a random encryption key once per run and injects it into environment files by replacing Changes
Estimated code review effort🎯 2 (Simple) | ⏱️ ~10 minutes 🚥 Pre-merge checks | ✅ 3✅ Passed checks (3 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
6d39f92 to
c58d2e4
Compare
There was a problem hiding this comment.
🧹 Nitpick comments (1)
scripts/setup-env-files.js (1)
18-19: Consider usingreplaceAll()for robustness.
String.prototype.replace()only replaces the first occurrence. While current.example.envfiles appear to have a single placeholder, usingreplaceAll()would be more defensive against future changes.♻️ Suggested change
- if (content.includes(ENCRYPTION_KEY_PLACEHOLDER) && sharedEncryptionKey) { - content = content.replace(ENCRYPTION_KEY_PLACEHOLDER, sharedEncryptionKey); + if (sharedEncryptionKey && content.includes(ENCRYPTION_KEY_PLACEHOLDER)) { + content = content.replaceAll(ENCRYPTION_KEY_PLACEHOLDER, sharedEncryptionKey);🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@scripts/setup-env-files.js` around lines 18 - 19, The code currently uses content.replace(ENCRYPTION_KEY_PLACEHOLDER, sharedEncryptionKey) which only replaces the first occurrence; update the replacement to use content.replaceAll(ENCRYPTION_KEY_PLACEHOLDER, sharedEncryptionKey) (or an equivalent split/join fallback) so all placeholders in the content are replaced; reference the variables content, ENCRYPTION_KEY_PLACEHOLDER and sharedEncryptionKey in the change.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Nitpick comments:
In `@scripts/setup-env-files.js`:
- Around line 18-19: The code currently uses
content.replace(ENCRYPTION_KEY_PLACEHOLDER, sharedEncryptionKey) which only
replaces the first occurrence; update the replacement to use
content.replaceAll(ENCRYPTION_KEY_PLACEHOLDER, sharedEncryptionKey) (or an
equivalent split/join fallback) so all placeholders in the content are replaced;
reference the variables content, ENCRYPTION_KEY_PLACEHOLDER and
sharedEncryptionKey in the change.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Pro
Run ID: 7aea6e74-1708-4163-bd13-399d16dc66b9
📒 Files selected for processing (1)
scripts/setup-env-files.js
There was a problem hiding this comment.
Cursor Bugbot has reviewed your changes and found 1 potential issue.
❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.
Comment @cursor review or bugbot run to trigger another review on this PR
Reviewed by Cursor Bugbot for commit 1acbf11. Configure here.
scripts/setup-env-files.js
Outdated
| const sourcePath = path.resolve(`${folderBasePath}/${folder}/${exampleEnvFilePath}`); | ||
| let content = fs.readFileSync(sourcePath, 'utf8'); | ||
| if (content.includes(ENCRYPTION_KEY_PLACEHOLDER) && sharedEncryptionKey) { | ||
| content = content.replace(ENCRYPTION_KEY_PLACEHOLDER, sharedEncryptionKey); |
There was a problem hiding this comment.
replace only substitutes first placeholder occurrence
Low Severity
content.replace(ENCRYPTION_KEY_PLACEHOLDER, sharedEncryptionKey) only replaces the first occurrence of the placeholder. If an .example.env file ever contains the <ENCRYPTION_KEY_MUST_BE_32_LONG> placeholder on more than one line, subsequent occurrences will be left as literal placeholder text, silently breaking those env vars. Using replaceAll (or split/join) would match the intent of replacing every occurrence.
Reviewed by Cursor Bugbot for commit 1acbf11. Configure here.
…bstituting the <ENCRYPTION_KEY_MUST_BE_32_LONG> placeholder.
…/novu into fix/setup-env-generate-scripts


What changed? Why was the change needed?
The setup-env-files.js script was copying .example.env files directly to .env without replacing encryption key placeholders. The literal value <ENCRYPTION_KEY_MUST_BE_32_LONG> was left in the generated environment files, causing service startup errors on local setup.
Changes:
Added the crypto module to generate random keys
The script now generates a single sharedEncryptionKey per run (32-char hex via randomBytes(16))
During .example.env copy, the <ENCRYPTION_KEY_MUST_BE_32_LONG> placeholder is automatically replaced with the generated key
The same key is shared across all apps (api, ws, worker, dashboard) to ensure consistency between services
I opened a new PR because I accidentally uploaded local code, my mistake, I apologize.
What changed
The setup-env-files.js script now automatically generates a random 32-character encryption key during startup and replaces the placeholder
<ENCRYPTION_KEY_MUST_BE_32_LONG>in .example.env files when copying them to .env. Previously, the script copied example files verbatim, leaving the placeholder text in place and causing local startup failures. The same generated key is applied consistently across all services (api, ws, worker, dashboard) to ensure alignment between services during development setup.Affected areas
Key technical decisions
crypto.randomBytes(16).toString('hex')to generate secure random 32-character hex keysTesting
No tests added. This is a local development setup script; manual verification during local environment initialization is sufficient.
Note
Low Risk
Low risk because changes are limited to a local dev setup script, but it alters generated
.envcontents and could affect local startup if placeholder replacement is incorrect.Overview
The env setup script now generates a single random 32-character encryption key per run and injects it into newly created
.envfiles by replacing the<ENCRYPTION_KEY_MUST_BE_32_LONG>placeholder when copying from.example.env.It also switches from raw file copying to reading/writing the env file content so the same key is shared across
api,ws,worker, anddashboardduring local setup.Reviewed by Cursor Bugbot for commit 1acbf11. Configure here.