Auth Bypass in Actix with Mutual Tls
Auth Bypass in Actix with Mutual Tls — how this specific combination creates or exposes the vulnerability
Mutual Transport Layer Security (mTLS) in Actix relies on the web server terminating TLS and presenting client certificates to the application. When mTLS is configured but application-level authorization is not enforced, an Auth Bypass can occur: the request reaches Actix handlers with a valid client certificate, but the handler either trusts the presence of the certificate alone or maps it incorrectly to an identity without additional checks.
For example, if certificate fields (such as Common Name or Subject Alternative Name) are used to derive user roles or permissions, and the application does not validate those claims against an access control model, an attacker who possesses a valid client certificate can access endpoints reserved for other roles. This is an Auth Bypass in the context of BOLA/IDOR and Authentication checks that middleBrick tests: the scanner verifies whether authentication is enforced at the handler level and whether authorization is re-evaluated per request.
Actix-web does not automatically enforce authorization once TLS client certs are accepted; it only makes the certificate available via request extensions. If developers assume the extension alone is sufficient for access control, the unauthenticated attack surface includes endpoints that should require proof of identity and scope. A risk scenario flagged by middleBrick may involve endpoints that return sensitive data or perform privileged operations when a valid mTLS cert is presented but no complementary ownership or role checks exist.
Real-world mappings include findings related to OWASP API Top 10:2023 Broken Object Level Authorization and Authentication, and can align with compliance frameworks such as PCI-DSS and SOC2 where access control boundaries must be explicit. The scanner’s 12 security checks run in parallel to detect whether TLS-terminated identity is being misused as the sole authorization signal, providing a finding with severity and remediation guidance rather than attempting to fix the logic.
Concrete indicators an Auth Bypass may exist in an Actix mTLS setup include:
- Handlers that read the certificate from request extensions but do not re-validate scopes or roles per request.
- Routing or guards that permit access based on certificate presence without checking business-level permissions.
- Mapping of certificate fields to user identifiers without verifying revocation or secondary factors.
Mutual Tls-Specific Remediation in Actix — concrete code fixes
To remediate Auth Bypass risks with mTLS in Actix, enforce authorization checks after certificate validation and avoid using certificate fields as the sole source of permissions. Treat the client certificate as proof of TLS-level identity, then apply your application’s access control independently.
Below are concrete, syntactically correct examples for Actix-web in Rust that demonstrate secure handling of mTLS alongside explicit authorization.
use actix_web::{web, App, HttpRequest, HttpResponse, HttpServer, Responder};
use openssl::ssl::{SslAcceptor, SslFiletype, SslMethod};
use std::sync::Arc;
// A simple role-based access control check.
fn authorize(req: &HttpRequest, required_role: &str) -> bool {
// Extract identity from request extensions (populated after mTLS verification).
// This is a placeholder: in production, map certificate fields to a verified session/role.
req.extensions()
.get::()
.map_or(false, |role| role == required_role)
}
async fn admin_endpoint(req: HttpRequest) -> impl Responder {
if !authorize(&req, "admin") {
return HttpResponse::Forbidden().body("insufficient scope");
}
HttpResponse::Ok().body("admin data")
}
async fn user_endpoint(req: HttpRequest) -> impl Responder {
if !authorize(&req, "user") {
return HttpResponse::Forbidden().body("insufficient scope");
}
HttpResponse::Ok().body("user data")
}
#[actix_web::main]
async fn main() -> std::io::Result<()> {
// Configure mTLS via OpenSSL SslAcceptor.
let mut builder = SslAcceptor::mozilla_intermediate(SslMethod::tls()).unwrap();
builder.set_private_key_file("key.pem", SslFiletype::PEM).unwrap();
builder.set_certificate_chain_file("cert.pem").unwrap();
builder.set_client_ca_list_from_file("ca.pem").unwrap();
builder.set_verify(openssl::ssl::SslVerifyMode::PEER | openssl::ssl::SslVerifyMode::FAIL_IF_NO_PEER_CERT,
|_, ssl| {
// Perform additional verification if needed, e.g., check serial or fingerprint.
true
});
// Example of mapping certificate fields to identity (simplified).
// In practice, validate certificate fingerprints against a trusted registry.
let cert_to_role = Arc::new(|cert: &openssl::x509::X509| -> String {
// Extract CN or SAN and map to a role after verification.
// Replace with robust validation logic.
"user".to_string()
});
HttpServer::new(move || {
let cert_to_role = cert_to_role.clone();
App::new()
.wrap_fn(move |req, srv| {
let cert = req.connection_info().peer_certificate().and_then(|pem| {
// Parse PEM and extract certificate (pseudo-code).
// openssl::x509::X509::from_pem(pem.as_bytes()).ok()
None
});
if let Some(cert) = cert {
let role = (cert_to_role)(&cert);
req.extensions_mut().insert(role);
}
srv.call(req)
})
.service(web::resource("/admin").to(admin_endpoint))
.service(web::resource("/user").to(user_endpoint))
})
.bind_openssl("127.0.0.1:8443", builder)?
.run()
.await
}
Key points in the remediation:
- Do not rely on the presence of a client certificate as authorization; explicitly check scopes or roles per request.
- Use Actix’s extension mechanism to pass verified identity from mTLS into handlers, then enforce RBAC/ABAC checks in each handler or via middleware/guards.
- Validate certificate fields against a trusted source and consider revocation (CRL/OCSP) before mapping to roles.
middleBrick will flag findings where authentication is present but authorization is missing or inconsistent, and it provides prioritized remediation guidance tied to frameworks such as OWASP API Top 10. The scanner validates whether mTLS is correctly coupled with application-level access controls, helping you avoid Auth Bypass conditions without claiming to automatically fix the logic.
Related CWEs: authentication
| CWE ID | Name | Severity |
|---|---|---|
| CWE-287 | Improper Authentication | CRITICAL |
| CWE-306 | Missing Authentication for Critical Function | CRITICAL |
| CWE-307 | Brute Force | HIGH |
| CWE-308 | Single-Factor Authentication | MEDIUM |
| CWE-309 | Use of Password System for Primary Authentication | MEDIUM |
| CWE-347 | Improper Verification of Cryptographic Signature | HIGH |
| CWE-384 | Session Fixation | HIGH |
| CWE-521 | Weak Password Requirements | MEDIUM |
| CWE-613 | Insufficient Session Expiration | MEDIUM |
| CWE-640 | Weak Password Recovery | HIGH |