NexusForce 1.0.0
A rigorously engineered full-stack C++ backend library.
载入中...
搜索中...
未找到
http_security.hpp
浏览该文件的文档.
1#ifndef NEFORCE_NETWORK_HTTP_HTTP_SECURITY_HPP__
2#define NEFORCE_NETWORK_HTTP_HTTP_SECURITY_HPP__
3
12
14NEFORCE_BEGIN_NAMESPACE__
15NEFORCE_BEGIN_HTTP__
16
21
30class NEFORCE_API security_headers_filter final : public http_filter {
31public:
33 bool enable_hsts = true;
36 bool hsts_preload = false;
37
40 string frame_option_value{"DENY"};
41
44
46 bool enable_csp = true;
47 string csp_value{"default-src 'self'"};
48
51 string xss_protection_value{"1; mode=block"};
52
55 string referrer_policy_value{"strict-origin-when-cross-origin"};
56
59 string permissions_policy_value{"geolocation=(), microphone=(), camera=()"};
60
61 bool pre_filter(http_request& request, http_response& response) override { return true; }
62 void post_filter(http_request& request, http_response& response) override;
63 void do_filter(http_request& request, http_response& response) override {}
64 NEFORCE_NODISCARD string name() const override { return "security_headers_filter"; }
65};
66
67// TODO: OAuth2 / OIDC authentication filter — implement Authorization Code, Client Credentials, PKCE flows with token validation
68// TODO: JWT token filter — parse, validate (exp/nbf/iss/aud), and extract claims from Bearer tokens; support JWKS key rotation
69// TODO: Role-based access control (RBAC) filter — @PreAuthorize-style method/route-level role & permission checking
70// TODO: Password encoding utilities — BCrypt, Argon2id, PBKDF2 hashing with salt generation and constant-time verification
71 // HTTP
73
74NEFORCE_END_HTTP__
75NEFORCE_END_NAMESPACE__
76#endif // NEFORCE_NETWORK_HTTP_HTTP_SECURITY_HPP__
bool enable_xss_protection
X-XSS-Protection: 浏览器XSS过滤器
void do_filter(http_request &request, http_response &response) override
核心过滤方法
bool enable_frame_options
X-Frame-Options: 防止Clickjacking
string name() const override
获取过滤器名称
bool enable_referrer_policy
Referrer-Policy: 控制Referer头的发送
bool enable_content_type_options
X-Content-Type-Options: 防止MIME类型嗅探
string frame_option_value
DENY | SAMEORIGIN | ALLOW-FROM uri
bool hsts_preload
是否加入HSTS preload列表
bool enable_hsts
HSTS: 强制浏览器使用HTTPS
bool enable_csp
Content-Security-Policy: 内容安全策略
bool enable_permissions_policy
Permissions-Policy: 控制浏览器特性权限
void post_filter(http_request &request, http_response &response) override
后处理方法
string csp_value
可配置的CSP策略字符串
bool hsts_include_subdomains
是否包含子域名
bool pre_filter(http_request &request, http_response &response) override
预处理方法
duration< int64_t > seconds
秒持续时间
http_server_response http_response
HTTP响应类型别名
http_server_request http_request
HTTP请求类型别名
HTTP过滤器链实现