Orbit Framework
An ultra-modern, asynchronous, cross-platform C++ Web Framework.
Loading...
Searching...
No Matches
middleware::Csrf Class Reference

Cross-Site Request Forgery (CSRF) protection middleware. More...

#include <Csrf.hpp>

Public Member Functions

 Csrf (const std::string &cookie_name="csrf_token", const std::string &header_name="X-CSRF-Token")
 Constructs a new Csrf middleware instance.
 
bool operator() (http::HttpRequest &req, std::shared_ptr< http::ResponseWriter > writer)
 Middleware execution operator.
 

Static Public Member Functions

static std::string generate_random_token ()
 Generates a random CSRF token.
 

Detailed Description

Cross-Site Request Forgery (CSRF) protection middleware.

Constructor & Destructor Documentation

◆ Csrf()

middleware::Csrf::Csrf ( const std::string &  cookie_name = "csrf_token",
const std::string &  header_name = "X-CSRF-Token" 
)

Constructs a new Csrf middleware instance.

Parameters
cookie_nameThe name of the cookie to store the CSRF token.
header_nameThe name of the header expected in requests.

Member Function Documentation

◆ generate_random_token()

std::string middleware::Csrf::generate_random_token ( )
static

Generates a random CSRF token.

Returns
std::string The generated token.

◆ operator()()

bool middleware::Csrf::operator() ( http::HttpRequest req,
std::shared_ptr< http::ResponseWriter writer 
)

Middleware execution operator.

Parameters
reqThe HTTP request.
writerThe HTTP response writer.
Returns
true If the request should continue to the next handler.
false If the request should be blocked.

The documentation for this class was generated from the following files: