fix(turbopack): Use rustls-tls-native-roots for system CA support #79060
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Bug Fix: Ensure
rustlsbackend respects system-native certificate authoritiesFixes #79059
Issue:
When Next.js (specifically Turbopack's
turbo-tasks-fetchmodule) usesreqwestwithrustlsas the TLS backend, it does not, by default, respect custom Certificate Authorities (CAs) that have been added to the operating system's native trust store. This is because therustls-tlsfeature inreqwesttypically defaults to using a bundled set of web CAs (e.g., viawebpki-roots) and does not automatically load CAs from the OS.This becomes problematic in environments where network traffic is routed through SSL-inspecting proxies (common in corporate settings) or when accessing internal HTTPS services that use certificates signed by an internal/custom CA. In such cases,
turbo-tasks-fetchwould fail with certificate validation errors, as it wouldn't trust the custom CA.The
native-tlsbackend forreqwest, on the other hand, generally does use the OS's native trust store and thus works correctly in these scenarios. The goal is to achieve consistent behavior withrustlswhen it's selected.Fix:
This patch modifies the
turbopack/crates/turbo-tasks-fetch/Cargo.tomlto change thereqwestfeature fromrustls-tlstorustls-tls-native-rootsfor the relevant target configurations.The
rustls-tls-native-rootsfeature flag forreqwestenables therustls-native-certscrate, which allowsrustlsto load root certificates from the platform's native certificate store. This ensures that if a custom CA is trusted by the OS,reqwest(when usingrustls) will also trust it, mirroring the behavior ofnative-tls.File Changed:
turbopack/crates/turbo-tasks-fetch/Cargo.tomlDiff:
How to Reproduce/Verify (Conceptually):
While setting up a full environment with a custom CA and an HTTPS server using it can be involved, the following conceptual steps and sample code illustrate the issue:
Environment Setup (Hypothetical):
update-ca-certificateson Linux).Sample Rust Code:
A minimal Rust program is provided in the
repro-custom-cadirectory (seerepro-custom-ca/src/main.rsandrepro-custom-ca/Cargo.toml). This program attempts to fetch a URL usingreqwest.repro-custom-ca/src/main.rsrepro-custom-ca/Cargo.tomlTesting the Behavior:
Modify
repro-custom-ca/Cargo.tomlto switch betweenreqwestfeatures:With
features = ["rustls-tls"](anddefault-features = false):If you run
cargo runinrepro-custom-caagainst your custom HTTPS server,reqwest(usingrustls) would likely fail with a certificate validation error because it wouldn't find the custom CA in its bundled root list.With
features = ["rustls-tls-native-roots"](anddefault-features = false) - THE FIX:Running
cargo runnow should succeed.reqwest(usingrustls) will load the custom CA from the OS trust store, and the certificate validation will pass.For comparison, with
features = ["native-tls"](anddefault-features = false):This would also typically succeed, as
native-tlsusually respects OS-level CAs. The patch aims to makerustlsbehave similarly in this regard.Conclusion:
This change ensures more consistent and robust behavior for
turbo-tasks-fetchwhen dealing with HTTPS connections in diverse network environments, particularly those requiring custom CAs. It aligns therustlsbackend's CA handling with that ofnative-tlsand standard browser behavior.