CSRF in Java+Spring+Thymeleaf

CSRF in Java+Spring+Thymeleaf

rytisrytis Posts: 4Questions: 1Answers: 1

Want to share my findings, which might look lik very simple and intuitive, but it took me couple days of research.
If anyone will want to use CSRF protection in Java+Spring+Thymeleaf environment and use POST method, the one should add the following code to DataTable section:

            ajax: {
                "url": "/modules/getSomething",
                "type": "POST",

                data: { "_csrf" :[[${_csrf.token}]] },
                dataSrc: function ( json ) {
                    if(json.csrf_token !== undefined) $("meta[name=_csrf]").attr("content", json.csrf_token);
                    return json.data;
                }

            },

Replies

  • allanallan Posts: 63,731Questions: 1Answers: 10,508 Site admin

    Hi,

    Thanks for posting this! I'm sure others will find it useful.

    Allan

This discussion has been closed.