Skip to content

fix: preserve system certs when adding Mozilla roots#706

Open
AyaanFaisal21 wants to merge 1 commit into
supabase:mainfrom
AyaanFaisal21:fix-ca-store-order
Open

fix: preserve system certs when adding Mozilla roots#706
AyaanFaisal21 wants to merge 1 commit into
supabase:mainfrom
AyaanFaisal21:fix-ca-store-order

Conversation

@AyaanFaisal21
Copy link
Copy Markdown

What kind of change does this PR introduce?

Bug fix.

Fixes #705.

What is the current behavior?

The environment variable configurationDENO_TLS_CA_STORE=system,mozilla loads system roots first, but then the mozilla branch replaces the existing RootCertStore, which drops the system roots that were just added.

This makes CA store behavior order-dependent: mozilla,system preserves both stores, while system,mozilla only keeps Mozilla/webpki roots.

What is the new behavior?

The mozilla branch now appends Mozilla/webpki roots to the existing RootCertStore instead of replacing it entirely.

This preserves system roots for the documented DENO_TLS_CA_STORE=system,mozilla environment variable configuration and makes system,mozilla / mozilla,system produce the same effective trust-anchor set.

I also added a deterministic regression test covering both orderings without depending on the host machine’s system certificate store.

Additional context

Verification run locally:

  • cargo fmt --check
  • cargo test -p deno_facade ca_store_order_does_not_drop_system_roots
  • cargo test -p deno_facade
  • git diff --check

Comment on lines +30 to 35
fn get_root_cert_store_with(
ca_stores: &[String],
mut add_mozilla_roots: impl FnMut(&mut RootCertStore),
mut add_system_roots: impl FnMut(&mut RootCertStore),
) -> Result<RootCertStore, AnyError> {
let mut root_cert_store = RootCertStore::empty();
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Couldn't it be simpler?
Any special reason why receiving it as closures?

I think the match expression below could just call the original fn directly

Comment on lines +101 to +102
|root_cert_store| add_test_root(root_cert_store, b"mozilla"),
|root_cert_store| add_test_root(root_cert_store, b"system"),
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Following my comment above, I couldn't get the idea about passing it down as closures using custom test functions.

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

DENO_TLS_CA_STORE="system,mozilla" silently drops system certs (order-dependent regression from upstream Deno)

2 participants