-
Notifications
You must be signed in to change notification settings - Fork 0
Revert password changes #309
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -3,7 +3,7 @@ import type { BackendController } from "../BackendController/BackendController"; | |
| import { type Request, type Response } from "express"; | ||
|
|
||
| import { createApplicationLogger } from "@/utils/logger"; | ||
| import { validateMasterPassword } from "@/utils/validatePassword"; | ||
| import { validateSnapshotPassword } from "@/utils/validatePassword"; | ||
|
|
||
| import type { | ||
| CreateSnapshotRequestDTO, | ||
|
|
@@ -82,7 +82,7 @@ export const createSnapshot = async ( | |
| .json({ error: "snapshot_from and snapshot_to must be valid ISO date strings" }); | ||
| } | ||
|
|
||
| if (!validateMasterPassword(password)) { | ||
| if (!validateSnapshotPassword(password)) { | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🩺 Stability & Availability | 🟡 Minor | ⚡ Quick win 🧩 Analysis chain🏁 Script executed: #!/bin/bash
# Check the asyncHandler implementation and error-handling middleware to verify
# whether raw error messages are sanitized before reaching the client.
rg -nC5 "asyncHandler" --type=ts packages/server/src/
rg -nC5 "error.*handler\|ErrorHandler\|err.*req.*res" --type=ts packages/server/src/ -g '!**/node_modules/**'Repository: UCSolarCarTeam/Helios-Telemetry Length of output: 5895 🏁 Script executed: #!/bin/bash
set -euo pipefail
echo "== errorHandler implementation =="
cat -n packages/server/src/middleware/errorHandler.ts
echo
echo "== snapshot controller around validateSnapshotPassword =="
rg -nC6 "validateSnapshotPassword|createSnapshot|SNAPSHOT_PASSWORD" packages/server/src/controllers/routeControllers/snapshot.controller.ts
echo
echo "== server/app wiring for error middleware =="
rg -nC4 "app.use\\(|errorHandler|asyncHandler|express\\(" packages/server/src -g '!**/node_modules/**'
echo
echo "== startup validation for driver update password =="
rg -nC6 "validateDriverUpdatePassword|DRIVER_UPDATE_PASSWORD|throw new Error" packages/server/srcRepository: UCSolarCarTeam/Helios-Telemetry Length of output: 23647 Avoid returning the missing-secret error to clients. 🤖 Prompt for AI Agents |
||
| logger.warn("Invalid password attempt for snapshot creation"); | ||
| return response.status(401).json({ error: "Invalid password" }); | ||
| } | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,7 +1,7 @@ | ||
| const validPassword = process.env.UI_MASTER_PASSWORD; | ||
| const validPassword = process.env.MQTT_PASSWORD; | ||
|
|
||
| if (!validPassword) { | ||
| throw new Error("UI_MASTER_PASSWORD environment variable is not configured"); | ||
| throw new Error("MQTT_PASSWORD environment variable is not configured"); | ||
|
Comment on lines
+1
to
+4
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🔒 Security & Privacy | 🟠 Major | ⚡ Quick win 🧩 Analysis chain🏁 Script executed: #!/bin/bash
# Verify that DRIVER_NAME_UPDATE_PASSWORD is not referenced anywhere in the application code.
rg -n "DRIVER_NAME_UPDATE_PASSWORD" --type=ts -g '!**/*.env*' -g '!**/backend.ts'
# Also check if MQTT_PASSWORD is referenced beyond MQTT connection setup.
rg -nC3 "MQTT_PASSWORD" --type=ts -g '!**/*.env*' -g '!**/backend.ts'Repository: UCSolarCarTeam/Helios-Telemetry Length of output: 169 🏁 Script executed: #!/bin/bash
set -euo pipefail
printf '\n== validatePassword.ts ==\n'
git ls-files 'packages/server/src/utils/validatePassword.ts' 'packages/server/src/**' | cat
echo
wc -l packages/server/src/utils/validatePassword.ts 2>/dev/null || true
echo
cat -n packages/server/src/utils/validatePassword.ts 2>/dev/null || true
printf '\n== References to DRIVER_NAME_UPDATE_PASSWORD ==\n'
rg -n -S "DRIVER_NAME_UPDATE_PASSWORD" .
printf '\n== References to MQTT_PASSWORD ==\n'
rg -n -C 3 -S "MQTT_PASSWORD" packages/server/src .Repository: UCSolarCarTeam/Helios-Telemetry Length of output: 9672
🤖 Prompt for AI AgentsSource: Linters/SAST tools |
||
| } | ||
|
|
||
| /** | ||
|
|
@@ -12,21 +12,32 @@ if (!validPassword) { | |
| */ | ||
|
|
||
| /** | ||
| * Validates a password against the shared master password. | ||
| * Validates the driver update password against the configured environment variable. | ||
| * | ||
| * Used by sensitive operations. Backed by the UI_MASTER_PASSWORD environment | ||
| * variable. | ||
| * This password is required for sensitive operations like updating driver information | ||
| * in the database. The password is stored in the MQTT_PASSWORD environment variable. | ||
| * | ||
| * @param password - The password to validate | ||
| * @returns true if the password matches the configured password, false otherwise | ||
| * | ||
| * @example | ||
| * ```typescript | ||
| * if (!validateMasterPassword(req.body.password)) { | ||
| * if (!validateDriverUpdatePassword(req.body.password)) { | ||
| * return res.status(401).json({ error: "Invalid password" }); | ||
| * } | ||
| * ``` | ||
| */ | ||
| export function validateMasterPassword(password: string): boolean { | ||
| export function validateDriverUpdatePassword(password: string): boolean { | ||
| return password === validPassword; | ||
| } | ||
|
|
||
| /** | ||
| * Validates the snapshot management password against SNAPSHOT_PASSWORD env var. | ||
| */ | ||
| export function validateSnapshotPassword(password: string): boolean { | ||
| const snapshotPassword = process.env.SNAPSHOT_PASSWORD; | ||
| if (!snapshotPassword) { | ||
| throw new Error("SNAPSHOT_PASSWORD environment variable is not configured"); | ||
| } | ||
| return password === snapshotPassword; | ||
| } | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🔒 Security & Privacy | 🟠 Major | ⚡ Quick win
Password is logged in the error message and the env-var check is fail-open.
Two issues on this password check:
CWE-532 — Sensitive data in logs:
logger.error("Invalid Password: " + password)logs the raw password value. The other controllers (driver.controller.ts,snapshot.controller.ts) log a generic "Invalid password attempt" message without the value. This is inconsistent and leaks credentials to log files.Fail-open when
FINISH_LINE_UPDATE_PASSWORDis unset: The raw comparisonpassword !== process.env.FINISH_LINE_UPDATE_PASSWORDpasses if both sides areundefined(env var not configured + missing password in payload). UnlikevalidateSnapshotPasswordwhich throws when the env var is missing, this check silently allows access.🔒 Proposed fix: remove password from log and guard against unset env var
const { lat, long, password } = newCoordInfo; - if (password !== process.env.FINISH_LINE_UPDATE_PASSWORD) { - logger.error("Invalid Password: " + password); + const finishLinePassword = process.env.FINISH_LINE_UPDATE_PASSWORD; + if (!finishLinePassword || password !== finishLinePassword) { + logger.error("Invalid password attempt for finish line update"); return { error: "Invalid Password", invalidFields: ["password"] }; }📝 Committable suggestion
🧰 Tools
🪛 ast-grep (0.44.1)
[warning] 140-140: Avoid logging sensitive data
Context: logger.error("Invalid Password: " + password)
Note: [CWE-532] Insertion of Sensitive Information into Log File.
(log-sensitive-data-typescript)
🤖 Prompt for AI Agents
Source: Linters/SAST tools