refactor: consolidate multiple passwords into a single master password for frontend actions - #307
Conversation
…d for frontend actions
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
📝 WalkthroughWalkthroughAction-specific passwords are consolidated into ChangesUI Master Password Consolidation
Estimated code review effort: 3 (Moderate) | ~20 minutes Possibly related PRs
Suggested reviewers: 🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
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 |
There was a problem hiding this comment.
Actionable comments posted: 1
🧹 Nitpick comments (2)
packages/server/src/utils/validatePassword.ts (1)
35-38: 🔒 Security & Privacy | 🔵 Trivial | ⚡ Quick winUse
crypto.timingSafeEqualfor password comparison.Both
validateDriverUpdatePasswordandvalidateSnapshotPassworduse===, which short-circuits on the first mismatched byte and leaks timing information. SincevalidateSnapshotPasswordwas rewritten in this PR, this is a good opportunity to adopt a timing-safe comparison. Note that both functions are now identical (password === validPassword), so a single sharedvalidateMasterPasswordfunction would eliminate the duplication.♻️ Proposed refactor: timing-safe shared validation
+import crypto from "crypto"; + const validPassword = process.env.MASTER_PASSWORD; if (!validPassword) { throw new Error("MASTER_PASSWORD environment variable is not configured"); } +function safeCompare(input: string, expected: string): boolean { + const a = Buffer.from(input); + const b = Buffer.from(expected); + if (a.length !== b.length) return false; + return crypto.timingSafeEqual(a, b); +} + +export function validateMasterPassword(password: string): boolean { + return safeCompare(password, validPassword); +} + export function validateDriverUpdatePassword(password: string): boolean { - return password === validPassword; + return validateMasterPassword(password); } export function validateSnapshotPassword(password: string): boolean { - return password === validPassword; + return validateMasterPassword(password); }🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@packages/server/src/utils/validatePassword.ts` around lines 35 - 38, `validateSnapshotPassword` currently compares passwords with `===`, which is not timing-safe and duplicates the same logic used by `validateDriverUpdatePassword`. Update the password validation path in `validatePassword.ts` to use `crypto.timingSafeEqual` on byte buffers, and factor the shared comparison into a single `validateMasterPassword` helper that both `validateDriverUpdatePassword` and `validateSnapshotPassword` call.packages/amplify/amplify/backend.ts (1)
220-222: 🔒 Security & Privacy | 🔵 TrivialUpdate the AWS
HeliosPasswordssecret before deployment.The
HeliosPasswordssecret in AWS Secrets Manager must contain aMASTER_PASSWORDkey. The old keys (DRIVER_NAME_UPDATE_PASSWORD,FINISH_LINE_UPDATE_PASSWORD,SNAPSHOT_PASSWORD) can be removed after confirming all services have been redeployed with this change. Consider a staged rollout: addMASTER_PASSWORDfirst, deploy, then remove old keys.🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@packages/amplify/amplify/backend.ts` around lines 220 - 222, The `HeliosPasswords` Secrets Manager entry must be updated to include `MASTER_PASSWORD` before this `backend.ts` change is deployed, since `ecs.Secret.fromSecretsManager` now reads that key. Add `MASTER_PASSWORD` to the secret first, verify deployment succeeds, and only then remove the legacy keys (`DRIVER_NAME_UPDATE_PASSWORD`, `FINISH_LINE_UPDATE_PASSWORD`, `SNAPSHOT_PASSWORD`) after all services have been rolled out with the new secret name.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@packages/server/src/controllers/LapController/LapController.ts`:
- Around line 140-141: LapController is comparing against
process.env.MASTER_PASSWORD inline and logging the submitted password, so switch
the check to the shared validatePassword utility (or a shared
validateMasterPassword/validateFinishLinePassword helper) used by
validatePassword.ts, and ensure the env var is validated at module load instead
of call time. Update the password failure path in LapController to use that
shared validator and redact the provided password from logger.error so no secret
value is emitted.
---
Nitpick comments:
In `@packages/amplify/amplify/backend.ts`:
- Around line 220-222: The `HeliosPasswords` Secrets Manager entry must be
updated to include `MASTER_PASSWORD` before this `backend.ts` change is
deployed, since `ecs.Secret.fromSecretsManager` now reads that key. Add
`MASTER_PASSWORD` to the secret first, verify deployment succeeds, and only then
remove the legacy keys (`DRIVER_NAME_UPDATE_PASSWORD`,
`FINISH_LINE_UPDATE_PASSWORD`, `SNAPSHOT_PASSWORD`) after all services have been
rolled out with the new secret name.
In `@packages/server/src/utils/validatePassword.ts`:
- Around line 35-38: `validateSnapshotPassword` currently compares passwords
with `===`, which is not timing-safe and duplicates the same logic used by
`validateDriverUpdatePassword`. Update the password validation path in
`validatePassword.ts` to use `crypto.timingSafeEqual` on byte buffers, and
factor the shared comparison into a single `validateMasterPassword` helper that
both `validateDriverUpdatePassword` and `validateSnapshotPassword` call.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: defaults
Review profile: CHILL
Plan: Pro
Run ID: 21b045e8-01d8-46c8-a6b0-7d08ee9fcc82
📒 Files selected for processing (4)
packages/amplify/amplify/backend.tspackages/server/.env.examplepackages/server/src/controllers/LapController/LapController.tspackages/server/src/utils/validatePassword.ts
…e master password function
f161643
There was a problem hiding this comment.
🧹 Nitpick comments (1)
packages/server/src/utils/validatePassword.ts (1)
30-32: 🔒 Security & Privacy | 🔵 Trivial | ⚡ Quick winConsider a constant-time comparison for the password check.
password === validPasswordshort-circuits on the first differing byte, leaking length/prefix timing. For a credential check, prefer a constant-time comparison (e.g.crypto.timingSafeEqualover equal-length buffers) to reduce timing side-channel risk.🔒 Proposed constant-time comparison
+import { timingSafeEqual } from "crypto"; + export function validateMasterPassword(password: string): boolean { - return password === validPassword; + const a = Buffer.from(String(password)); + const b = Buffer.from(String(validPassword)); + return a.length === b.length && timingSafeEqual(a, b); }Please confirm the Node runtime target supports
crypto.timingSafeEqual(Node ≥ 6.6) in this package.🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@packages/server/src/utils/validatePassword.ts` around lines 30 - 32, Update validateMasterPassword to use Node’s crypto.timingSafeEqual with equal-length buffers for comparing password and validPassword, handling differing lengths without calling the API on mismatched buffers. Confirm the package targets a Node runtime that supports timingSafeEqual, while preserving the boolean validation result.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Nitpick comments:
In `@packages/server/src/utils/validatePassword.ts`:
- Around line 30-32: Update validateMasterPassword to use Node’s
crypto.timingSafeEqual with equal-length buffers for comparing password and
validPassword, handling differing lengths without calling the API on mismatched
buffers. Confirm the package targets a Node runtime that supports
timingSafeEqual, while preserving the boolean validation result.
ℹ️ Review info
⚙️ Run configuration
Configuration used: defaults
Review profile: CHILL
Plan: Pro
Run ID: 8d3b1637-de82-4115-9d77-6bde2273c9e5
📒 Files selected for processing (6)
packages/amplify/amplify/backend.tspackages/server/.env.examplepackages/server/src/controllers/LapController/LapController.tspackages/server/src/controllers/routeControllers/driver.controller.tspackages/server/src/controllers/routeControllers/snapshot.controller.tspackages/server/src/utils/validatePassword.ts
✅ Files skipped from review due to trivial changes (1)
- packages/server/.env.example
🚧 Files skipped from review as they are similar to previous changes (1)
- packages/amplify/amplify/backend.ts
Summary by CodeRabbit
New Features
Bug Fixes