Skip to content

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

Merged
David Sanchez (dsanchezcr) merged 3 commits into
mainfrom
copilot/fix-code-scanning-alerts
Nov 3, 2026
Merged

David Sanchez (dsanchezcr) merged 3 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 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
@dsanchezcr
David Sanchez (dsanchezcr) marked this pull request as ready for review November 3, 2026 14:25
Copilot AI balanced review requested due to automatic review settings November 3, 2026 14:26
@github-actions

github-actions Bot commented Nov 3, 2026

Copy link
Copy Markdown

❌ Lighthouse Accessibility Score

Category Score Threshold
♿ Accessibility N/A% ≥ 90%

⚠️ Score is below the 90% threshold — please fix the violations.

🔗 View full Lighthouse report (expires in 7 days)

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Changes recommended

The security-sensitive missing-emulator-certificate fallback lacks a regression test verifying the actionable warning and absence of a TLS-validation-disabled agent.

1 open issue
What changed in this PR

This PR addresses the CodeQL certificate-validation alert by removing the Cosmos DB emulator’s insecure TLS fallback.

Changes:

  • Removes the agent that disabled certificate validation when the emulator CA certificate was missing.
  • Adds a descriptive missing-certificate error, logged by the existing catch block with setup guidance.
File Description
api/​src/​shared/​cosmosdb.ts Removes the insecure emulator TLS fallback and adds an actionable certificate warning.

Review effort: Balanced

Comment on lines +90 to +93
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.`
)
@dsanchezcr
David Sanchez (dsanchezcr) merged commit 2b7abcc into main Nov 3, 2026
18 of 19 checks passed
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.

3 participants