Potential fix for code scanning alert no. 38: Disabling certificate validation#18
Potential fix for code scanning alert no. 38: Disabling certificate validation#18TheInfamousToTo merged 1 commit intomainfrom
Conversation
…alidation Co-authored-by: Copilot Autofix powered by AI <62310815+github-advanced-security[bot]@users.noreply.github.com>
There was a problem hiding this comment.
Pull request overview
This PR addresses code scanning alert #38 by removing the explicit disabling of TLS certificate validation in the backend Pi-hole web client, restoring Node’s default HTTPS certificate verification behavior.
Changes:
- Removed
rejectUnauthorized: falsefrom the Axios HTTPS agent configuration. - Only provides an
httpsAgentwhenuseHttpsis enabled (and omits it for HTTP).
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| const httpsAgent = useHttps ? new https.Agent() : undefined; | ||
|
|
There was a problem hiding this comment.
new https.Agent() is being created even though no custom agent options are being set. Since createApiClient returns a new Axios instance each call, this can prevent reuse of Node’s default global agent (connection pooling / TLS session reuse) and adds overhead. Consider omitting httpsAgent entirely unless you need to customize it (e.g., custom CA or keepAlive settings), and rely on Axios/Node defaults for HTTPS.
Potential fix for https://github.com/TheInfamousToTo/PiHoleVault/security/code-scanning/38
To fix the problem, we should stop disabling TLS certificate validation and let Node’s default behavior verify server certificates against the system trust store. This means removing
rejectUnauthorized: falseand only customizing thehttps.Agentwhen strictly necessary (for example, when a trusted custom CA is configured), and even then keepingrejectUnauthorized: true.The single best fix, without changing functionality more than necessary, is:
https.AgentwithrejectUnauthorized: falseby default.useHttpsisfalse, we don’t need anhttps.Agentat all.useHttpsistrue, either:https.Agentby omittinghttpsAgententirely, orhttps.Agentwith that CA while keepingrejectUnauthorizedat its default (true). Because we are not shown such configuration here, we will choose the safe/default path: only sethttpsAgentwhenuseHttpsis true, and in that case, do not overriderejectUnauthorized.Concretely in
backend/services/PiHoleWebService.js, insidecreateApiClient:httpsAgentbased onuseHttps:const httpsAgent = useHttps ? new https.Agent() : undefined;httpsAgentintoaxios.create, but only when defined.rejectUnauthorized: falseentirely.This keeps the public interface of
createApiClientunchanged while restoring proper certificate validation for HTTPS connections.Suggested fixes powered by Copilot Autofix. Review carefully before merging.