liveBook · Manning

Mutation

As explained in Spring Security in Action, Second Edition

A mutating operation is an application operation that changes stored data or other server-side state.

A mutating operation changes stored data or other server-side state. In browser applications, CSRF protection requires these requests to carry a token so a foreign page cannot act as the logged-in user. section 9.1 section 9.2

Spring Security handles mutation requests through this sequence:

  • Allow GET, HEAD, TRACE, and OPTIONS requests without a CSRF token. section 9.1
  • Generate a token when the user first loads a page with an HTTP GET request. section 9.1
  • Require POST, PUT, DELETE, and other mutating requests to return the token in a header or form field. section 9.1 section 9.2
  • Reject a missing or incorrect token with HTTP 403 Forbidden. section 9.1

Protecting a product form

A POST endpoint such as /product/add is rejected until the Thymeleaf form includes a hidden input containing ${_csrf.parameterName} and ${_csrf.token}; after that, the controller action runs. section 9.2

Figure 9.2 To make a POST request, the client needs to add a header containing the CSRF token. The application generates a CSRF token when the page is loaded (via a GET request), and the token is added to all requests that can be made from the loaded page. This way, only the loaded page can make mutating requests.

Shows how a page-loaded token is added to POST requests so only the loaded application page can perform mutations. section 9.1

How Spring Security in Action, Second Edition covers it

How deep it goes
Explains token generation, filter enforcement, form integration, and 403 failures, while deferring broader CSRF theory.
Examples
Uses GET and POST hello endpoints, default form login, a product form, curl requests, and a custom token-logging filter.
What it assumes
Assumes basic Spring and Java knowledge while teaching CSRF token handling and default form-login protection through a small application.
What you can do after
Operate/configure Spring Security to protect POST forms and diagnose missing-token failures through HTTP 403 responses.
How it connects
Connects mutation with CSRF protection, HTTP methods, CSRF tokens, Spring Security, and the filter chain.

Also explained in

Compare how 12 books explain mutation →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Spring Security in Action, Second Edition. The section links point to the parts of the book it draws on.