|
| 1 | +# Security Headers Implementation |
| 2 | + |
| 3 | +This document describes the security headers implemented to protect the Layer5 website against clickjacking attacks and other security vulnerabilities. |
| 4 | + |
| 5 | +## Overview |
| 6 | + |
| 7 | +Clickjacking is an attack where an attacker tricks users into clicking on hidden or disguised elements by overlaying a malicious page on top of a legitimate one. This can lead to unintended actions or data theft. |
| 8 | + |
| 9 | +## Implemented Security Measures |
| 10 | + |
| 11 | +### 1. X-Frame-Options Header |
| 12 | + |
| 13 | +**Location**: `_headers` file |
| 14 | +**Value**: `SAMEORIGIN` |
| 15 | + |
| 16 | +This header prevents the website from being embedded in iframes on other domains, while still allowing it to be embedded on the same origin. |
| 17 | + |
| 18 | +```http |
| 19 | +X-Frame-Options: SAMEORIGIN |
| 20 | +``` |
| 21 | + |
| 22 | +### 2. Content Security Policy (CSP) |
| 23 | + |
| 24 | +**Location**: `src/html.js` and `_headers` file |
| 25 | +**Directive**: `frame-ancestors 'self'` |
| 26 | + |
| 27 | +The CSP frame-ancestors directive provides additional protection by specifying which sites can frame our content. The `'self'` value only allows the same origin to frame the content. |
| 28 | + |
| 29 | +```http |
| 30 | +Content-Security-Policy: frame-ancestors 'self' |
| 31 | +``` |
| 32 | + |
| 33 | +### 3. Comprehensive CSP Policy |
| 34 | + |
| 35 | +**Location**: `src/html.js` |
| 36 | + |
| 37 | +A more comprehensive CSP policy is implemented in the HTML template that includes: |
| 38 | + |
| 39 | +- `frame-ancestors 'self'` - Prevents framing by other sites |
| 40 | +- `default-src 'self'` - Restricts default sources to same origin |
| 41 | +- `script-src 'self' 'unsafe-inline'` - Allows inline scripts and same-origin scripts |
| 42 | +- `style-src 'self' 'unsafe-inline'` - Allows inline styles and same-origin styles |
| 43 | +- `frame-src` - Allows specific trusted domains for iframes (YouTube, Google Docs, etc.) |
| 44 | + |
| 45 | +## Configuration Files |
| 46 | + |
| 47 | +### `_headers` File |
| 48 | + |
| 49 | +```http |
| 50 | +# Security headers to prevent clickjacking |
| 51 | +/* |
| 52 | + X-Frame-Options: SAMEORIGIN |
| 53 | + Content-Security-Policy: frame-ancestors 'self' |
| 54 | +``` |
| 55 | + |
| 56 | +### `src/html.js` File |
| 57 | + |
| 58 | +```javascript |
| 59 | +<meta |
| 60 | + httpEquiv="Content-Security-Policy" |
| 61 | + content="frame-ancestors 'self'; default-src 'self'; script-src 'self' 'unsafe-inline' https://fonts.gstatic.com https://v8hx52m354g0.statuspage.io; style-src 'self' 'unsafe-inline' https://fonts.googleapis.com; font-src 'self' https://fonts.gstatic.com; img-src 'self' data: https:; connect-src 'self' https:; frame-src 'self' https://www.youtube.com https://w.soundcloud.com https://calcotestudios.com https://docs.google.com https://us15.list-manage.com https://hook.us1.make.com https://hook.us2.make.com https://calcotestudios.us15.list-manage.com;" |
| 62 | +/> |
| 63 | +``` |
| 64 | + |
| 65 | +## Testing |
| 66 | + |
| 67 | +### Manual Testing |
| 68 | + |
| 69 | +1. **Test X-Frame-Options**: |
| 70 | + ```bash |
| 71 | + curl -I https://layer5.io |
| 72 | + ``` |
| 73 | + Look for: `X-Frame-Options: SAMEORIGIN` |
| 74 | + |
| 75 | +2. **Test CSP**: |
| 76 | + ```bash |
| 77 | + curl -I https://layer5.io |
| 78 | + ``` |
| 79 | + Look for: `Content-Security-Policy` header with `frame-ancestors 'self'` |
| 80 | + |
| 81 | +### Automated Testing |
| 82 | + |
| 83 | +Run the test script to verify headers: |
| 84 | + |
| 85 | +```bash |
| 86 | +node test-security-headers.js |
| 87 | +``` |
| 88 | + |
| 89 | +## Acceptance Tests |
| 90 | + |
| 91 | +The implementation ensures that: |
| 92 | + |
| 93 | +1. ✅ **Signing into https://cloud.layer5.io is unaffected** |
| 94 | + - The CSP allows necessary domains for authentication |
| 95 | + - X-Frame-Options doesn't interfere with legitimate same-origin requests |
| 96 | + |
| 97 | +2. ✅ **Submission of forms like https://layer5.io/newcomers is unaffected** |
| 98 | + - Form submission endpoints are allowed in the CSP |
| 99 | + - No blocking of legitimate form submissions |
| 100 | + |
| 101 | +3. ✅ **Calendar links to meet with the team is unaffected** |
| 102 | + - Calendar integration domains are included in the CSP |
| 103 | + - External calendar services can still be accessed |
| 104 | + |
| 105 | +## External Services Allowed |
| 106 | + |
| 107 | +The following external services are explicitly allowed in the CSP to maintain functionality: |
| 108 | + |
| 109 | +- **YouTube**: For embedded videos |
| 110 | +- **Google Docs**: For embedded presentations |
| 111 | +- **SoundCloud**: For embedded audio |
| 112 | +- **Mailchimp**: For newsletter signups |
| 113 | +- **Make.com**: For form processing |
| 114 | +- **Statuspage**: For status monitoring |
| 115 | + |
| 116 | +## Browser Support |
| 117 | + |
| 118 | +- **X-Frame-Options**: Supported in all modern browsers |
| 119 | +- **CSP frame-ancestors**: Supported in all modern browsers (Chrome 40+, Firefox 36+, Safari 10+) |
| 120 | + |
| 121 | +## Security Benefits |
| 122 | + |
| 123 | +1. **Prevents Clickjacking**: Users cannot be tricked into clicking on hidden elements |
| 124 | +2. **Protects User Actions**: Prevents unauthorized form submissions or button clicks |
| 125 | +3. **Maintains Functionality**: All legitimate features continue to work |
| 126 | +4. **Defense in Depth**: Multiple layers of protection (X-Frame-Options + CSP) |
| 127 | + |
| 128 | +## Monitoring |
| 129 | + |
| 130 | +Regular monitoring should be performed to ensure: |
| 131 | + |
| 132 | +1. Headers are properly set on all pages |
| 133 | +2. No legitimate functionality is broken |
| 134 | +3. New external services are properly added to CSP if needed |
| 135 | + |
| 136 | +## Troubleshooting |
| 137 | + |
| 138 | +If issues arise: |
| 139 | + |
| 140 | +1. Check browser developer tools for CSP violations |
| 141 | +2. Verify headers are being set correctly |
| 142 | +3. Ensure new external domains are added to the CSP if needed |
| 143 | +4. Test functionality on affected pages |
| 144 | + |
| 145 | +## References |
| 146 | + |
| 147 | +- [OWASP Clickjacking Defense](https://owasp.org/www-community/attacks/Clickjacking) |
| 148 | +- [MDN X-Frame-Options](https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/X-Frame-Options) |
| 149 | +- [MDN Content Security Policy](https://developer.mozilla.org/en-US/docs/Web/HTTP/CSP) |
0 commit comments