[H-6] Full-table scans on every hot path — no Mnesia indexes on certificate_request / oauth_client; login_attempt index unused #10

Closed
opened 2026-11-14 18:28:44 +01:00 by amiryahaya · 0 comments
Owner

Finding

Lookups are match_object full scans. certificate_request has no index on ic_number/serial, so every status check, enrollment pre-check, OCSP request (×2 scans) and CRL rebuild is O(all certs ever issued). oauth_client scans per JWT verification. login_attempt creates an index but find still full-scans.

Evidence

  • lib/mdid_ws/cert_management/certificate_request_data_store.ex:91-101 — match_object patterns
  • lib/mdid_ws/cert_management/ocsp_responder.ex:142-153 — two scans per OCSP request
  • lib/mdid_ws/cert_management/crl_publisher.ex:97-106 — full scan per revocation
  • lib/mdid_ws/oauth/client_data_store.ex:111-123; lib/mdid_ws/auth/login_attempt_data_store.ex:79-81, 135

Impact

A CA's issuance table grows monotonically — OCSP/status latency degrades linearly for relying parties; every auth request scans the client table.

Fix

  • Add index: [:ic_number, :cert_serialnumber] to certificate_request (with a transform_table migration like the existing legacy one) and index: [:client_id] to oauth_client
  • Use :mnesia.index_read in the find clauses
  • Use the existing login_attempt identifier index

Line numbers refer to the initial import commit 282cb11. Source: comprehensive audit, 2026-11-12 (first review of this codebase).

## Finding Lookups are `match_object` full scans. `certificate_request` has no index on `ic_number`/serial, so every status check, enrollment pre-check, OCSP request (×2 scans) and CRL rebuild is O(all certs ever issued). `oauth_client` scans per JWT verification. `login_attempt` creates an index but `find` still full-scans. ## Evidence - `lib/mdid_ws/cert_management/certificate_request_data_store.ex:91-101` — match_object patterns - `lib/mdid_ws/cert_management/ocsp_responder.ex:142-153` — two scans per OCSP request - `lib/mdid_ws/cert_management/crl_publisher.ex:97-106` — full scan per revocation - `lib/mdid_ws/oauth/client_data_store.ex:111-123`; `lib/mdid_ws/auth/login_attempt_data_store.ex:79-81, 135` ## Impact A CA's issuance table grows monotonically — OCSP/status latency degrades linearly for relying parties; every auth request scans the client table. ## Fix - [ ] Add `index: [:ic_number, :cert_serialnumber]` to certificate_request (with a `transform_table` migration like the existing legacy one) and `index: [:client_id]` to oauth_client - [ ] Use `:mnesia.index_read` in the find clauses - [ ] Use the existing login_attempt identifier index _Line numbers refer to the initial import commit `282cb11`. Source: comprehensive audit, 2026-11-12 (first review of this codebase)._
Sign in to join this conversation.
No description provided.