Skip to content

Commit f0e6b6a

Browse files
committed
eli-389 adding security headers to default API Gateway responses
1 parent 600e109 commit f0e6b6a

File tree

1 file changed

+61
-0
lines changed

1 file changed

+61
-0
lines changed
Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
# Gateway Responses with Security Headers
2+
# These responses are used when API Gateway itself returns an error (e.g., validation failures, auth errors)
3+
# They ensure security headers are present even on API Gateway-generated error responses
4+
5+
resource "aws_api_gateway_gateway_response" "response_4xx" {
6+
rest_api_id = module.eligibility_signposting_api_gateway.rest_api_id
7+
response_type = "DEFAULT_4XX"
8+
9+
response_parameters = {
10+
"gatewayresponse.header.Cache-Control" = "'no-store, private'"
11+
"gatewayresponse.header.Strict-Transport-Security" = "'max-age=31536000; includeSubDomains'"
12+
"gatewayresponse.header.X-Content-Type-Options" = "'nosniff'"
13+
}
14+
}
15+
16+
resource "aws_api_gateway_gateway_response" "response_5xx" {
17+
rest_api_id = module.eligibility_signposting_api_gateway.rest_api_id
18+
response_type = "DEFAULT_5XX"
19+
20+
response_parameters = {
21+
"gatewayresponse.header.Cache-Control" = "'no-store, private'"
22+
"gatewayresponse.header.Strict-Transport-Security" = "'max-age=31536000; includeSubDomains'"
23+
"gatewayresponse.header.X-Content-Type-Options" = "'nosniff'"
24+
}
25+
}
26+
27+
resource "aws_api_gateway_gateway_response" "unauthorized" {
28+
rest_api_id = module.eligibility_signposting_api_gateway.rest_api_id
29+
response_type = "UNAUTHORIZED"
30+
status_code = "401"
31+
32+
response_parameters = {
33+
"gatewayresponse.header.Cache-Control" = "'no-store, private'"
34+
"gatewayresponse.header.Strict-Transport-Security" = "'max-age=31536000; includeSubDomains'"
35+
"gatewayresponse.header.X-Content-Type-Options" = "'nosniff'"
36+
}
37+
}
38+
39+
resource "aws_api_gateway_gateway_response" "access_denied" {
40+
rest_api_id = module.eligibility_signposting_api_gateway.rest_api_id
41+
response_type = "ACCESS_DENIED"
42+
status_code = "403"
43+
44+
response_parameters = {
45+
"gatewayresponse.header.Cache-Control" = "'no-store, private'"
46+
"gatewayresponse.header.Strict-Transport-Security" = "'max-age=31536000; includeSubDomains'"
47+
"gatewayresponse.header.X-Content-Type-Options" = "'nosniff'"
48+
}
49+
}
50+
51+
resource "aws_api_gateway_gateway_response" "throttled" {
52+
rest_api_id = module.eligibility_signposting_api_gateway.rest_api_id
53+
response_type = "THROTTLED"
54+
status_code = "429"
55+
56+
response_parameters = {
57+
"gatewayresponse.header.Cache-Control" = "'no-store, private'"
58+
"gatewayresponse.header.Strict-Transport-Security" = "'max-age=31536000; includeSubDomains'"
59+
"gatewayresponse.header.X-Content-Type-Options" = "'nosniff'"
60+
}
61+
}

0 commit comments

Comments
 (0)