Skip to content

fix: remove rejectUnauthorized: false — resolve CodeQL certificate validation alert - #94

Draft
dsanchezcr with Copilot wants to merge 2 commits into
mainfrom
copilot/fix-code-scanning-alerts
Draft

fix: remove rejectUnauthorized: false — resolve CodeQL certificate validation alert#94
dsanchezcr with Copilot wants to merge 2 commits into
mainfrom
copilot/fix-code-scanning-alerts

Conversation

Copilot AI commented Jul 23, 2026

Copy link
Copy Markdown
Contributor

CodeQL flagged a high-severity js/disabling-certificate-validation alert (CWE-295/CWE-297): the Cosmos DB emulator setup fell back to rejectUnauthorized: false when the emulator CA cert file was missing, fully disabling TLS validation and opening the door to MITM attacks.

Change

api/src/shared/cosmosdb.ts

  • Removed the insecure fallback https.Agent({ rejectUnauthorized: false }) — including its prod-environment guard, which was insufficient mitigation
  • When the emulator CA cert is not found, a descriptive error is now thrown and caught by the surrounding try/catch, which logs a clear actionable warning
// Before
} else {
  if (process.env.ENVIRONMENT === 'prod') {
    throw new Error('Cannot disable TLS verification in production environment')
  }
  clientOptions.agent = new https.Agent({ rejectUnauthorized: false }) // ← flagged
}

// After
} else {
  throw new Error(
    `Cosmos DB Emulator CA certificate not found at "${emulatorCertPath}". ` +
    `Run the emulator setup script or set COSMOS_EMULATOR_CERT_PATH to a valid cert file.`
  )
}

TLS validation is now always enforced; developers get an explicit error instead of a silent insecure connection.

Copilot AI requested review from Copilot and removed request for Copilot July 23, 2026 16:59
Copilot AI requested review from Copilot and removed request for Copilot July 23, 2026 17:02
Copilot AI changed the title [WIP] Fix code scanning alert(s) flagged in repository fix: remove rejectUnauthorized: false — resolve CodeQL certificate validation alert Jul 23, 2026
Copilot AI requested a review from dsanchezcr July 23, 2026 17:03
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