Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

프로필 파일 업로드 취약점 패치 #342

Merged
merged 3 commits into from
Jul 3, 2024
Merged

프로필 파일 업로드 취약점 패치 #342

merged 3 commits into from
Jul 3, 2024

Conversation

Jueuunn7
Copy link
Contributor

@Jueuunn7 Jueuunn7 commented Jul 3, 2024

💡 배경 및 개요

프로필사진 파일 업로드 취약점을 보완하였습니다.

Resolves: #341

📃 작업내용

해당 취약점을 패치 후 필요없는 로직을 삭제하였습니다.

✅ PR 체크리스트

템플릿 체크리스트 말고도 추가적으로 필요한 체크리스트는 추가해주세요!

  • 이 작업으로 인해 변경이 필요한 문서가 변경되었나요? (e.g. .env, 노션, README)
  • 이 작업을 하고나서 공유해야할 팀원들에게 공유되었나요? (e.g. "API 개발 완료됐어요", "환경값 추가되었어요")
  • 작업한 코드가 정상적으로 동작하나요?
  • Merge 대상 브랜치가 올바른가요?
  • PR과 관련 없는 작업이 있지는 않나요?
  • 이 작업으로 인해 발생한 변경 사항이 Resource 서버에도 반영되었나요?

@Jueuunn7 Jueuunn7 changed the title 프로필 업로드 취약점 패치 프로필 파일 업로드 취약점 패치 Jul 3, 2024
@@ -21,11 +21,8 @@ class S3Util(

val splitFile = image.originalFilename.toString().split(".")

if(splitFile.size < 2)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

위 검증 로직이 잘못되어있는 것 같네요

splitFile의 인자가 2개 미만이면 if문을 실행시키는 것으로 보이는데

만약에 script.svg.php라면 splitFile 배열에 담기는 것은 [script, svg, php]가 담기게 되는데 이것이 if문의 결과를 false로 만들게 되네요 그래서 통과가 되던 것 같구요

그래서 last()를 사용하는 법도 있겠지만 splitFile.size >= 2로 바꾸는 것도 방법이 될 수 있을 것 같습니다

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

리뷰 해주셔서 감사합니다.🙇🙇

splitFile.size >= 2 이렇게 if문을 바꾸는 방법도 좋은 방법인것 같습니다.

해당 취약점은 .의 갯수가 여러개라서 발생하는것보단 확장자를 한번 더 덮어씌우는데 중점이 있습니다.

만약에 사용자가 hello.world.png파일을 업로드하게 되면 정상적인 파일도 .이 2개 이상이 되기 때문에 정상적인 파일도 필터링 해서 가용성에 문제가 생길수도 있을 것 같습니다.

이 두가지의 이유와 가독성이 향상되는 이유로 last()를 사용하는 것은 어떨까요?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

잘못 전달한 부분이 있네요 일단 그 부분에 대해서는 사과 드립니다

저도 배열에 직접 접근하는 것 보다는 last() 사용하는 것이 더 좋아보이네요
하지만 한번 더 정확한 검증을 위해서 If문을 삭제하지 않고 처음부터 xxx.xxx의 형식인 파일만 받을 수 있도록 하자는 취지로 삭제한 If문을 되돌리며 동시에 처음에 제시한 조건이 아닌 if(splitFile.size != 2)로 변경하자는 의견이었습니다

빠르게 답변 드리려다 보니 깊게 생각하지 못하고 잘못된 조건을 전달드렸네요

Copy link
Contributor Author

@Jueuunn7 Jueuunn7 Jul 3, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

좋은 의견 감사합니다.🙇🙇

if문을 사용하면 검증을 더욱 정확히 할 수 있지만 last()보단 가용성이 떨어질 수 있습니다.
또한 last()를 사용하면 가용성과 가독성을 향상시킬 수 있지만 if문 보단 무결성이 떨어질 수 있습니다.

무결성, 가용성과 가독성의 균형을 맞춰야하는 문제 같은데 저는 last()를 사용하는 방법이 더 이점이 많다고 생각합니다.

어떻게 생각하시나요?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

두개 전부 반영하자는 의견이었습니다!!

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

cb4740e
전부 반영하는 방법도 좋은 방법 같습니다! 수정했습니다.

Copy link
Contributor

@KimTaeO KimTaeO left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

저희 프로젝트에 관심을 가지고 기여해주셔서 진심으로 감사드립니다.
앞으로도 많은 관심 부탁드리겠습니다
수고하셨습니다!! 👍 👍

@KimTaeO KimTaeO merged commit ffb204d into GSM-MSG:main Jul 3, 2024
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

GAuth-BackEnd에 프로필사진 파일 업로드 취악점이 있습니다.
2 participants