Skip to content

security: harden CSPRNG, SQL injection guard, error handling, and info disclosure#58

Merged
ernysans merged 3 commits into
mainfrom
copilot/security-review-vulnerability-patch
Jun 17, 2026
Merged

security: harden CSPRNG, SQL injection guard, error handling, and info disclosure#58
ernysans merged 3 commits into
mainfrom
copilot/security-review-vulnerability-patch

Conversation

Copilot AI commented Jun 17, 2026

Copy link
Copy Markdown
Contributor

Defensive security pass across src/ addressing six distinct vulnerability classes without altering public API behavior.

Changes

Insecure Randomness (hash-id.ts)

Replaced Math.random() with crypto.randomInt(). The module is documented as suitable for one-time codes — it must use a CSPRNG.

SQL Injection via Identifier Interpolation (cleaner.ts)

dataset, table, timestamp, and column were interpolated directly into a BigQuery DML template literal. Added validateIdentifier() enforcing ^[a-zA-Z_][a-zA-Z0-9_]*$ on all four before SQL is built.

// Before — no validation:
return `DELETE FROM \`${filter.dataset}.${filter.table}\` WHERE STRUCT(id, ${filter.timestamp} ...`;

// After — identifier validated first:
validateIdentifier(filter.dataset, 'dataset');
validateIdentifier(filter.table, 'table');
validateIdentifier(filter.timestamp, 'timestamp');

Unguarded JSON.parse (global.ts)

getPublicUrl and getUrlAndGs called JSON.parse(process.env.FIREBASE_CONFIG) with no error handling — a missing or malformed env var produced cryptic SyntaxError crashes. Extracted a parseFirebaseConfig() helper that validates presence and catches parse errors with descriptive messages.

Non-JSON Error Body (api-request.ts)

response.json() in the non-ok path had no fallback; a non-JSON error body would surface an unhandled SyntaxError. Wrapped in try/catch with 'unknown error' fallback. Also removed a console.log that leaked content-type headers on every request.

User Input in Error Messages (validate-url.ts)

throw new Error(\Invalid URL: ${url}`)reflected raw user input into error messages, enabling log injection. Simplified tothrow new Error('Invalid URL')`.

Primitive String Throws (user.ts)

Two catch blocks used throw \template literal`— losing stack traces and breakinginstanceof Errorchecks. Both now usethrow new Error(message, { cause: error })`.

@ernysans
ernysans marked this pull request as ready for review June 17, 2026 12:52
@ernysans
ernysans merged commit 8c17a29 into main Jun 17, 2026
2 checks passed
@ernysans
ernysans deleted the copilot/security-review-vulnerability-patch branch June 17, 2026 12:52
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants