본문 바로가기
Etc

BE개발자가 모르면 안되는 것 - 정보 누출

by SuperDT 2025. 4. 6.

Information Leakage는

 

아래와 같이 민감한 정보(사용자 ID, 비밀번호, 서버 정보 등)가

로그 또는 오류 메시지를 통해 외부에 노출되는 경우를 말한다

@GetMapping("/user/{id}")
public ResponseEntity<?> getUser(@PathVariable Long id) {
    User user = userService.getUserById(id);
    if (user == null) {
        return ResponseEntity.status(HttpStatus.NOT_FOUND)
            .body("사용자가 존재하지 않습니다: " + id); //ID 노출 위험
    }
    return ResponseEntity.ok(user);
}

 

공통 에러 메시지 사용하여

공격자가 사용자 ID 추측할 수 없도록 실패 응답 작성

@GetMapping("/user/{id}")
public ResponseEntity<?> getUser(@PathVariable Long id) {
    return userService.getUserById(id)
        .map(user -> ResponseEntity.ok(user))
        .orElse(ResponseEntity.status(HttpStatus.NOT_FOUND).body("아이디 또는 비밀번호가 일치하지 않습니다."));
}