Skip to content

Enable CSRF in spring security #10

Description

@Questlog

Hey, a downside of HTMX is that it is does not send CSRF tokens per default. I had some troubles with that.

I would advise against disabling CSRF in the spring security config and instead use this in the thymleaf layout:

<script th:inline="javascript">
    document.body.addEventListener('htmx:configRequest', (event) => {
        event.detail.headers[ [[${_csrf.headerName}]] ] = [[${_csrf.token}]];
    })
</script>

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions