Issue: CSRF cookie (XSRF-TOKEN) is created correctly when accessing via localhost but NOT created when accessing via remote IP address (e.g., http://192.168.1.100:8080).
Root Cause: The WTF_CSRF_SSL_STRICT=true (default) setting blocks cookie creation for HTTP connections to non-localhost addresses as a security measure.
We've provided an automated script that configures the application correctly for IP address access:
Linux/Mac:
bash scripts/fix_csrf_ip_access.shWindows:
scripts\fix_csrf_ip_access.batThe script sets:
WTF_CSRF_SSL_STRICT=false— Allows CSRF tokens over HTTPSESSION_COOKIE_SECURE=false— Allows session cookies over HTTPCSRF_COOKIE_SECURE=false— Allows CSRF cookies over HTTP
- Added
WTF_CSRF_SSL_STRICT=falsesetting with documentation - Added detailed comments about CSRF cookie settings
- Added specific guidance for IP address access
- Updated troubleshooting tips
- Added
WTF_CSRF_SSL_STRICTenvironment variable with defaultfalse - Added
SESSION_COOKIE_SECUREenvironment variable with defaultfalse - Enhanced documentation about CSRF configuration
- Added reference to new troubleshooting guides
Comprehensive guide covering:
- Problem description and root cause
- Quick fix instructions
- Detailed explanation of each setting
- Testing procedures
- Security considerations
- Alternative solutions (domain names, HTTPS)
- Troubleshooting steps
- Configuration examples for different environments
Quick reference guide with:
- Problem summary
- One-command fixes
- Verification steps
- Security notes
- Alternative solutions
- Troubleshooting checklist
Implementation summary documenting all changes
- Added new section #8: "Accessing via IP Address (Not Localhost)"
- Updated related documentation links
- Added reference to the new IP access guide
- Added link to
CSRF_IP_ACCESS_FIX.mdin troubleshooting section - Highlighted with 🔥 emoji for visibility
Bash script for Linux/Mac that:
- Checks for
.envfile, creates if missing - Shows current CSRF configuration
- Updates
.envwith correct settings - Restarts the Docker container
- Provides verification steps
Windows batch script that:
- Uses PowerShell for
.envfile manipulation - Same functionality as bash version
- Windows-friendly output and instructions
WTF_CSRF_SSL_STRICT=false
SESSION_COOKIE_SECURE=false
CSRF_COOKIE_SECURE=false
SESSION_COOKIE_SAMESITE=Lax
CSRF_COOKIE_SAMESITE=LaxWTF_CSRF_SSL_STRICT=true
SESSION_COOKIE_SECURE=true
CSRF_COOKIE_SECURE=true
SESSION_COOKIE_SAMESITE=Strict
CSRF_COOKIE_SAMESITE=Strict- User accesses
http://192.168.1.100:8080 - Flask-WTF checks
WTF_CSRF_SSL_STRICTsetting (default:true) - Since request is HTTP to non-localhost, Flask-WTF blocks cookie creation
- CSRF cookie is NOT set in browser
- Form submissions fail with "CSRF token missing or invalid"
- User accesses
http://192.168.1.100:8080 - Flask-WTF checks
WTF_CSRF_SSL_STRICTsetting (now:false) - Flask-WTF allows cookie creation over HTTP
- CSRF cookie (
XSRF-TOKEN) is set in browser - Form submissions work correctly ✅
- ✅ Development environments
- ✅ Testing on local networks
- ✅ Private/trusted networks (VPN, home network)
- ✅ Isolated lab environments
- ❌ Public internet without HTTPS
- ❌ Production with sensitive data over HTTP
- ❌ Untrusted networks
- ❌ Public-facing applications
- Development: Use the provided settings (
WTF_CSRF_SSL_STRICT=false) - Production: Always use HTTPS with strict settings (
WTF_CSRF_SSL_STRICT=true) - Network Security: If using HTTP, ensure network is trusted
- Migration: When moving to production, update all security settings
bash scripts/fix_csrf_ip_access.sh # or .bat on Windowsdocker-compose exec app env | grep -E "WTF_CSRF|SESSION_COOKIE|CSRF_COOKIE"- Open DevTools (F12)
- Navigate to
http://YOUR_IP:8080 - Go to Application → Cookies
- Verify
sessionandXSRF-TOKENcookies exist
curl -v http://YOUR_IP:8080/auth/csrf-tokenLook for Set-Cookie headers in response.
- Try logging in via IP address
- Submit any form (create project, log time, etc.)
- Should work without CSRF errors ✅
# Add to hosts file
192.168.1.100 timetracker.local
# Access via domain
http://timetracker.local:8080
# Generate certificate
openssl req -x509 -newkey rsa:4096 -nodes \
-keyout key.pem -out cert.pem -days 365 \
-subj "/CN=192.168.1.100"
# Configure nginx/docker for HTTPS
# Set all security flags to trueWTF_CSRF_ENABLED=false # ⚠️ ONLY for isolated development!If you need to revert to strict security settings:
- Edit
.env:
WTF_CSRF_SSL_STRICT=true
SESSION_COOKIE_SECURE=true
CSRF_COOKIE_SECURE=true- Restart:
docker-compose restart appNote: This will prevent IP access over HTTP again.
- ❌ Users accessing via IP see CSRF errors on all forms
- ❌ Login fails with "CSRF token missing or invalid"
- ❌ No clear error message about IP/localhost difference
- ❌ Users confused why localhost works but IP doesn't
- ✅ Automated script makes fix one-click easy
- ✅ Clear documentation explains the issue
- ✅ Multiple solutions provided (scripts, manual, alternatives)
- ✅ Users understand security implications
- ✅ Separate configs for dev/prod clearly documented
This fix integrates with:
CSRF_TROUBLESHOOTING.md— Main troubleshooting guidedocs/CSRF_CONFIGURATION.md— Detailed CSRF configurationdocs/DOCKER_PUBLIC_SETUP.md— Docker setup guideenv.example— Configuration template
Potential enhancements:
- Auto-detection of access method (localhost vs IP)
- Configuration wizard for first-time setup
- Web UI warning when accessing via IP with strict settings
- Automated HTTPS setup script with Let's Encrypt
- Environment-specific docker-compose files (dev/prod)
This fix provides:
- ✅ Immediate solution via automated scripts
- ✅ Clear documentation explaining the problem and fix
- ✅ Security guidance for different environments
- ✅ Multiple approaches (automated, manual, alternatives)
- ✅ Comprehensive testing procedures
- ✅ User-friendly implementation
Result: Users can now access the application via IP address without CSRF cookie issues, while understanding the security implications and having clear paths for both development and production configurations.
docs/CSRF_IP_ACCESS_GUIDE.md— Comprehensive guideCSRF_IP_ACCESS_FIX.md— Quick referencescripts/fix_csrf_ip_access.sh— Linux/Mac automationscripts/fix_csrf_ip_access.bat— Windows automationCSRF_IP_FIX_SUMMARY.md— This summary
env.example— Added CSRF IP settingsdocker-compose.yml— Added environment variablesCSRF_TROUBLESHOOTING.md— Added IP access sectionREADME.md— Added link to fix guide
- 11 files changed/created
- 5 documentation files
- 2 automation scripts
- 4 configuration files
Implementation Date: October 2024
Tested On: TimeTracker v1.0+
Issue: CSRF cookies not created when accessing via IP address
Status: ✅ Resolved