javaspringspring-securityspring-bootx-frame-options

How to disable 'X-Frame-Options' response header in Spring Security?


I have CKeditor on my JSP and whenever I upload something, the following error pops out:

 Refused to display 'http://localhost:8080/xxx/xxx/upload-image?CKEditor=text&CKEditorFuncNum=1&langCode=ru' in a frame because it set 'X-Frame-Options' to 'DENY'.

I have tried removing Spring Security and everything works like a charm.


Solution

  • By default X-Frame-Options is set to denied, to prevent clickjacking attacks. To override this, you can add the following into your spring security config

    <http>    
        <headers>
            <frame-options policy="SAMEORIGIN"/>
        </headers>
    </http>
    

    Here are available options for policy

    For more information take a look here.

    And here to check how you can configure the headers using either XML or Java configs.

    Note, that you might need also to specify appropriate strategy, based on needs.