Task 1-2: Review và Re-enable validateCode() trong signIn()
Phase: 1 - Security Priority: Medium Module:
authenticationDepends on: Không có Blocks: task-4-1 Reference:docs/BountyHunter-Backend/details/feature-authentication/SPEC.md
Background
validateCode() trong signIn() bị comment out trong AuthService. Chưa rõ lý do — nếu unintentional thì có security hole: bất kỳ code nào cũng pass.
Tasks
File: authentication/controllers/auth/AuthService.java
DI / Context note:
validateCode()là một private method của chínhAuthService— không cần inject từ bên ngoài. Nó nhận tham sốUserModel user(được lấy từ DB trước đó trongsignIn()) vàString code(từ request body). Đảm bảoUserModelcó các getter:getAuthCode()vàgetExpireAuthCode()(kiểuInstant). Import cần thêm nếu chưa có:java.time.Instant.
-
[ ] Tìm và đọc logic
validateCode():private void validateCode(UserModel user, String code) { // Check: code match + not expired if (!user.getAuthCode().equals(code)) throw new BadRequestException("INVALID_CODE"); if (Instant.now().isAfter(user.getExpireAuthCode())) throw new BadRequestException("CODE_EXPIRED"); } -
[ ] Xác nhận lý do comment out (check git blame / PR history)
- Nếu có lý do hợp lệ → thêm comment giải thích rõ ràng
-
Nếu unintentional → re-enable
-
[ ] Re-enable (nếu cần):
// Trước: // this.validateCode(user, baseMap.get("code")); // Sau: this.validateCode(user, baseMap.get("code")); -
[ ] Test trên staging với code đúng và code sai trước khi merge
Verification / Acceptance Criteria
- [ ] Compile check:
AuthService.javacompile thành công —UserModelcógetAuthCode()vàgetExpireAuthCode(), importjava.time.Instanttồn tại. - [ ] Valid code:
POST /api/auth/sign-invới code đúng và còn hạn → login thành công, nhậnUserAuthResponse. - [ ] Invalid code:
POST /api/auth/sign-invới code sai → nhận lỗiINVALID_CODE(HTTP 400). - [ ] Expired code:
POST /api/auth/sign-invới code đã hết hạn (expireAuthCodetrong quá khứ) → nhận lỗiCODE_EXPIRED(HTTP 400). - [ ] Test reference: Scenario "expired auth code" trong
task-4-3pass sau khi thay đổi.
Files to Modify
authentication/src/main/java/com/figpop/authentication/controllers/auth/AuthService.java