2단계 인증은 7.0.6 에서 서버측이 갖춰졌지만 인증번호를 입력할 화면이 어느 버전에도
없었다. 그래서 그 설정을 켠 사이트는 관리자를 포함한 전원이 로그인할 수 없었다.
원인은 `POST /api/auth/login` 이 조건에 따라 **다른 형태의 200** 을 돌려준다는 것이다.
평소에는 `{token, user}` 지만 2단계 인증이 켜져 있으면 `{two_factor_required,
challenge_id, ...}` 를 돌려준다. 프론트는 앞의 형태만 선언하고 `response.data.user.language`
를 바로 읽었으므로 그 자리에서 TypeError 가 났고, 영문 원문이 로그인 화면에 그대로 노출됐다.
서버는 정상 응답했으므로 서버 로그에는 아무 흔적도 남지 않는다.
이어서 `setToken(undefined)` 가 `localStorage` 에 문자열 `"undefined"` 를 남겼다.
이 값은 truthy 라 이후 모든 요청이 `Bearer undefined` 로 나가 401 이 되고, 사용자에게는
「세션이 만료되었습니다」로 보인다. 관리자 로그인은 한발 더 나가 `null->isAdmin` 으로
500 이 되어, 설정을 되돌릴 수단까지 함께 사라졌다.
## 구현
- 로그인 응답을 판별 유니온(`LoginResult`)으로 표현하고, 형태를 판별한 뒤에 읽는다.
`ApiClient.setToken` 은 비어 있지 않은 문자열만 저장한다.
- 사용자·관리자 로그인 화면에 인증번호 입력 단계를 추가했다. 같은 카드 안에서 넘어가며
「인증번호 다시 받기」와 「처음부터」를 제공한다. 관리자 판정은 코드 확인에 성공한 뒤에
수행하고, 거부할 때는 그 직전에 발급된 토큰을 회수한다.
- 재발송(`login/two-factor/resend`)은 기존 challenge 를 취소하고 새로 발행한다. 유효한
코드를 여러 개 살려 두면 대입 시도의 표적이 넓어진다.
- 인증번호를 보내지 못하면 401 이 아니라 503 으로 답한다. 자격 증명은 올바른데 401 로
뭉개면 사용자는 비밀번호를 의심하며 같은 시도를 반복하고, 운영자는 메일 설정이 깨진
사실을 알 방법이 없다.
- 공개 본인인증 경로(`identity/verify`·`cancel`)가 로그인 목적의 challenge 를 소진하지
못하도록 403 게이트를 세웠다. 소진되면 그 challenge 로 영영 로그인할 수 없다.
- 로그인 시도 제한 429 응답이 다국어 문구를 싣도록 했다(종전에는 프레임워크 기본 영문).
- 다국어 파라미터에서 파이프 표현식이 평가되지 않아 「유효시간 까지」처럼 값이 빠지던
문제를 함께 고쳤다. 같은 결함이 문의 목록 화면에도 있었다.
## 이번 점검에서 함께 고친 것
- 계정 잠금(423)·발송 실패(503) 응답이 사용자·관리자 컨트롤러에 동일하게 복제돼 있었고
그 주석 자신은 "단일 지점에서 만든다" 고 적혀 있었다. 페이로드에 필드가 하나 추가되면
한쪽만 따라가 같은 실패를 두 화면이 다르게 안내하게 된다 — 트레이트로 통합했다.
- 테스트가 개발자 자신의 사이트 설정을 읽고 있었다. 2단계 인증을 켜 둔 환경에서는 로그인
성공을 전제한 테스트가 503 으로 깨지는데 실패 메시지가 원인을 가리키지도 않는다.
같은 결함군을 위해 이미 존재하던 단일 지점에 그 축을 추가했다.
## 버전
코어 7.0.11 · sirsoft-basic 1.1.4 · sirsoft-admin_basic 1.0.9 ·
번들 일본어팩 3종 · 템플릿 엔진 engine-v1.65.0.
50 lines
3.0 KiB
PHP
50 lines
3.0 KiB
PHP
<?php
|
|
|
|
return [
|
|
// Authentication related messages
|
|
'login_success' => 'Login successful.',
|
|
'login_failed' => 'Authentication failed.',
|
|
'two_factor_required' => 'A verification code has been sent. Enter it to finish signing in.',
|
|
'two_factor_failed' => 'The verification code is incorrect or has expired.',
|
|
'two_factor_invalid_challenge' => 'Verification request not found. Please sign in again.',
|
|
'two_factor_delivery_failed' => 'Could not send the verification code. Please contact the administrator.',
|
|
'register_success' => 'Registration successful.',
|
|
'register_failed' => 'Registration failed.',
|
|
'logout_success' => 'Logout successful.',
|
|
'logout_all_devices_success' => 'Logged out from all devices.',
|
|
'password_reset_success' => 'Password has been successfully reset.',
|
|
'password_reset_failed' => 'Password reset failed.',
|
|
'invalid_credentials' => 'Invalid credentials.',
|
|
'admin_login_success' => 'Admin login successful.',
|
|
'admin_required' => 'Administrator privileges required.',
|
|
'unauthenticated' => 'Authentication required.',
|
|
'permission_denied' => 'Permission denied.',
|
|
'layout_permission_denied' => 'You do not have permission to access this layout. (Required: :required_permissions)',
|
|
'layout_guest_permission_denied' => 'Authentication required to access this layout. (Required: :required_permissions)',
|
|
'invalid_permission_type' => 'Invalid permission type.',
|
|
'role_denied' => 'Role access denied.',
|
|
'email_not_registered' => 'Email address is not registered.',
|
|
'guest_permission_denied' => 'Guests are not allowed to perform this action. Login required.',
|
|
'scope_denied' => 'You do not have access to this resource.',
|
|
'scope_type_all' => 'All',
|
|
'scope_type_self' => 'Self only',
|
|
'scope_type_role' => 'Shared roles',
|
|
'invalid_token' => 'Invalid authentication token.',
|
|
'token_expired' => 'Authentication token has expired. Please login again.',
|
|
'user_not_found' => 'User not found.',
|
|
'account_inactive' => 'Your account is inactive. Please contact the administrator.',
|
|
'account_blocked' => 'Your account has been blocked. Please contact the administrator.',
|
|
'account_withdrawn' => 'This account has been withdrawn.',
|
|
'account_pending_verification' => 'Identity verification is not complete. Please complete the email verification.',
|
|
'account_locked' => 'Too many failed login attempts. Your account is locked for :minutes minute(s).',
|
|
'account_locked_permanently' => 'Too many failed login attempts. Your account has been locked. Please contact an administrator.',
|
|
'too_many_attempts' => 'Too many requests. Please try again in :seconds second(s).',
|
|
'account_unlocked' => 'The account lock has been released.',
|
|
|
|
// Password reset
|
|
'reset_token_invalid' => 'Invalid password reset token.',
|
|
'reset_token_expired' => 'Password reset token has expired. Please request again.',
|
|
'password_reset_email_sent' => 'Password reset email has been sent.',
|
|
'email_send_failed' => 'Failed to send email. Please try again later.',
|
|
];
|