CsrfBuilder
mach::CsrfBuilder
Description
Section titled “Description”Configures the application’s Cross-Site Request Forgery (CSRF) protection.
Headers
Section titled “Headers”Primary header:
#include <mach/CsrfBuilder.hpp>Convenience header:
#include <mach/mach.hpp>Syntax
Section titled “Syntax”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);};Member Functions
Section titled “Member Functions”| 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. |
Thread Safety
Section titled “Thread Safety”This class is not thread-safe. CSRF configuration should be performed from one thread.
Ownership
Section titled “Ownership”- A
CsrfBuilderinstance 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.
Example
Section titled “Example”builder.addCsrf([](mach::CsrfBuilder& csrf) { csrf.cookieName("csrf-token"); csrf.headerName("X-Mach-CSRF");});See Also
Section titled “See Also”| Name | Description |
|---|---|
AppBuilder |
Builds and configures a Mach application. |