IT

스프링 부트 img-src 특정 url 추가방법 Content Security policy directive :"img-src 'self' data:

프로개발러 2023. 7. 31. 15:20
반응형

가장 중요한 것은 아무리 html meta태그에 csp를 추가해도

 

아래와 같이 contentSecurityPolicy가 적용 우선 순위가 높다.

@Override
protected void configure(HttpSecurity http) throws Exception {
    http
    .headers()
    .contentSecurityPolicy(

 

그리고 만약 contentSecurityPolicy에 적용했는데도 적용이 안되면

다른 설정파일이 더 있는지 체크...

 

그리고 

 

http
.headers()
.contentSecurityPolicy(
    "default-src 'self' 'unsafe-inline'; "
    + "script-src 'self'; "
    + "object-src 'none'; "
    + "base-uri 'none'; "
    + "img-src www.naver.com 'self' data:; "
    + "connect-src *; "
    );

이런식으로 img-src에 www.naver.com  url만 추가하면 됨.

 

https 붙여도 되고 www.naver.com/  해도 되지만

주의할 것이 'self' 추가해야 하고 data할 때 data   >>>>: <<<< 추가해야 함.

반응형