Fix staging ZAP baseline scan by migrating security headers#4114
Fix staging ZAP baseline scan by migrating security headers#4114xDipzz wants to merge 2 commits intoOWASP:mainfrom
Conversation
WalkthroughThis PR introduces Content Security Policy and related HTTP security headers (HSTS, X-Content-Type-Options, X-Frame-Options) across the frontend and infrastructure layers. Headers are configured at the Next.js application level and AWS ALB level, with corresponding test coverage added. Changes
Estimated code review effort🎯 2 (Simple) | ⏱️ ~12 minutes Suggested labels
Suggested reviewers
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
|
There was a problem hiding this comment.
🧹 Nitpick comments (1)
infrastructure/modules/alb/tests/alb.tftest.hcl (1)
218-248: Good test coverage for security headers.The new test blocks comprehensively verify all four security headers on the HTTPS listener. This will prevent regressions.
Minor maintenance concern: The CSP string on line 245 is duplicated from
main.tf. If the CSP policy changes, both locations need to be updated. Consider extracting the CSP to a shared variable or using a Terraform data source in tests to reference the actual value, though this may not be straightforward in test files.🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@infrastructure/modules/alb/tests/alb.tftest.hcl` around lines 218 - 248, The CSP string is duplicated in the test "test_https_listener_sets_csp_header" (aws_lb_listener.https.routing_http_response_content_security_policy_header_value) and should be referenced from a single source; update the tests to pull the expected CSP from the same variable used in main (e.g., create or reuse a shared variable like var.content_security_policy or a Terraform data source and reference it in the assert) so that changes to the CSP only need to be made in one place rather than editing the hard-coded string in the test block.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Nitpick comments:
In `@infrastructure/modules/alb/tests/alb.tftest.hcl`:
- Around line 218-248: The CSP string is duplicated in the test
"test_https_listener_sets_csp_header"
(aws_lb_listener.https.routing_http_response_content_security_policy_header_value)
and should be referenced from a single source; update the tests to pull the
expected CSP from the same variable used in main (e.g., create or reuse a shared
variable like var.content_security_policy or a Terraform data source and
reference it in the assert) so that changes to the CSP only need to be made in
one place rather than editing the hard-coded string in the test block.
ℹ️ Review info
Configuration used: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (3)
frontend/next.config.tsinfrastructure/modules/alb/main.tfinfrastructure/modules/alb/tests/alb.tftest.hcl
|
Closing in favor of #4137 |



Resolves #4090
Staging ZAP baseline scan started failing post-migration with new warnings for missing response headers:
This PR fixes the findings without adding ignores by migrating the existing header policy (from
proxy/headers.conf) into the new stack:Content-Security-Policy,Permissions-Policy,X-Content-Type-Options: nosniff,X-Frame-Options: DENYfor all routes viaheaders().'unsafe-eval'whenNEXT_PUBLIC_ENVIRONMENT=local.terraform testassertions to prevent regressions.Notes
Permissions-Policyis kept at the app layer because AWS provideraws_lb_listenerdoes not expose aPermissions-Policyresponse header attribute.Verification
Terraform (ALB module):
cd infrastructure/modules/albdocker run --rm -v "$PWD":/work -w /work hashicorp/terraform:1.14.0 init -backend=falsedocker run --rm -v "$PWD":/work -w /work hashicorp/terraform:1.14.0 validatedocker run --rm -v "$PWD":/work -w /work hashicorp/terraform:1.14.0 testHeaders (local dev):
curl -sSI http://localhost:3000/ | grep -iE '^(content-security-policy|permissions-policy|x-content-type-options|x-frame-options):'curl -sSI http://localhost:3000/chapters | grep -iE '^(content-security-policy|permissions-policy|x-content-type-options|x-frame-options):'Terraform init / validate

Terraform test (44 passed)

Response headers (curl)

Checklist
make check-testlocally: all warnings addressed, tests passed