infrastructure tier

infrastructure-hardening

Response-side HTTP hardening: security headers + safe-by-default CORS (fail-closed)

Response-side HTTP hardening: security headers + safe-by-default CORS (fail-closed)

Tierinfrastructure
Roleunclassified (baselined)
Pathcrates/infrastructure/hardening
Edition2021
Targetsinfrastructure_hardening
Public items4 across 1 module
Tests9

What it is for

Response-side HTTP hardening for axum/tower services.

Companion to infrastructure-waf (request-side: signatures, rate-limit, honeypots). This crate owns the response posture — security headers and safe-by-default CORS — with a fail-closed config: a missing or partial config deserializes to a fully hardened posture.

# Ordering (important)

The header layer must be the outermost layer so its headers apply to every response, including short-circuit responses from inner layers such as a WAF 403. With tower::ServiceBuilder the FIRST .layer() is outermost:

use tower::ServiceBuilder;
let svc = ServiceBuilder::new()
.layer(infrastructure_hardening::recommended()) // outermost: headers on ALL responses
// .layer(cors).layer(ceilings).layer(waf)  // inner
.service(router);

Note: chained axum::Router::layer() orders in REVERSE of ServiceBuilder (last-added is outermost), so prefer an explicit ServiceBuilder for the security stack to avoid getting the order backwards.

Capabilities

crate root

Response-side HTTP hardening for axum/tower services.

Item
fn recommended() -> SecurityHeadersLayer

cors (other)

Safe-by-default CORS builders.

Item
fn allowlist(origins : Vec <HeaderValue>) -> CorsLayer
fn allowlist_with_credentials(origins : Vec <HeaderValue>) -> CorsLayer
fn dangerously_reflect_any_origin() -> CorsLayer

How to use it

No examples/ target and no doctest in this crate's rustdoc. The tests listed under Verification are the closest executable usage.

Module structure

infrastructure_hardening

Public surface

`crate root`

ItemWhat it is
fn recommended() -> SecurityHeadersLayerSecure-default response-header layer: HSTS, nosniff, X-Frame-Options, Referrer-Policy, and Permissions-Policy

`cors`

ItemWhat it is
fn allowlist(origins : Vec <HeaderValue>) -> CorsLayerCORS restricted to an explicit origin allowlist
fn allowlist_with_credentials(origins : Vec <HeaderValue>) -> CorsLayerCORS restricted to an explicit origin allowlist, with credentials
fn dangerously_reflect_any_origin() -> CorsLayerDANGEROUS: reflects any request Origin

Re-exports. Exported here, defined elsewhere.

ExportDefined in
{FrameOptions,HardeningConfig}config::{FrameOptions,HardeningConfig}
{SecurityHeadersLayer,SecurityHeadersService}headers::{SecurityHeadersLayer,SecurityHeadersService}

Boundary

Depends on no other workspace tier.

Shares tier infrastructure with 82 other crates: infrastructure-acquire, infrastructure-adapters-google-calendar, infrastructure-adapters-google-gmail, infrastructure-adapters-google-places, infrastructure-adapters-google-trends, infrastructure-adapters-shodan, infrastructure-adapters-yelp, infrastructure-agent, … (82 total).

_What this crate deliberately does NOT own is a judgment. No committed registry records one for it, so none is stated here._

Where it sits

Tier (ontology)infrastructure
Architectural role (taxonomy)unclassified (baselined)
Locationcrates/infrastructure/hardening
Vocabulary in force (lexicon)current

Dependencies

Runtime, from outside the workspace.

CrateRequirementFeaturesOptionalOnly on
http^1.1noalways
serde^1derivenoalways
tower^0.5utilnoalways
tower-http^0.6fs, trace, cors, request-id, corsnoalways

Development, from outside the workspace.

CrateRequirementFeaturesOptionalOnly on
axum^0.7multipartnoalways
serde_json^1noalways
tokio^1fullnoalways

Build. None.

Depended on by. 2 workspace crates.

Signal flow — what reaches this crate, and what it reaches.

flowchart LR
  n_application_security["application-security"] -->|uses| SELF
  n_infrastructure_security_scan["infrastructure-security-scan"] -->|uses| SELF
  SELF["infrastructure-hardening"]
  classDef self fill:#1f883d,stroke:#1f883d,color:#fff;
  class SELF self;

Feature flags

No Cargo features are defined: every capability is unconditional, so no consumer can receive a half-wired crate.

Targets

KindNameSource
libinfrastructure_hardening`src/lib.rs`

Error model

No public error type was detected: no public item declares a type named *Error, and no public signature returns one.

Operational characteristics

PropertyEvidence
async public surfacenone detected
async runtimenone detected
database accessnone detected
network I/Oyes
unsafe codenone detected
environment variablesnone detected

No unsafe block, unsafe fn, unsafe impl or unsafe trait was found by the parser anywhere in this crate's source.

Configuration

No environment variable is read with a literal name anywhere in this crate. A variable whose key is computed at run time cannot be listed here, and is not claimed to be absent.

2 workspace crates depend on this one: application-security, infrastructure-security-scan.

Verification

KindCount
Unit tests9
Integration tests0
Examples0
Doctests0

Evidence by module. How often each public module is named by something executable.

ModuleTestsExamplesConsumers
crate root101
cors302

What the tests establish, by name:

Documentation coverage

MeasureDocumentedTotal
Public items with rustdoc44
Public modules with a //! block11
pie showData
    title Public items with rustdoc
    "Documented" : 4
    "No rustdoc detected" : 0

Metrics

MetricValue
Rust source files4
Source lines458
Code lines331
Public API items4
Public modules1
Tests9
Examples0
Cargo features0
Direct runtime dependencies4
Workspace reverse dependencies2
pie showData
    title Public API by kind
    "function" : 4
pie showData
    title Rust source composition
    "Code" : 331
    "Blank or comment" : 127

Generation

Rendered by tools-corpus corpus readme from repository evidence alone, renderer schema 2, lexicon current. No model, network service or database was consulted. Regenerate with tools-corpus corpus readme --write; verify with --check.

All infrastructure · Manual