Repository navigation
Conversation
getAgent returned the result of setGlobalDispatcher (always undefined)
on its first call, and the agent it installed as undici's global
dispatcher set rejectUnauthorized: false. Once any request had loaded
the certs, every server-side fetch in the process skipped TLS
certificate verification, including calls to third parties.
The global dispatcher stays, because it is the only way the agent takes
effect: Node's built-in fetch ignores the `agent` option callers pass,
and rejects our undici@8 Agent as a `dispatcher` ("invalid
onRequestStart method").
- Remove rejectUnauthorized: false, so all requests verify certificates.
- Trust Node's default root CAs alongside the CA bundle, as setting `ca`
replaces the default trust store.
- Memoise the in-flight promise, so concurrent first calls share one
cert load and agent, and the dispatcher is installed once. Always
resolve to the agent, and retry after a failed cert load.
amoore108
force-pushed
the
amoore108-scope-mtls-agent
branch
from
November 29, 2026 23:07
5d1afe1 to
4c18275
Compare
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Resolves JIRA:
Summary
getAgentinstalls the mTLS agent as undici's global dispatcher, and that agent setrejectUnauthorized: false. So once any request had loaded the certificates, every server-sidefetchin the process skipped TLS certificate verification, including calls to third parties. This PR keeps the global dispatcher but turns verification back on.The global dispatcher has to stay: it's the only way the agent takes effect. Node's built-in
fetchignores theagentoption callers pass, and rejects ourundici@8Agent as adispatcher(invalid onRequestStart method, on Node 22 and 24).Code changes
rejectUnauthorized: false, so all server-side requests verify certificates.ca: [...tls.rootCertificates, ca]), because settingcareplaces the default trust store and requests to services that don't use the BBC CA also go through this agent.getAgentnow always resolves to the agent. Its first call used to returnsetGlobalDispatcher(...), which is alwaysundefined.Testing
yarn workspace simorgh-nextjs test utilities/getAgent. The tests now cover verification being on, the dispatcher being installed once, concurrent calls and retrying after a failure.fetchand generated certificates:https://www.bbc.co.uk/: 200ws-downloads.files.bbci.co.uk, OG image fonts) still succeed.Useful Links