Skip to content
Download

addCsrf

mach::AppBuilder::addCsrf

Adds CSRF protection.

Adds CSRF protection to the application.

// (1)
AppBuilder& addCsrf();
// (2)
template <typename TConfigure>
requires std::invocable<TConfigure, CsrfBuilder&>
AppBuilder& addCsrf(TConfigure&& configure);

A reference to the current AppBuilder instance.

Parameter Description
TConfigure The type of the callable used to configure CSRF.
Parameter Description
configure A callable that receives a CsrfBuilder used to configure CSRF.
  • In overload (2), the configuration callable is invoked immediately and receives a CsrfBuilder by reference.
  • Changes made after App::run() has been called do not take effect.

This method is not thread-safe and should only be called during application configuration, before the application starts handling requests.

builder.addCsrf();
builder.addCsrf([](mach::CsrfBuilder& csrf) {
csrf.cookieName("csrf-token")
.headerName("X-CSRF-Token");
});
Name Description
CsrfBuilder Configures CSRF.