cors 에러 조치 / Access-Control-Allow-Origin / access-control-allow-credentials

 

오류 내용 

Response to preflight request doesn't pass access control check: 
The value of the 'Access-Control-Allow-Origin' header in the response must not be the wildcard '*' when the request's credentials mode is 'include'. 
The credentials mode of requests initiated by the XMLHttpRequest is controlled by the withCredentials attribute.

 

 

서버 환경 

access-control-allow-origin: *

CORS설정으로 웹 브라우저에서 다른 도메인의 API를 사용할 때, 보안을 위해 설정된 보안 정책입니다.

* 값은 모든 도메인으로부터의 접근 허용이니다.  

(자세한 내용은 링크 참고 https://sh-safer.tistory.com/326 )

 

access-control-allow-credentials: true

http요청 시 인증 정보가 포함되는 경우 

access-control-allow-credentials 헤더값은 "true"로 설정해야 함.

 

 

정리

오류 내용인 즉슨, 요청에 인증정보(쿠키전달)가 포함된 경우(access-control-allow-credentials: true

Access-Control-Allow-Origin 헤더 값은 " * " 이 아니어야 한다는 내용입니다.

 

 

조치

Access-Control-Allow-Origin 헤더 값에 * 대신 허용이 필요한 도메인 정보를 넣어주거나

오리진의 헤더 정보를 그대로 사용하도록  설정

댓글

Designed by JB FACTORY

loading