Spring Security Redirect Location이 Mixed Content로 차단되는 경우

Mineru·2022년 5월 20일
0

Mixed Content란?

  • Google은 https 사이트에서 http 컨텐츠가 혼합이 된 경우를 https 보안에 있어 큰 문제라 생각하여 크롬에서는 이를 차단시켰습니다.

배포

  1. Nginx + Spring Boot 2.6.6(with Embedded Tomcat) + Spring Security 조합
  2. Nginx에서 ssl http2 적용
  3. Spring 구현 서버에서 Spring Security를 이용하여 ThirdParty Login을 지원
  4. ThirdParty Login 관련 토큰 값이 없거나 유효하지 않은 경우, Spring Security가 로그인 페이지로 리다이렉트
    → 문제! 리다이렉트하라고 내려준 Location의 정보가 HTTP로 되어 있음
  5. Mixed Content 발생(HTTPS에서 HTTP를 호출해야하기 때문)

원인

  1. Spring Security는 Tomcat으로 올린 서버에 설정되어있는데, 이는 https로 떠있음을 인지하지 못함 : HTTPS는 NGINX에 설정했기 때문
  2. 따라서, location 헤더에 ThirdParty 로그인 Redirect Page를 HTTP 프로토콜이라고 알려줌
  3. HTTPS로 요청한 부분에서, HTTP로 Redirect 하라고 정보가 내려오니 Mixed Content 문제 발생

해결 방안

  1. Nginx location 블록 아래에 proxy_set_header X-Forwarded-Proto $scheme; 코드 적용
  2. Spring application.yml에 해당 코드 추가
    server.tomcat.use-relative-redirects=true

출처

아래 출처와 개발바닥 커뮤니티에서 나온 의견을 통해서 해당 문제 해결했습니다.
https://velog.io/@jamie/mixed-content-error

profile
Daily Coding

0개의 댓글