Security: Fix 4 vulnerabilities — API key exposure, unauthenticated endpoints, open proxy - #43
Draft
cursor[bot] wants to merge 3 commits into
Draft
Security: Fix 4 vulnerabilities — API key exposure, unauthenticated endpoints, open proxy#43cursor[bot] wants to merge 3 commits into
cursor[bot] wants to merge 3 commits into
Conversation
Prevents accidental commit of .env.local and other secret-bearing environment files from workers/silverback-ai-studio/ and repo root. The the-unit/api/.gitignore already had this but root did not. Co-authored-by: CARBComplianceApp <CARBComplianceApp@users.noreply.github.com>
…ndpoint - Remove Vite 'define' that inlined GEMINI_API_KEY into client bundle - Add /api/analyze endpoint on Express server (server-side Gemini calls) - Update App.tsx analyzeEvent() to call server endpoint via fetch - Protect /api/trigger-alert with x-alert-secret header check The API key is no longer embedded in browser-accessible JavaScript. The trigger-alert endpoint now requires a shared secret to prevent unauthenticated alert injection. Co-authored-by: CARBComplianceApp <CARBComplianceApp@users.noreply.github.com>
- New allowlist.ts middleware rejects users not in ALLOWED_EMAILS - Fail-closed: if ALLOWED_EMAILS is empty, all requests are blocked - Wire enforceAllowlist into all /v1/* provider routes after auth - Update deploy script to pass ALLOWED_EMAILS env var (defaults to admin) Prevents abuse by arbitrary Google accounts authenticating via Firebase and proxying paid LLM API calls (Anthropic, OpenAI, xAI, Vertex AI) at the project owner's expense. Co-authored-by: CARBComplianceApp <CARBComplianceApp@users.noreply.github.com>
| app.use("/v1/openai", requireFirebaseAuth, enforceDailyCap, openaiRouter); | ||
| app.use("/v1/xai", requireFirebaseAuth, enforceDailyCap, xaiRouter); | ||
| app.use("/v1/gemini", requireFirebaseAuth, enforceDailyCap, geminiRouter); | ||
| app.use("/v1/anthropic", requireFirebaseAuth, enforceAllowlist, enforceDailyCap, anthropicRouter); |
| app.use("/v1/xai", requireFirebaseAuth, enforceDailyCap, xaiRouter); | ||
| app.use("/v1/gemini", requireFirebaseAuth, enforceDailyCap, geminiRouter); | ||
| app.use("/v1/anthropic", requireFirebaseAuth, enforceAllowlist, enforceDailyCap, anthropicRouter); | ||
| app.use("/v1/openai", requireFirebaseAuth, enforceAllowlist, enforceDailyCap, openaiRouter); |
| app.use("/v1/gemini", requireFirebaseAuth, enforceDailyCap, geminiRouter); | ||
| app.use("/v1/anthropic", requireFirebaseAuth, enforceAllowlist, enforceDailyCap, anthropicRouter); | ||
| app.use("/v1/openai", requireFirebaseAuth, enforceAllowlist, enforceDailyCap, openaiRouter); | ||
| app.use("/v1/xai", requireFirebaseAuth, enforceAllowlist, enforceDailyCap, xaiRouter); |
| app.use("/v1/anthropic", requireFirebaseAuth, enforceAllowlist, enforceDailyCap, anthropicRouter); | ||
| app.use("/v1/openai", requireFirebaseAuth, enforceAllowlist, enforceDailyCap, openaiRouter); | ||
| app.use("/v1/xai", requireFirebaseAuth, enforceAllowlist, enforceDailyCap, xaiRouter); | ||
| app.use("/v1/gemini", requireFirebaseAuth, enforceAllowlist, enforceDailyCap, geminiRouter); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Automated security scan identified 4 vulnerabilities (3 HIGH, 1 MEDIUM) and this PR implements fixes for all of them.
Changes
1. Root
.gitignore— add.envexclusion patterns (MEDIUM fix)Prevents accidental commit of
.env.localand other secret-bearing environment files. Previously onlythe-unit/api/.gitignorehad this protection.2. Gemini API key moved server-side (HIGH fix)
define: { 'process.env.GEMINI_API_KEY': ... }fromvite.config.ts— the key is no longer inlined into the client JavaScript bundlePOST /api/analyzeendpoint inserver.tsthat makes Gemini calls server-sideApp.tsxanalyzeEvent()to call the new server endpoint viafetch()3.
/api/trigger-alertprotected with shared secret (HIGH fix)The endpoint now requires an
x-alert-secretheader matching theALERT_SECRETenvironment variable. Unauthenticated requests are rejected with 401.4. User allowlist for LLM proxy API (HIGH fix)
allowlist.tsmiddleware that rejects users not inALLOWED_EMAILSenv varALLOWED_EMAILSis empty, all requests are blocked/v1/*provider routes (Anthropic, OpenAI, xAI, Gemini)deploy-gcp.shto passALLOWED_EMAILS(defaults to admin email)Testing
npm run lint(tsc --noEmit) passes for silverback-ai-studionpm run build(Vite production build) succeeds — verified bundle no longer contains inlined API keynpm run test:bootpasses all 6 existing tests for the-unit/apinode sites/build.mjsgenerates all 11 sites successfullyDeployment Notes
After merging, set these environment variables:
ALERT_SECRET(any strong random string) for the trigger-alert endpointALLOWED_EMAILS=bryan@norcalcarbmobile.com(comma-separated list of approved users)