Skip to content

vscode/proxy-agent uses untrusted certificates on macOS #247003

Closed

Description

@tmm1

Does this issue occur when all extensions are disabled?: Yes

  • VS Code Version: any
  • OS Version: macOS

Steps to Reproduce:

on macOS, vscode/proxy-agent uses:

https://github.com/microsoft/vscode-proxy-agent/blob/ef240a475dd742e2ecfcb65b0a1722817aacce81/src/index.ts#L860-L862

async function readMacCaCertificates() {
	const stdout = await new Promise<string>((resolve, reject) => {
		const child = cp.spawn('/usr/bin/security', ['find-certificate', '-a', '-p']);

this returns all the certificates in the keychain, regardless of trust settings. by default, when installing a new cert on modern version of macOS, it is not trusted:

Image

contrast this with the new --use-system-ca flag in nodejs v23, which looks at the individual trust settings of each imported cert:

https://github.com/nodejs/node/blob/25842c5e35efb45df169e591c775a3c4f853556d/src/crypto/crypto_context.cc#L367-L375

TrustStatus IsTrustSettingsTrustedForPolicy(CFArrayRef trust_settings,
                                            bool is_self_issued) {
  // The trust_settings parameter can return a valid but empty CFArrayRef.
  // This empty trust-settings array means “always trust this certificate”
  // with an overall trust setting for the certificate of
  // kSecTrustSettingsResultTrustRoot
  if (CFArrayGetCount(trust_settings) == 0) {
    return is_self_issued ? TrustStatus::TRUSTED : TrustStatus::UNSPECIFIED;
  }

Activity

  1. chrmarti commented on Apr 22, 2025

    @chrmarti
    Collaborator

    It looks like security verify-cert can be used to check trust on each CAs.

  2. added
    bug
    proxy
    on Apr 22, 2025
  3. chrmarti commented on Apr 24, 2025

    @chrmarti
    Collaborator

    Node.js 22.x is getting support for reading OS certificates on Windows and macOS: nodejs/node#57840

  4. chrmarti commented on Aug 28, 2026

    @chrmarti
    Collaborator

    Fixed with #332504.

  5. added this to the 1.136.0 milestone on Aug 28, 2026
  6. chrmarti commented on Aug 28, 2026

    @chrmarti
    Collaborator

    Steps to Verify

    1. On macOS, install the latest VS Code Insiders build containing Enable Node.js system certificates by default #332504.

    2. Remove any explicit http.systemCertificatesNode value from the Default profile’s User Settings, confirming the new default is exercised.

    3. Create a self-signed certificate for localhost using the command below.

    4. Add localhost-cert.pem to the macOS login Keychain.

    5. In Keychain Access, open the certificate, expand Trust, and select Never Trust.

    6. Start the local HTTPS server using the command below.

    7. Fully quit and restart VS Code Insiders so system certificates are reloaded.

    8. Use the Network Proxy Test extension’s Network Proxy Test: Test Connection command with:

      https://localhost:8443/
      
    9. Verify that the configured Node.js request fails with a certificate trust error. An untrusted certificate must not be accepted merely because it is present in the Keychain.

    10. In Keychain Access, change the certificate to Always Trust.

    11. Fully quit and restart VS Code Insiders, then repeat the connection test.

    12. Verify that the configured Node.js request now succeeds.

    13. Change the certificate back to Never Trust, restart Insiders, and confirm that the request fails again.

    14. Stop the HTTPS server, delete the certificate from Keychain Access, and remove the temporary files.

    Expected: With http.systemCertificatesNode enabled by default, Node.js honors the macOS trust settings: the certificate is accepted when set to Always Trust and rejected when set to Never Trust.

    Create the Self-Signed Certificate

    mkdir -p /tmp/vscode-system-ca-test
    cd /tmp/vscode-system-ca-test
    
    openssl req \
      -x509 \
      -newkey rsa:2048 \
      -nodes \
      -sha256 \
      -days 7 \
      -subj "/CN=localhost" \
      -addext "subjectAltName=DNS:localhost,IP:127.0.0.1" \
      -addext "basicConstraints=critical,CA:TRUE" \
      -addext "keyUsage=critical,digitalSignature,keyEncipherment,keyCertSign" \
      -addext "extendedKeyUsage=serverAuth" \
      -keyout localhost-key.pem \
      -out localhost-cert.pem

    Run the Local HTTPS Server

    From /tmp/vscode-system-ca-test, run:

    openssl s_server \
      -accept 8443 \
      -cert localhost-cert.pem \
      -key localhost-key.pem \
      -www

    Keep the server running while testing. Stop it afterward with Ctrl+C.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Labels

bugproxyverified

Type

No type

Projects

No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions