Environment Variables
Authentication & Authorization
NETBIRD_ALLOWED_DOMAIN
Purpose: Restrict access to users from a specific email domain- Enforced during OAuth callback after successful Google authentication
- Case-insensitive domain matching
- Users with non-matching domains are rejected with a clear error message
- Existing users with non-matching domains can still access if already registered
Implementation details
Implementation details
NETBIRD_ADMIN_EMAIL
Purpose: Define the administrator email address- Approve or deny resource requests
- Create resources without approval
- Edit and delete any resource
- View activity logs
- Manage all pending requests
Only one admin email is supported. For multiple admins, consider implementing role-based access control or granting elevated NetBird API permissions to multiple users.
API Security
NETBIRD_API_TOKEN
Purpose: Authenticate with the NetBird APINETBIRD_API_URL
Purpose: NetBird API endpoint URL- Use official NetBird API URL or your self-hosted instance
- Must use HTTPS in production
- Default:
https://api.netbird.io
Session Configuration
SESSION_DRIVER
Purpose: Session storage backenddatabase (default)
Options:
database- Best for production (scalable, persistent)redis- High-performance option for large deploymentsfile- Development only (not scalable)cookie- Not recommended (security implications)
SESSION_LIFETIME
Purpose: Session idle timeout in minutes- Shorter lifetime = better security, more frequent re-authentication
- Longer lifetime = better UX, higher session hijacking risk
- Recommended range: 60-240 minutes
Balance security with user experience. For high-security environments, consider 60 minutes. For general use, 120 minutes is appropriate.
SESSION_SECURE_COOKIE
Purpose: Require HTTPS for session cookiesSESSION_HTTP_ONLY
Purpose: Prevent JavaScript access to session cookiestrue
Leave enabled - This is critical XSS protection. There is no legitimate reason to disable this.
SESSION_SAME_SITE
Purpose: CSRF protection via SameSite cookie attributelax
Options:
lax(recommended) - Balances security and compatibilitystrict- Maximum security, may break OAuth flowsnone- Not recommended (requiressecure=true)
SESSION_ENCRYPT
Purpose: Encrypt session datafalse
Encryption adds overhead but provides defense-in-depth. Enable if storing sensitive data in sessions or if compliance requires it.
OAuth Configuration
Google OAuth (Example)
- Must exactly match the URI registered in Google Cloud Console
- Must use HTTPS in production
- Cannot use wildcards
- Each environment needs its own redirect URI
Application Security
APP_ENV
Purpose: Application environmentAPP_DEBUG
Purpose: Enable/disable debug modeAPP_KEY
Purpose: Application encryption keyphp artisan key:generate
APP_URL
Purpose: Application base URL- Must use HTTPS (not HTTP)
- Should match your actual domain
- Used for generating OAuth callback URLs and email links
- Include port if non-standard (e.g.,
https://example.com:8443)
Production Security Configuration
Minimal Secure Configuration
Configuration Checklist
Before going live:Security checklist (click to expand)
Security checklist (click to expand)
-
APP_ENV=production -
APP_DEBUG=false -
APP_KEYgenerated and unique -
APP_URLuses HTTPS -
NETBIRD_ALLOWED_DOMAINconfigured -
NETBIRD_ADMIN_EMAILset to trusted user -
NETBIRD_API_TOKENis production token -
SESSION_SECURE_COOKIE=true -
SESSION_HTTP_ONLY=true - Strong database password
- OAuth production credentials
- OAuth redirect URI uses HTTPS
-
.envfile has proper permissions (600) -
.envexcluded from version control - Web server configured for HTTPS
- Firewall rules configured
- Database backups enabled
- Log monitoring configured
Testing Security Configuration
Verify HTTPS Enforcement
Verify Domain Restriction
- Attempt login with non-allowed domain email
- Should be rejected with error message
- Check error appears at post-OAuth step
Verify Session Security
Inspect session cookie in browser dev tools:Secureflag should betrueHttpOnlyflag should betrueSameSiteshould beLax
Verify Admin Access
- Login as admin user (matching
NETBIRD_ADMIN_EMAIL) - Verify “Pending Approvals” section appears
- Verify ability to approve/deny requests
- Logout and login as non-admin
- Verify approval section is hidden
Troubleshooting
”CSRF token mismatch” errors
Cause: Session configuration issues Solutions:- Verify
SESSION_DOMAINmatches your actual domain - Check
SESSION_SECURE_COOKIEis correct for your protocol - Clear browser cookies and retry
- Run
php artisan config:clear
OAuth redirect errors
Cause: Mismatch between configured and registered URIs Solutions:- Verify
GOOGLE_REDIRECT_URIexactly matches Google Console - Ensure using HTTPS in production
- Check for trailing slashes (must match exactly)
- Verify OAuth app is not in testing mode with limited users
Users bypassing domain restriction
Cause: Users registered before restriction was configured Solution:Next Steps
Overview
Return to security overview
Best Practices
Learn security best practices