Skip to content

Use the global fetch for OCSP requests - #479

Open
vishalhabib99 wants to merge 1 commit into
apple:mainfrom
vishalhabib99:fix/ocsp-global-fetch
Open

vishalhabib99 wants to merge 1 commit into
apple:mainfrom
vishalhabib99:fix/ocsp-global-fetch

Conversation

@vishalhabib99

Copy link
Copy Markdown

Fixes #476 (blocker 2: the OCSP request).

checkOCSPStatus used two node-fetch v2-only APIs: the timeout option and response.buffer(). When node-fetch resolves to a polyfill over the platform fetch, as it does in Cloudflare Workers with nodejs_compat, the OCSP request fails before it is sent, and online checks always return RETRYABLE_VERIFICATION_FAILURE.

This PR switches only the OCSP request to the global fetch (Node 18+; CI runs 22, 24 and 26):

  • signal: AbortSignal.timeout(30000) instead of timeout: 30000
  • Buffer.from(await response.arrayBuffer()) instead of response.buffer()
  • a plain headers object instead of node-fetch's Headers

AppStoreServerAPIClient still uses node-fetch. Its makeFetchRequest is protected and returns a node-fetch Response, so changing it would affect subclasses. I left it alone.

Reproduction

I used a minimal Worker on wrangler 4.149.0 (workerd), with compatibility_date = "2026-10-01" and nodejs_compat. It calls verifyCertificateChain with enableOnlineChecks = true on the real Apple chain and date from should validate a real chain with OCSP. As #476 suggests, the library is loaded with a dynamic import() to get past the jsrsasign blocker. I ran it with --local-upstream foo.com because Apple's responder returns 403 to CF-Worker: example.com.

  • main: FAIL status=2 cause=(0 , node_fetch_1.default) is not a function
  • this branch: PASS (3 of 3 runs)

Tests

  • jws_verification.test.ts now mocks the global fetch with a standard Response, which has no buffer(). The delegated-responder test also checks that the request is a POST with the OCSP content type and an AbortSignal.
  • yarn build and npx jest pass on Node 24: 17 suites, 456 tests, including the live should validate a real chain with OCSP.

Note on #455 / #456

#456 fixes the timeout handling for #455 and edits the same lines. With this change the abort signal also covers reading the body, so a stalled body is aborted and the socket is closed. I didn't change how a body-read timeout is classified, which is what #456 handles. Whichever of the two merges first, I'm happy to rebase this one on top.

checkOCSPStatus relied on two node-fetch v2-only APIs: the timeout
option and response.buffer(). On runtimes where node-fetch resolves to
a polyfill over the platform fetch (Cloudflare Workers with
nodejs_compat), the OCSP request fails before it is sent, so online
checks always return RETRYABLE_VERIFICATION_FAILURE.

Use the global fetch with AbortSignal.timeout(30000) and read the body
with arrayBuffer(). Behavior on Node is unchanged; the API client still
uses node-fetch.

Fixes apple#476

This branch has not been deployed

No deployments
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.

Cloudflare Workers (nodejs_compat): SignedDataVerifier passes with online checks; two non-crypto blockers remain

1 participant