티스토리 뷰

1. 파일 업로드 / 다운로드 취약점


- 업로드 기능에서 파일 사이즈의 제한을 주지 않을 경우


- 파일 타입의 체크가 없는 경우


- 파일이 업로드 되는 경로가 외부에서 직접적으로 접근 가능하거나 실행 권한을 가지게 되는 경우



2. 취약점 제거를 위한 보안코딩 기법


- 업로드 되는 타입이나 확장자를 체크하여 허용되는 확장자 또틑 타입의 경우에만 업로드 할 수 있도록 한다.


- 업로드 되는 파일은 외부에서 직접 접근이 불가능한 경로에 저장한다.


- 업로드되는 파일의 이름과 실제 저장되는 파일의 이름을 다르게하여 공격자가 파일을 직접 엑세스 할 수 없도록 한다.



3. 시큐어 코딩


 - 파일 확장자를 체크한다.


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
 if!uploadedFile.isEmpty() ) {
            
            String fileName = uploadedFile.getOriginalFilename();
            
            if ( fileName.toLowerCase().endsWith(".jpg"
                    || fileName.toLowerCase().endsWith(".jpeg"
                    || fileName.toLowerCase().endsWith(".png"
                    || fileName.toLowerCase().endsWith(".gif")
                    || fileName.toLowerCase().endsWith(".bmp")) {
                
                // 외부 URL 접근이 가능함.
                File file = new File(FILE_PATH, uploadedFile.getOriginalFilename());
                try {
                    uploadedFile.transferTo(file);
                    board.setFileName(uploadedFile.getOriginalFilename());
                } catch (IllegalStateException | IOException e) {
                    e.printStackTrace();
                }
  }
cs




 - 외부에서 접근되지 않도록 웹 서버와 다른 파일 시스템을 사용하게 설정한다.


1
String uploadPath = session.getServletContext().getRealPath("/" + "WEB-INF/files/";
cs


- 파일 사이즈 Context.xml 에서 설정하기


1
2
3
4
5
    <bean id="multipartResolver"
          class="org.springframework.web.multipart.commons.CommonsMultipartResolver" >
        <property name="maxUploadSize" value="104857600" /<!-- 100MB -->
        <property name="defaultEncoding" value="UTF-8" />
    </bean>
cs




'Secure Coding' 카테고리의 다른 글

안전하지 않은 예외처리  (2) 2016.05.02
크로스 사이트 요청 위조 [ CSRF ]  (0) 2016.04.29
크로스 사이트 스크립팅 [ XSS ]  (0) 2016.04.29
로그인 시도 횟수 제한  (0) 2016.04.28
패스워드 정책  (0) 2016.04.28
댓글
공지사항
최근에 올라온 글
최근에 달린 댓글
Total
Today
Yesterday
«   2024/05   »
1 2 3 4
5 6 7 8 9 10 11
12 13 14 15 16 17 18
19 20 21 22 23 24 25
26 27 28 29 30 31
글 보관함