Implement global security headers and CSP - Fix of #93PR #97
Conversation
Update application.rb with couple of Content-security headers so that the rail server executes and shows the localhost:3000/api/docs page
Update application.rb with couple of Content-security headers
|
Tested the fix locally by checking out PR #97 and running: curl -I http://localhost:3000/api/units/1/all_resources Confirmed that the required security headers (X-Frame-Options, X-Content-Type-Options, Referrer-Policy, Permissions-Policy, and Content-Security-Policy) are now present in the API response. The fix is working as expected.
|
|
Reviewed and Tested – Working as Expected Confirmed all five security headers are present in the response: X-Frame-Options: DENY Code Review: Headers are applied globally via config/application.rb using Rails' default headers configuration — clean approach that avoids duplicating logic across individual controllers
|



Description-
This fix addresses missing HTTP security headers in Doubtfire API responses. Previously, API responses did not consistently include important browser-side protections such as Content-Security-Policy, X-Frame-Options, X-Content-Type-Options, Referrer-Policy, and Permissions-Policy. The absence of these headers increased exposure to risks such as clickjacking, MIME sniffing, cross-site scripting (XSS), and unnecessary browser feature access.
Changes made
doubtfire-api/config/application.rb
Added global security headers using Rails default headers configuration so all API responses automatically include them:
This approach ensures headers are applied consistently across all controllers and API endpoints without modifying individual routes.
Fixes: Missing Security Headers issue
How Has This Been Tested?
The fix was verified locally using curl and Burp Suite against the Rails API running on localhost:3000.
Test 1 — curl header validation
Sent request to:
GET /api/units/1/all_resources
Confirmed response now includes:
Command used:
curl -I http://localhost:3000/api/units/1/all_resources
Test 2 — Burp Suite validation
Captured API response using Burp Suite Proxy.
Confirmed:
Security headers are present in all responses
Headers match expected secure configuration
No missing header issues observed
Impact
This fix strengthens the application’s security posture by enforcing standard HTTP security headers aligned with OWASP best practices, reducing exposure to common web-based attacks.
Checklist: