perf(auth): OIDC 토큰 지연 해소 — client_secret SHA-256 + 비밀번호 네이티브 scrypt 전환 - #73
Merged
Conversation
OIDC 콜백이 ~6초 걸리던 원인인 순수 JS argon2id(verify 1회 ~4.4초 CPU) 제거: - client_secret 검증을 SHA-256 단일 해시(sha256$)로 전환. 서버 생성 32바이트 랜덤값(256비트 엔트로피)이라 메모리 하드 KDF 불필요. 레거시 argon2/pbkdf2 해시는 검증 성공 시 자동 업그레이드. - 사용자 비밀번호 해싱을 node:crypto 네이티브 scrypt(N=32768,r=8,p=3, 32MiB — OWASP 권고)로 전환. Workers 2025-04 부터 네이티브 지원, workerd 실측 106ms. 레거시 해시는 로그인 성공 시 자동 rehash, 향후 파라미터 상향 시에도 자동 재해싱. - /oidc/token 의 독립 조회 3개(유저/서명키/권한매핑) Promise.all 병렬화. Co-Authored-By: Claude Fable 5 <[email protected]>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
문제
RP(drone.devday.one)의 OIDC 콜백이 약 6초 걸립니다. 콜백 처리 중 RP 가 KeyStone 의
POST /oidc/token을 호출하는데, 이 엔드포인트가 요청마다 client_secret 을@hicaru/argon2-pure.js(순수 JS argon2id, m=7168/t=5)로 검증하면서 verify 1회에 ~4.4초의 CPU 를 태우는 것이 주범이었습니다 (로컬 실측 4,372ms). 로그인의 비밀번호 검증도 같은 코드 경로라 동일하게 느렸습니다.해결
1. client_secret 검증: argon2 → SHA-256 (
src/lib/server/oidc/client.ts)client_secret 은 서버가 생성한 32바이트 랜덤값(256비트 엔트로피) 이라 사전공격·무차별대입이 불가능하므로, 저엔트로피 비밀번호용 메모리 하드 KDF 대신 SHA-256 단일 해시(
sha256$<b64u>)로 충분합니다. 검증 4.4초 → <1ms.auth_method=none) 처리 등 기존 보안 검사는 그대로 유지2. 비밀번호 해싱: 순수 JS argon2id → 네이티브 scrypt (
src/lib/server/auth/password.ts)Workers 는 런타임 WASM 바이트 컴파일을 금지해 WASM argon2 도입에는 빌드 배관이 필요한 반면,
node:cryptoscrypt 는 2025-04 부터 Workers 네이티브(BoringSSL) 지원됩니다 (better-auth 도 같은 이유로 채택).scrypt$N=32768,r=8,p=3$<salt_b64>$<hash_b64>authenticateLocalUser영속화 경로 재사용) — 락아웃 없음3.
/oidc/token쿼리 병렬화grant 소진 후 서로 독립인 조회 3개(유저·서명키·권한매핑)를
Promise.all로 병렬화.검증
wrangler dev): scrypt 106ms, 결정적 동작 확인배포 후 동작
6초 → 12초🤖 Generated with Claude Code