테스트 환경

Web 서버 CDN
EC2 인스턴스 2개, ELB 연동 S3 + CloudFront

Web 서버에서의 테스트 코드 (test.php)

<!DOCTYPE html>
<html>
    <head>
        <script>
            function cors() {
                var xhttp = new XMLHttpRequest();
                xhttp.onreadystatechange = function() {
                    if (this.readyState == 4 && this.status == 200) {
                        alert(this.responseText);
                    }
                };
                xhttp.open("GET", "http://CDN주소.cloudfront.net/secret.txt", true);
                xhttp.send();
            };
        </script>
    </head>

    <body onload="cors()">
        <h2>CORS Exploit</h2>
        <h3>CDN data</h3>
    </body>
</html>

CDN에 업로드 한 테스트 코드 (secret.txt)

secret code

CORS 정책 위반 상황

온프레미스 환경과 마찬가지로 CORS 정책 위반으로 인해 secret.txt 파일을 불러올 수 없다.




해결 방법

온프레미스 환경에서는 CDN 환경으로 사용한 Web2 서버에서 “Access-Control-Allow-Origin” 설정을 했지만 AWS는 S3 버킷 권한 설정에서 할 수 있다.




secret.txt 관련 HTTP 헤더

Tags: ,

Categories:

Published:

Updated: