Skip to content

Commit 2851b76

Browse files
committed
eli-389 added mild documentation of the middleware implementation
1 parent f0e6b6a commit 2851b76

File tree

1 file changed

+46
-0
lines changed

1 file changed

+46
-0
lines changed

docs/security-headers.md

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
# Security Headers Implementation
2+
3+
This document describes the implementation of security headers for the Eligibility Signposting API.
4+
5+
## Overview
6+
7+
Security headers have been implemented using a two-layer approach:
8+
9+
1. **API Gateway Responses** (Terraform) - For error responses (4xx, 5xx) generated by API Gateway
10+
2. **Flask Middleware** (Python) - For all successful responses (200, 201, etc.) from the Lambda function
11+
12+
This ensures security headers are present on **all** responses, regardless of where they originate.
13+
14+
## Security Headers
15+
16+
The following security headers are applied to all responses:
17+
18+
| Header | Value | Purpose |
19+
|--------|-------|---------|
20+
| `Cache-Control` | `no-store, private` | Prevents caching of sensitive data |
21+
| `Strict-Transport-Security` | `max-age=31536000; includeSubDomains` | Enforces HTTPS for 1 year on all subdomains |
22+
| `X-Content-Type-Options` | `nosniff` | Prevents MIME type sniffing |
23+
24+
## Implementation Details
25+
26+
### 1. API Gateway Responses (Terraform)
27+
28+
File: `infrastructure/stacks/api-layer/gateway_responses.tf`
29+
30+
Gateway responses handle error responses generated by API Gateway itself (e.g., validation failures, authorization errors, throttling).
31+
32+
The following response types have been configured:
33+
- `DEFAULT_4XX` - All 4xx errors
34+
- `DEFAULT_5XX` - All 5xx errors
35+
- `UNAUTHORIZED` (401)
36+
- `ACCESS_DENIED` (403)
37+
- `THROTTLED` (429)
38+
39+
### 2. Flask Middleware
40+
41+
Files:
42+
- `src/eligibility_signposting_api/middleware/security_headers.py` - Middleware implementation
43+
- `src/eligibility_signposting_api/middleware/__init__.py` - Package exports
44+
- `src/eligibility_signposting_api/app.py` - Middleware registration
45+
46+
The middleware uses Flask's `after_request` hook to add security headers to all responses from the Lambda function. It's non-overriding: Allows specific endpoints to override headers if needed

0 commit comments

Comments
 (0)