This document outlines the security measures implemented to achieve Google Lighthouse security best practices.
Purpose: Protects against XSS attacks by controlling which resources can be loaded.
Configuration: app/Http/Middleware/SecurityHeaders.php
Current CSP policy:
default-src 'self'
- Only allow resources from same originscript-src 'self' 'unsafe-eval' 'unsafe-inline' https://cdn.jsdelivr.net
- Scripts from self and trusted CDNstyle-src 'self' 'unsafe-inline' https://fonts.googleapis.com
- Styles from self and Google Fontsfont-src 'self' https://fonts.gstatic.com
- Fonts from self and Google Fontsimg-src 'self' data: https:
- Images from self, data URLs, and HTTPS sourcesconnect-src 'self'
- AJAX requests only to same originframe-ancestors 'none'
- Prevents embedding in frames (clickjacking protection)base-uri 'self'
- Restricts base elementform-action 'self'
- Forms can only submit to same origin
Purpose: Forces browsers to use HTTPS connections.
Configuration: Automatically added for HTTPS requests
max-age=31536000
- 1 year cache durationincludeSubDomains
- Apply to all subdomainspreload
- Eligible for browser preload lists
Purpose: Isolates browsing context to prevent cross-origin attacks.
Configuration: same-origin
- Isolates from other origins
Purpose: Additional isolation for embedded resources.
Configuration: require-corp
- Requires explicit cross-origin permissions
Purpose: Prevents clickjacking attacks.
Configuration: DENY
- Never allow framing
X-Content-Type-Options: nosniff
- Prevents MIME type sniffingReferrer-Policy: strict-origin-when-cross-origin
- Controls referrer informationX-XSS-Protection: 1; mode=block
- Legacy XSS protection for older browsersPermissions-Policy
- Restricts browser features (geolocation, camera, etc.)
File: config/session.php
secure: true
- Only send cookies over HTTPShttp_only: true
- Prevent JavaScript access to cookiessame_site: 'strict'
- Strict same-site policy to prevent CSRF
Add to your .env
file:
SESSION_SECURE_COOKIE=true
SESSION_HTTP_ONLY=true
SESSION_SAME_SITE=strict
SESSION_PARTITIONED_COOKIE=false
The strict cookie configuration helps address third-party cookie issues:
- Cookies are restricted to same-site requests
- Secure flag ensures HTTPS-only transmission
- HttpOnly prevents JavaScript access
- Missing apple-touch-icon.png - Created placeholder icons for all required sizes
- Third-party cookies from Cloudflare CDN - Moved Font Awesome to local hosting
- Third-party cookies from Google Analytics - Implemented cookie consent banner
- Browser console errors - Fixed missing resources and updated CSP
Added comprehensive cookie consent system:
- Cookie consent banner appears for new visitors
- Google Analytics only loads after user consent
- User preferences stored in localStorage
- GDPR-compliant consent options (Accept/Decline)
- Downloaded Font Awesome 6.5.1 locally to
/public/css/fontawesome.min.css
- Eliminated third-party CDN dependency
- Improved performance and privacy
Use the custom Artisan command to check for common security issues:
php artisan security:check-browser-errors
This command checks for:
- CSP configuration
- Mixed content issues
- Deprecated API usage
- Cookie configuration problems
- ✅ CSP middleware configured
- ✅ Session cookies properly secured
⚠️ localStorage usage (for cookie consent - acceptable)⚠️ HTTP URL in development (set HTTPS for production)
Use online tools like:
- Open browser developer tools
- Navigate to Console tab
- Look for CSP violations or security warnings
- Check Network tab for mixed content issues
Temporarily add inline scripts/styles to test CSP blocking:
<!-- This should be blocked by CSP -->
<script>alert('test')</script>
<div style="color: red;">Test</div>
In browser developer tools:
- Go to Application/Storage tab
- Check Cookies section
- Verify cookies have Secure, HttpOnly, and SameSite flags
Ensure your production environment uses HTTPS:
- Configure SSL certificate
- Set
APP_URL=https://yourdomain.com
- Consider HTTP to HTTPS redirects
The current CSP allows unsafe-inline
and unsafe-eval
for compatibility.
For maximum security, consider:
- Using nonces for inline scripts
- Removing
unsafe-eval
if not needed - Adding specific domains instead of wildcards
After testing HSTS for a while, consider submitting your domain to the HSTS preload list:
- Visit hstspreload.org
- Ensure compliance with requirements
- Submit your domain
- Run
php artisan security:check-browser-errors
regularly - Use Google Lighthouse security audits
- Monitor for new security headers and best practices
If resources are blocked by CSP:
- Check browser console for violation reports
- Add legitimate sources to appropriate CSP directives
- Test changes thoroughly
If you see mixed content warnings:
- Ensure all asset URLs use HTTPS
- Check third-party resources
- Update any hardcoded HTTP URLs
If cookies aren't working properly:
- Verify HTTPS setup in production
- Check domain configuration
- Ensure SameSite compatibility with your use case
Set up monitoring for:
- CSP violation reports (consider CSP reporting endpoints)
- Security header presence
- SSL certificate expiration
- Security audit scores
Regular monitoring helps maintain security posture and catch issues early.