For AI agents: A markdown version of this page is available at https://docs.datadoghq.com/security/code_security/static_analysis/static_analysis_rules/rust-security/permissive-cors.md. A documentation index is available at /llms.txt.

Permissive CORS configuration allows any origin

This product is not supported for your selected Datadog site. ().

Metadata

ID: rust-security/permissive-cors

Language: Rust

Severity: Warning

Category: Security

CWE: 346

Related CWEs:

Description

Permissive CORS configurations allow any origin to read responses from the server, exposing authenticated endpoints to cross-origin attacks such as data theft and CSRF amplification. In Rust this most often appears as tower_http::cors::CorsLayer::permissive(), CorsLayer::very_permissive(), .allow_origin(Any), or actix-cors’s Cors::permissive() / .allow_any_origin(). Replace with an explicit allow-list of origins, or gate permissive setups behind cfg(debug_assertions) for local development only.

Learn More

Non-Compliant Code Examples

use tower_http::cors::{CorsLayer, Any};
use actix_cors::Cors;

fn tower_permissive() {
    let _ = CorsLayer::permissive();
}

fn tower_very_permissive() {
    let _ = CorsLayer::very_permissive();
}

fn tower_qualified() {
    let _ = tower_http::cors::CorsLayer::permissive();
}

fn tower_allow_any() {
    let _ = CorsLayer::new().allow_origin(Any);
}

fn tower_allow_any_qualified() {
    let _ = CorsLayer::new().allow_origin(tower_http::cors::Any);
}

fn actix_permissive() {
    let _ = Cors::permissive();
}

fn actix_allow_any_origin() {
    let _ = Cors::default().allow_any_origin();
}

Compliant Code Examples

use tower_http::cors::{CorsLayer, Any};
use http::HeaderValue;

fn ok() {
    // Explicit allow-list
    let origin: HeaderValue = "https://example.com".parse().unwrap();
    let _ = CorsLayer::new().allow_origin(origin);

    // Default restrictive layer
    let _ = CorsLayer::new();

    // Allowing all methods or headers is not flagged — only origin is the security boundary
    let _ = CorsLayer::new().allow_methods(Any).allow_headers(Any);
}
https://static.datadoghq.com/static/images/logos/github_avatar.svg https://static.datadoghq.com/static/images/logos/vscode_avatar.svg jetbrains

Seamless integrations. Try Datadog Code Security