Apple SecTrust legacy path accepts untrusted certificates on pre-10.14 macOS/iOS when built with USE_APPLE_SECTRUST
The legacy certificate verification path in libcurl's Apple SecTrust integration compares an OSStatus error code against SecTrustResultType enum values instead of checking the actual trust result, so the result variable remains CURLE_OK even when the certificate is untrusted. On affected older Apple systems, an attacker could bypass TLS certificate validation and perform a man-in-the-middle attack.
Originally disclosed on HackerOne
- Disclosed after 39 hours
Summary:
When libcurl is built with USE_APPLE_SECTRUST and runs on Apple OS versions that lack SecTrustEvaluateWithError (macOS <10.14 / iOS <12), the legacy verification path miscompares OSStatus to SecTrustResultType and never checks the SecTrust result. This can cause untrusted certificates to be accepted.
[Statement clarifying if an AI was used to find the issue or generate the report] This report was prepared with assistance from an AI code analysis tool; the core diagnosis and scope were validated by a combination of classical software, manual inspection of the code, and AI.
Affected version
Reproduced on current master (as of 2025‑10‑07). Affects builds that enable USE_APPLE_SECTRUST and run on macOS <10.14 / iOS <12. The defect is in lib/vtls/apple.c and is independent of the TLS backend choice (it is reached via OpenSSL or GnuTLS when the native CA store is used).
Steps To Reproduce:
Code Verification (Any modern macOS):
- Inspect the vulnerable code in
lib/vtls/apple.clines 263-275 - Observe the type confusion:
status(OSStatus) is compared tokSecTrustResultTypeenum values - Create test program demonstrating the logic bug (see verification artifacts)
- Create untrusted certificate and verify system curl rejects it
Runtime Exploitation (Requires macOS <10.14 or iOS <12):
Note: This requires an actual legacy system. Building with
-DCMAKE_OSX_DEPLOYMENT_TARGET=10.13 on modern macOS will NOT trigger
the bug at runtime due to __builtin_available checks.
-
On a system running macOS 10.13.6 (High Sierra) or earlier, build curl:
cmake -DUSE_APPLE_SECTRUST=ON -DCURL_USE_OPENSSL=ON \ -DCMAKE_BUILD_TYPE=Release .. -
Create untrusted certificates (as described)
-
Start test server:
openssl s_server -accept 8443 -www -key leaf.key -cert leaf.pem -
Test:
./src/curl -v https://localhost:8443/- Expected secure behavior: Connection rejected
- Actual buggy behavior: Connection succeeds
Alternative Verification Without Legacy Hardware:
Since the bug is a clear logic error (comparing wrong variable), it can be confirmed through:
- Static code analysis (lines 270-271 compare
statusinstead ofsec_result) - Logic demonstration (status=0 never equals kSecTrustResultUnspecified=4)
- The fact that
resultremainsCURLE_OKwhen the conditions fail
Supporting Material/References:
Problematic code (legacy fallback uses SecTrustEvaluate; compares status to SecTrustResultType instead of checking sec_result):
#ifndef REQUIRES_SecTrustEvaluateWithError
SecTrustResultType sec_result;
status = SecTrustEvaluate(trust, &sec_result);
if(status != noErr) {
failf(data, "Apple SecTrust verification failed: error %i", (int)status);
}
else if((status == kSecTrustResultUnspecified) ||
(status == kSecTrustResultProceed)) {
/* "unspecified" means system-trusted with no explicit user setting */
result = CURLE_OK;
}
#endif /* REQUIRES_SecTrustEvaluateWithError */
Correct modern code path (only available on 10.14+/iOS 12+):
result = SecTrustEvaluateWithError(trust, &error) ?
CURLE_OK : CURLE_PEER_FAILED_VERIFICATION;
Behavioral gates where Apple SecTrust verification is invoked:
- OpenSSL:
if(!verified &&
conn_config->verifypeer && ssl_config->native_ca_store &&
(ossl_verify == X509_V_ERR_UNABLE_TO_GET_ISSUER_CERT_LOCALLY)) {
result = ossl_apple_verify(..., &verified);
...
}
- GnuTLS:
if(!verified && ssl_config->native_ca_store &&
(verify_status & GNUTLS_CERT_SIGNER_NOT_FOUND)) {
result = glts_apple_verify(..., &verified);
...
}
## Impact
## Summary:
On affected configurations (USE_APPLE_SECTRUST builds running on pre‑10.14 Apple OS with native CA verification engaged), an attacker can bypass TLS certificate validation. This enables Man‑in‑the‑Middle interception, compromising confidentiality and integrity of HTTPS and other TLS‑protected transfers.
Scope caveats:
- Feature is compile‑time gated (`USE_APPLE_SECTRUST`) and off by default in CMake.
- Runtime reachability depends on backend conditions (OpenSSL “unable to get local issuer certificate” or GnuTLS “signer not found”).
- The bug only affects older Apple OS versions that lack `SecTrustEvaluateWithError`; modern Apple OS uses the correct code path.
Not written yet. The AI write-up for this report has not been written yet. The Original tab links to the source.
How it worked
Root cause
Likely the legacy fallback code compares the OSStatus return value of SecTrustEvaluate against SecTrustResultType constants instead of examining the sec_result output parameter, so the trust decision is never actually evaluated.
Impact
On affected configurations, an attacker could bypass TLS certificate validation and perform a man-in-the-middle attack, compromising the confidentiality and integrity of HTTPS and other TLS-protected transfers; however, the feature is compile-time gated and off by default, runtime reachability depends on specific backend conditions, and only older Apple OS versions are affected.
What the attacker needed
Libcurl built with USE_APPLE_SECTRUST; macOS <10.14 or iOS <12; native CA store verification engaged; OpenSSL or GnuTLS backend condition met
How it was found
- Build curl on a legacy Apple system with USE_APPLE_SECTRUST enabled and OpenSSL as the TLS backend.
- Create untrusted certificates for a test server.
- Start a test server using those certificates.
- Run curl against the test server and observe that the connection succeeds instead of being rejected.
Explained by bugbounty.wiki with AI from the original and checked against quotes from it; it can still be wrong. Read the original before relying on a detail.
Not written yet. The AI write-up for this report has not been written yet. The Original tab links to the source.
When a program connects to a secure website, it checks the website's certificate to make sure it is talking to the real server. In this bug, the check was written incorrectly: it looked at the wrong value and therefore did not notice when a certificate was not trusted. On older Apple systems, this meant an attacker could pretend to be the website and read or change the traffic.
What is Crypto?
Encryption, signatures, randomness or certificate checks that do not protect what they claim to.