How do I hand over the csrf token when I submit a form in a new window?

29 Views Asked by At
<body>
    <form:form id="gotoPopupPreview" name="gotoPopupPreview" method="post" action="">
        <input type="hidden" name="isPreview" value="Y">
        <input type="hidden" name="nttId" value="${searchVO.nttId}">
        <!--...(skip)-->
    </form:form>

    <script>
        function openPreview(url, target, otherData){
        var f = $("#gotoPopupPreview");
        f.attr('action', url);
        f.attr('target', target);
    //...(skip)
        window.open('', target);
        f.submit();
    }

    $("submitBtn").click(function(){
        var otherData = 'blahblah';
        openPreview("http://www.test.or.kr/", 'test', otherData);
    });
    </script>
</body>

The above is the code I wrote. I created a form tag and sent a submit by opening a new window in the script.

But on the server "AccessDeniedException : org.springframework.security.web.csrf.MissingCsrfTokenException: Could not verify the provided CSRF token because your session was not found. result :::: {"result" : "fail", "message" : "Could not verify the provided CSRF token because your session was not found."}"

With this message, it says there is no csrf token..

I saw an article that if you use form taglib in JSP, you will automatically put tokens in, so I wrote it as above, and if I look at the source, it seems to contain tokens well, but I don't know why such an exception appears.

Is it a problem to open it with a new window? In this case, how should I put the token in?

I'm sorry that I'm not good at English.

0

There are 0 best solutions below