티스토리 뷰

Spring

[ Spring Boot ] X-Frame-Options 설정

구티맨 2020. 3. 18. 12:41

X-Frame-Options 헤더는 clickjacking attack을 방지하기 위해 사용하는 헤더이다.

<frame> <iframe>, <embed> or <object> tag에 페이지 렌더링을 허용할지 말지를 정의 할 수 있다.

SAMEORIGIN

같은 origin(서버) 에서는 렌더링을 허용

DENY

렌더링을 허용하지 않음

ALLOW-FROM url

특정 url에서만 렌더링을 허용

 

코드

httpSecurity.headers().frameOptions().disable().addHeaderWriter(
                            new XFrameOptionsHeaderWriter(
                                    new StaticAllowFromStrategy(URI.create("*"))
                            )
                    )

: httpSecurity 에서 allow-from 으로 모든 URI를 허용하는 코드이다.

httpSecurity.headers().frameOptions().disable().addHeaderWriter(
                            new XFrameOptionsHeaderWriter(
                                    new WhiteListedAllowFromStrategy(Arrays.asList("http://www.example.com","http://www.example2.com"))
                            )
                    )

: whiteList로 허용하는 여러 uri 를 지정할 수도 있다.

  단, Request에서 x-frames-allow-from header 에 whitelist 되어 있는 URI를 넣어서 보내야 한다.

  그렇지 않으면 whitelist에 허용되지 않아 에러가 발생 한다.

참조

https://tools.ietf.org/html/rfc7034
https://stackoverflow.com/questions/56512445/whitelistedallowfromstrategy-does-not-work
https://docs.spring.io/autorepo/docs/spring-security/3.2.0.CI-SNAPSHOT/reference/html/headers.html#headers-frame-options

댓글
공지사항
최근에 올라온 글
최근에 달린 댓글
Total
Today
Yesterday
링크
«   2024/03   »
1 2
3 4 5 6 7 8 9
10 11 12 13 14 15 16
17 18 19 20 21 22 23
24 25 26 27 28 29 30
31
글 보관함