Skip to content
Download

CsrfBuilder

mach::CsrfBuilder

Configures the application’s Cross-Site Request Forgery (CSRF) protection.

Primary header:

#include <mach/CsrfBuilder.hpp>

Convenience header:

#include <mach/mach.hpp>
class CsrfBuilder {
public:
CsrfBuilder(const CsrfBuilder&) = delete;
CsrfBuilder& operator=(const CsrfBuilder&) = delete;
CsrfBuilder(CsrfBuilder&&) noexcept = default;
CsrfBuilder& operator=(CsrfBuilder&&) noexcept = default;
~CsrfBuilder() = default;
CsrfBuilder& cookieName(std::string_view name);
CsrfBuilder& headerName(std::string_view name);
};
Name Description
cookieName Sets the name of the cookie used to store the CSRF token.
headerName Sets the name of the request header used to submit the CSRF token.

This class is not thread-safe. CSRF configuration should be performed from one thread.

  • A CsrfBuilder instance is owned by the framework and is provided to the CSRF configuration callback.
  • The configured CSRF state is transferred to the application when the callback returns. The builder is valid only for the duration of the callback and must not be stored or used afterward.
builder.addCsrf([](mach::CsrfBuilder& csrf) {
csrf.cookieName("csrf-token");
csrf.headerName("X-Mach-CSRF");
});
Name Description
AppBuilder Builds and configures a Mach application.