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
rustls
backend respects system-native certificate authoritiesFixes #79059
Issue:
When Next.js (specifically Turbopack's
turbo-tasks-fetch
module) usesreqwest
withrustls
as 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-tls
feature inreqwest
typically 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-fetch
would fail with certificate validation errors, as it wouldn't trust the custom CA.The
native-tls
backend 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 withrustls
when it's selected.Fix:
This patch modifies the
turbopack/crates/turbo-tasks-fetch/Cargo.toml
to change thereqwest
feature fromrustls-tls
torustls-tls-native-roots
for the relevant target configurations.The
rustls-tls-native-roots
feature flag forreqwest
enables therustls-native-certs
crate, which allowsrustls
to 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.toml
Diff:
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-certificates
on Linux).Sample Rust Code:
A minimal Rust program is provided in the
repro-custom-ca
directory (seerepro-custom-ca/src/main.rs
andrepro-custom-ca/Cargo.toml
). This program attempts to fetch a URL usingreqwest
.repro-custom-ca/src/main.rs
repro-custom-ca/Cargo.toml
Testing the Behavior:
Modify
repro-custom-ca/Cargo.toml
to switch betweenreqwest
features:With
features = ["rustls-tls"]
(anddefault-features = false
):If you run
cargo run
inrepro-custom-ca
against 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 run
now 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-tls
usually respects OS-level CAs. The patch aims to makerustls
behave similarly in this regard.Conclusion:
This change ensures more consistent and robust behavior for
turbo-tasks-fetch
when dealing with HTTPS connections in diverse network environments, particularly those requiring custom CAs. It aligns therustls
backend's CA handling with that ofnative-tls
and standard browser behavior.