Skip to content

Memory-hard KDF for hashing API keys at rest (Argon2id) #222

Description

@kilodesodiq-arch

Problem Statement. The current keyHash is described as SHA-256 in spec. SHA-256 of an
API key is fast — exactly what an attacker brute-forcing a leaked hash wants.

Why it matters. Even with a long random key, a stolen keyHash can be reversed by
someone who controls the database.

Technical Context. Existing keyHash column allows arbitrary length. Argon2id
produces a 32-byte hash with a parameter-aware string that can fit.

Expected Outcome. API keys are hashed with argon2id, parameters encoded inside the
hash output so verification doesn't need a config match.

Acceptance Criteria.

  • Verification uses argon2-cffi's PasswordHasher verify.
  • Existing hashes are invalidated on next request (re-authentication required).
  • E2E test demonstrates that an SHA-256 hash purely fails the new verifier.

Implementation Notes. Pick parameters (m=64 MiB, t=3, p=1) carefully; benchmark
against the existing verify latency budget.

Files or modules likely to be affected. src/api-keys/*,
src/common/guards/api-key.guard.ts, requirements.txt /
package.json (argon2, argon2-cffi).

Difficulty. Medium
Estimated effort. S


Smart-Contract Safety — Issues 15–28


Backlog item #14 from `docs/maintainer-issue-backlog.md.

Activity

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

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions