Same-Origin-Policy

Origin에서 불러온 문서나 스크립트가 다른 Origin에서 가져온 리소스와 상호 작용을 제한하는 정책


CORS

웹 브라우저에서 외부 DNS와 통신하기 위한 방식을 표준화한 Specification

 


CORS 요청 종류

  • Simple
  • Preflight
  • Credential
  • Non-Credential

 


Simple Request

  1) GET, HEAD, POST 중의 한 가지 방식 사용
  2) POST 방식일 경우 Content-type 이 셋 중 하나
         - application/x-www-form-urlencoded
         - multipart/form-data
         - text/plain (default)
3) Custom header 를 전송하지 않음


Preflight Request

1) GET, HEAD, POST 외의 다른 방식으로도 요청을 보낼 수 있음
2) application/xml 처럼 다른 Content-type 으로 요청을 보낼 수 있음
3) Custom header 사용 가능


Credential Request

Credential Request 는 HTTP Cookies 와 HTTP Authentication 정보를 인식할 수 있도록 하는 요청


Non-Credential Request

아무런 설정을 하지 않은 경우 CORS 요청은 기본적으로 Non-Credential Requset

 


CORS Header 종류

  • Access-Control-Allow-Origin
    단일 출처를 지정하여 브라우저가 해당 출처가 리소스에 접근하도록 허용
  • Access-Control-Allow-Headers
    실제 요청 시 사용할 수 있는 HTTP Header 지정
  • Access-Control-Allow-Methods
    리소스에 접근할 때 허용되는 Method 지정
  • Access-Control-Allow-Age
    preflight request 요청 결과를 캐시할 수 있는 시간(단위:second)을 지정
  • Access-Control-Allow-Credentials
    credentials 플래그가 true 일 때, 요청에 대한 응답을 표시하기 위해 사용, 설정하지 않을 경우 브라우저에서 응답 무시
  • Access-Control-Expose-Headers
    브라우저가 접근할 수 있는 헤더를 서버의 화이트 리스트에 추가할 때 사용

WebtoB 설정

http.m

1. vhost에 header 추가

2. Headers 절 추가


Error 로그 

1. "The 'Access-Control-Allow-Origin' header contains multiple values '*, *', but only one is allowed.
-> NODE절과 VHost 절에 똑같은 Header가 들어있는 경우, 중복 에러가 나오게 된다. 중복된 Header를 삭제한다.

 

2.Access to fetch at 'https://A사이트' from origin 'http://localhost:8080' has been blocked by CORS policy: Response to preflight request doesn't pass access control check: Redirect is not allowed for a preflight request.

-> CORS 정책상 https -> http로의 접근이 불가능하다. https -> https 또는 http -> https 설정으로 호출해야 한다.

+ Recent posts