- Implement session management with device tracking - Implement audit logging system - Implement account lockout for brute-force protection - Add security headers middleware - Add rate limiting middleware (stub) - Integrate security services into main application Build Status: Compiles successfully Phase: 2.6 of 8 (75% complete)
39 lines
963 B
Rust
39 lines
963 B
Rust
use axum::{
|
|
extract::Request,
|
|
http::HeaderValue,
|
|
middleware::Next,
|
|
response::Response,
|
|
};
|
|
|
|
pub async fn security_headers_middleware(
|
|
req: Request,
|
|
next: Next,
|
|
) -> Response {
|
|
let mut response = next.run(req).await;
|
|
|
|
let headers = response.headers_mut();
|
|
|
|
// Security headers
|
|
headers.insert(
|
|
"X-Content-Type-Options",
|
|
HeaderValue::from_static("nosniff"),
|
|
);
|
|
headers.insert(
|
|
"X-Frame-Options",
|
|
HeaderValue::from_static("DENY"),
|
|
);
|
|
headers.insert(
|
|
"X-XSS-Protection",
|
|
HeaderValue::from_static("1; mode=block"),
|
|
);
|
|
headers.insert(
|
|
"Strict-Transport-Security",
|
|
HeaderValue::from_static("max-age=31536000; includeSubDomains"),
|
|
);
|
|
headers.insert(
|
|
"Content-Security-Policy",
|
|
HeaderValue::from_static("default-src 'self'; script-src 'self' 'unsafe-inline'; style-src 'self' 'unsafe-inline'"),
|
|
);
|
|
|
|
response
|
|
}
|