WEB-SER-003: 부적절한 이용자 인가 | 위험도: 5 (매우 높음)
해커가 보는 브라우저
시나리오를 선택하세요
// Controller.java
@GetMapping("/account")
public Account getAccount(@RequestParam Long id) {
// ❌ 문제점 1: 세션 확인도 안함!
// ❌ 문제점 2: 권한 검증 없음!
return accountRepository.findById(id);
}
// SQL 실행됨
SELECT * FROM accounts WHERE id = ?
-- userId 조건 없음! (치명적)
XX은행 서버 처리 과정
// Controller.java
@GetMapping("/account")
public Account getAccount(
@RequestParam Long id,
@AuthenticationPrincipal User user) {
// ✅ 1단계: 인증 확인 (Spring Security)
if (user == null) {
throw new UnauthorizedException();
}
Account account = accountRepository
.findById(id)
.orElseThrow();
// ✅ 2단계: 권한 검증 (핵심!)
if (!account.getUserId().equals(user.getId())) {
// 로깅 추가
logger.warn("Unauthorized access attempt: " +
"user={}, account={}",
user.getId(), id);
throw new ForbiddenException();
}
return account;
}
// 또는 Repository에서 해결 (더 안전)
accountRepository.findByIdAndUserId(id, user.getId())
// SQL 실행됨
SELECT * FROM accounts
WHERE id = ? AND user_id = ?
-- user_id 조건 필수!