컴공생의 다이어리
[스프링, Spring] spring security 적용 후 Refused to display in a frame because it set 'X-Frame-Options' to 'DENY' 발생 본문
[스프링, Spring] spring security 적용 후 Refused to display in a frame because it set 'X-Frame-Options' to 'DENY' 발생
컴공 K 2022. 2. 5. 00:01spring security 적용 후 Refused to display in a frame because it set 'X-Frame-Options' to 'DENY' 발생
spring 프로젝트에 naver smarteditor2를 적용하려고 하니 Refused to display "http://localhost:8080/~" in a frame because it set 'X-Frame-Options' to 'DENY'라는 오류가 발생해 제대로 적용되지 않았다. 이유를 찾아보니 spring security를 적용하면 기본적으로 X-Frame-Options Click jacking 공격 막기 설정이 되어있기 때문이었다.
X-Frame-Options 종류로는 아래 3가지가 있는데 이번 오류는 SAMEORIGIN 옵션을 사용해서 해결할 것이다.
- DENY : 해당 페이지는 frame을 표시할 수 없음
- SAMEORIGIN : 해당 페이지와 동일한 orgin에 해당하는 frame만 표시할 수 있음
- ALLOW-FROM uri : 해당 페이지는 지정된 orgin에 해당하는 frame만 표시할 수 있음
따라서 이와 관련된 설정을 해주어야 한다. spring security관련해서 설정한 xml 파일에서 <http auto-config='true' use-expressions="true"> 태그 밑에 표시한 부분을 추가해주면 된다.
<http auto-config='true' use-expressions="true">
<!-- 여기부터 -->
<headers>
<frame-options policy="SAMEORIGIN"/>
</headers>
<!-- 여기까지 추가-->
....
</http>
만일 Spring Boot를 사용한다면 xml 파일이 아닌 이와 관련된 Java파일로 설정을 할 것이다. 이 경우에는 아래와 같이 하면 되는 것 같은데 정확히 실행해보지 않았지만 핵심은 http.headers().frameOptions().sameOrigin()을 사용하는 것 같다.
@EnableWebSecurity
public class WebSecurityConfig extends WebSecurityConfigurerAdapter {
@Override
protected void configure(HttpSecurity http) throws Exception {
http
// ...
.headers()
.frameOptions().sameOrigin();
}
}
https://docs.spring.io/spring-security/site/docs/5.0.x/reference/html/headers.html
21. Security HTTP Response Headers
Spring Security allows users to easily inject the default security headers to assist in protecting their application. The default for Spring Security is to include the following headers: For additional details on each of these headers, refer to the corresp
docs.spring.io
https://gigas-blog.tistory.com/124
[Spring] Spring Security에서 'X-Frame-Options'응답 헤더 설정
Spring Boot 2.x 로 개발을 하다보면 어마어마한 문제들이 많이 발생합니다. 최근 보안정책을 준수하기 때문에 일반적으로 사용이 가능한 부분들도 보안취약점으로 구분되기도 하죠. 이번에도 Virtua
gigas-blog.tistory.com
https://goni9071.tistory.com/360
spring security headers frameOptions 선택적 disable
Spring Boot 환경에서 Spring security를 사용하고 있습니다. 원래 ...headers().frameOptions().sameOrigin() 을 기본으로 전체 적용해서 사용하고 있었습니다. 그런데 외부에 iframe에 들어가야하는 페이지가..
goni9071.tistory.com
https://yangbongsoo.tistory.com/10
개발 이슈 모음
1. Spring Security X-Frame-Options 이슈 Default Security Headers Cache-Control: no-cache, no-store, max-age=0, must-revalidate Pragma: no-cache Expires: 0 X-Content-Type-Options: nosniff Strict-Tran..
yangbongsoo.tistory.com
Refused to display in a frame because it set 'X-Frame-Options' to 'DENY' X-frame-Options 응답 헤더 설정
Refused to display 'http://localhost:8080/...' in a frame because it set 'X-Frame-...
blog.naver.com
'Development > Spring & SpringBoot' 카테고리의 다른 글
[스프링 부트, Spring Boot] @Transactional(readOnly = true) 오류 (0) | 2022.02.16 |
---|---|
[MyBatis] 마이바티스 Like문 사용방법 (0) | 2022.02.09 |
[스프링, Spring] JDBC queryForObject의 결과가 없을 때(null) 혹은 결과가 2개 이상일 때 - IncorrectResultSizeDataAccessException (0) | 2022.02.04 |
[스프링, Spring] jsp파일에서 JSTL 사용하기 (0) | 2022.01.21 |
[스프링, Spring] root-context.xml에서 db 정보 properties 파일로 분리 (0) | 2022.01.18 |