Closed
Conversation
Collaborator
Author
|
민수햄 비상!!!!!!!!!!!!!!!!!! |
Collaborator
Author
|
42 minutes ago <- 42분째 도는데 이거 맞음? 진짜 모름.... |
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.
이미지 업로드 보안성 높이기
Apache Tika 의존성 추가
Double Extension 공격 방어 코드 추가
-> 기존 generateUniqueFileName 메서드에서 test.php.jpg 같은 이중 확장자를 허용하는 문제
파일명을 점(.)으로 분리하여 개수를 체크하는 검증 로직을 추가
위험한 확장자 블랙리스트(jsp, php, asp 등)를 만들어 파일명 어디에든 해당 확장자가 포함되면 차단
허용된 확장자 화이트리스트(jpg, jpeg, png, gif, webp)만 통과하도록 이중 검증을 추가
null byte injection 공격 방어를 위해 파일명에 \0이 포함되어 있는지 검사
파일명 길이를 255자로 제한하여 버퍼 오버플로우를 방지
Magic Number(파일 시그니처) 검증 기능 추가
Content-Type 헤더는 클라이언트가 조작 가능하므로 신뢰 불가능
verifyImageSignature 메서드를 새로 만들어 파일의 실제 바이트를 읽어 진짜 이미지 파일인지 확인
JPEG는 FF D8 FF로 시작하는지, PNG는 89 50 4E 47로 시작하는지 등 각 이미지 포맷의 고유 시그니처를 검증
IMAGE_SIGNATURES라는 static Map을 추가하여 각 이미지 타입별 시그니처를 정의
Apache Tika를 통한 실제 MIME 타입 검출
validateImageFile 메서드에 Tika를 사용한 MIME 타입 검출 로직을 추가
클라이언트가 보낸 Content-Type과 Tika가 검출한 실제 타입을 비교하여 불일치 시 경고 로그를 남김
실제 검출된 MIME 타입이 허용된 이미지 타입 목록에 있는지 최종 검증
메모리 기반 DoS 공격 방어 추가
참고로 위에 있는 대부분의 보안적 코드는 클로드가 작성해준다는 것을 알아주십쇼. (보안력 다 빠짐 이슈)
저는 먼저 코드를 작성 후 해당 보안 이슈에 대해 블로그, 공식 문서로 공부하고 있습니다.
그렇기에 먼저 PR을 작성해서 올려두고 계속 공부하면서 수정과 추가를 이어나갈 계획입니당
한번에 다 올리면 나도 기억 못해
고민중인 거 : Rate Limiting 추가 <- 예전에 혼자 Spring 가지고 놀 때 한번 만들어본 경험은 있음.
댓글로 한번씩 피드백 주시기를 오네가이시마스