← Back to Pull requests

feat(commons): sign and verify requests from core to country config #14397

Open
unknown opened this pull request with 342 lines diff across 4 files
View on GitHub
unknown unknown commented on Nov 11, 2026 13:28 UTC
Author

Part 1 of 6 of #14240. Nothing in the running system changes in this PR.

Summary

packages/commons/src/request-signing/
├── signature.ts   # signCoreRequest, verifyCoreRequest, withCoreSignature, Content-Digest
├── keys.ts        # loadCoreSigningKeyFile (Ed25519 PEM → key + kid), toPublicJwk (RFC 7638 kid)
├── key-list.ts    # createCoreKeyList: keys from auth's JWKS, fetched again for an unknown kid
├── hapi.ts        # coreRequestAuth plugin: the `core` auth strategy
└── testing.ts     # createTestCoreKey: a key and signed requests for tests of `auth: 'core'` routes

The profile of RFC 9421 that #14240 describes: label core, components "@method" "@path" "@query" "content-digest", alg="ed25519", tag="opencrvs-core-request", and a window of 300 s.

coreRequestAuth (route with auth: 'core')
  authenticate
    verify the signature and the window, find the key by kid    → 403 if wrong
    GET / HEAD: the digest must be that of an empty body          → 403 if wrong
    collect the raw body chunks ('peek')
  payload
    compare the raw body with Content-Digest                     → 403 if wrong

Who uses which part:

| Export | Package | User |
|---|---|---|
| withCoreSignature, loadCoreSigningKeyFile, toPublicJwk, verifyCoreRequest | @opencrvs/commons/request-signing | core (later slices) |
| coreRequestAuth, createTestCoreKey | @opencrvs/toolkit/request-signing | country config |

Differences from #14240, on purpose:

  • Toolkit does not export signCoreRequest and verifyCoreRequest. Country config needs only the core strategy, and createTestCoreKey to test its routes.

  • Until the first fetch of the JWKS succeeds, an unknown kid can fetch it again after 5 seconds, not after a minute. Country config can start before auth, and without this it rejects core for up to a minute.
  • Evidence

  • Before: no way for country config to check that a request comes from core.

  • After: unit tests in signature.test.ts, keys.test.ts (RFC 8037 test vectors), key-list.test.ts, hapi.test.ts and testing.test.ts, for example:
    - a request signed with the key → 200; one changed byte in the body → 403
    - a signature older than 300 s, an unknown kid, a missing header → 403, with the reason only in the log
    - an unknown kid fetches the key list again, at most once a minute
    - a request from createTestCoreKey passes the core strategy, both with findPublicKey and with its JWKS
  • commons and toolkit: 726 tests pass. Typecheck, lint and knip (35, same as develop) pass.
  • Merge Danger

    Door: two-way

    Only new code, which nothing calls yet.

    Blast Radius: none

    🤖 Generated with Claude Code

    Diff: 342 lines (+256 / -86) across 4 files Reviewer: panva Review duration: 13316m
    All Vouch review confidence checks passed
    Residual risk 0.35 = Change Risk (0.65) × (1 − Review Confidence (0.47)). Review depth and reviewer attention state are adequate.
    Model 1 · Change Risk (XGBoost)
    Score: 0.65 · 342 lines diff across 4 files
    0.65
    Model 2 · Review Depth (DistilBERT)
    Depth Score: 0.02 · 1 substantive comment(s)
    0.02
    Model 3 · Review Timing & Attention
    Session adequacy: 100% · Reviewer familiarity: 35%
    46%
    Bedrock Claude 3 · Risk Narration
    (disconnected)
    Groq
    Groq Risk Narration
    AWS Bedrock is currently disconnected. Generate high-confidence PR triage narration on-demand using Groq.
    Model 1 · Change Risk Attribution
    SHAP Weights
    Diff Size diff_size
    0.349
    Shallow Review Depth shallow_review_depth
    0.344
    Sensitive Paths sensitive_paths
    0.065
    Real PR Conversation Timeline
    1 comments
    "Review active on #14397"
    general weight: 0.35
    Reviewers
    Assignees
    Unassigned
    Labels
    risk: low confidence: 46.7% reviewed sensitive_module
    Vouch Risk Breakdown
    AI-powered review risk analysis
    Change Risk
    Change Risk · Model 1 (XGBoost)
    Predicted defect probability (0.00–1.00) based on diff churn, modified sensitive files, and author risk history.
    Score: 65.5% (HIGH) · Higher = larger blast radius
    65.5%
    Review Confidence
    Review Confidence · Models 2 & 3
    Scrutiny score (0.00–1.00) combining DistilBERT semantic review depth with reviewer familiarity and session dwell time.
    Score: 46.7% · Lower = rushed or shallow review
    46.7%
    Residual Risk
    Residual Risk · Core Equation
    Residual = Change × (1 − Confidence)
    Unmitigated risk surviving review. ≥ 0.65 triggers an automated re-queue to protect production.
    Score: 34.9% · Safe to merge
    34.9%