Orbit Framework 2.0.0
A high-performance asynchronous C++20 HTTP server framework.
Loading...
Searching...
No Matches
orbit::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.
 

Private Attributes

std::string cookie_name_
 
std::string header_name_
 

Detailed Description

Cross-Site Request Forgery (CSRF) protection middleware.

Constructor & Destructor Documentation

◆ Csrf()

orbit::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()

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

Generates a random CSRF token.

Returns
std::string The generated token.

◆ operator()()

bool orbit::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.

Member Data Documentation

◆ cookie_name_

std::string orbit::middleware::Csrf::cookie_name_
private

◆ header_name_

std::string orbit::middleware::Csrf::header_name_
private

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