- Branch diff:
main...fix/issue-3-token-hashing - Files:
scaffold/pm-api/src/utils/hash.ts(new)scaffold/pm-api/src/auth.tsscaffold/pm-api/src/routes/v2-admin.tsscaffold/pm-api/sql/008-hash-tokens.sql(new)
scaffold/pm-api/sql/008-hash-tokens.sql | 9 +++++++++
scaffold/pm-api/src/auth.ts | 11 ++++++++---
scaffold/pm-api/src/routes/v2-admin.ts | 17 +++++++++++------
scaffold/pm-api/src/utils/hash.ts | 12 ++++++++++++
4 files changed, 40 insertions(+), 9 deletions(-)- ✅
hashTokenusescrypto.subtle.digest('SHA-256', ...)withTextEncoder. - ✅ No
node:cryptoimport inutils/hash.ts.
- ✅
auth.tschecksWHERE (token_hash = ? OR token = ?) .... - ✅ This supports existing plaintext rows and new hashed rows.
- ✅
v2-admin.tscomputestokenHash = await hashToken(body.token)before insert. ⚠️ But plaintext token is still stored intokencolumn as well.
- ✅
008-hash-tokens.sqladdstoken_hash TEXTand indexidx_auth_tokens_token_hash.
Where: v2-admin.ts insert/update SQL still writes token = ?.
Impact: If DB is leaked, active bearer tokens are immediately usable. This weakens the main purpose of hashing-at-rest.
Recommendation:
- Store only
token_hashfor new/regenerated tokens. - Keep
tokennullable only for temporary legacy rows. - Add migration plan to null/clear legacy plaintext tokens after rollover.
Where: src/routes/auth.ts still does WHERE token = ? only.
Impact: Auth behavior is inconsistent across code paths. If token column is later removed/cleared, this endpoint will fail while middleware may still work.
Recommendation: Update routes/auth.ts to use same dual-lookup logic as auth.ts during migration.
Where: 008-hash-tokens.sql adds column/index only; no data migration.
Impact: Legacy rows never become hash-searchable unless manually regenerated. Migration can remain half-complete indefinitely.
Recommendation: Add explicit backfill strategy (app-side script or phased re-issue) and track completion criteria.
Where: migration creates non-unique index only.
Impact: Accidental duplicate token values can create ambiguous ownership/validation behavior.
Recommendation: Add UNIQUE constraint/index on token_hash (after backfill cleanup), plus conflict handling.
REQUEST_CHANGES
핵심 보안 목표(토큰 평문 비저장)가 아직 완전히 달성되지 않았고, 인증 경로 일관성(/verify) 및 마이그레이션 완결성(backfill/unique) 이슈가 남아 있습니다.