In today's digital landscape, website security and performance are more critical than ever. Cyber attacks, DDoS attempts, and malicious bots can severely impact your business operations and customer trust. That's why we're excited to share this comprehensive guide on setting up Cloudflare protection for your website.
Cloudflare offers enterprise-grade security features including Web Application Firewall (WAF), DDoS protection, and advanced bot management. In this guide, we'll walk you through the entire process of setting up Cloudflare protection, with a special focus on implementing targeted security rules for sensitive pages like login and registration forms.
What You'll Learn
- How to add and verify your domain in Cloudflare
- Setting up DNS configuration
- Enabling Web Application Firewall (WAF) rules
- Creating custom security rules for specific URIs
- Best practices for ongoing security management
Step 1: Creating Your Cloudflare Account and Adding Your Domain
1.1 Sign Up for Cloudflare
- Visit cloudflare.com and click "Sign Up"
- Enter your email address and create a strong password
- Verify your email address through the confirmation link
1.2 Add Your Website
- Once logged in, click "Add Site" from the dashboard
- Enter your domain name (e.g.,
yourwebsite.com
)
- Click "Add Site" to continue
- Cloudflare will scan your existing DNS records (this may take a few moments)
1.3 Choose Your Plan
Select the plan that best fits your needs:
- Free Plan: Basic DDoS protection and CDN (recommended)
- Pro Plan: Advanced security features and analytics
- Business Plan: Enhanced WAF rules and priority support
- Enterprise Plan: Custom security rules and dedicated support
For most businesses, the Pro Plan offers an excellent balance of features and cost.
Step 2: DNS Configuration and Domain Verification
2.1 Review DNS Records
- Cloudflare will display all discovered DNS records
- Review each record to ensure accuracy:
- A Records: Point to your server's IP address
- CNAME Records: For subdomains and services
- MX Records: For email routing
- TXT Records: For domain verification and SPF records
- Make any necessary corrections by clicking the "Edit" button next to each record
- Ensure the Proxy Status is enabled (orange cloud icon) for records you want protected
2.2 Update Nameservers
- Cloudflare will provide you with two nameservers (e.g.,
nina.ns.cloudflare.com
and walt.ns.cloudflare.com
)
- Log into your domain registrar's control panel
- Navigate to the DNS or Nameserver settings
- Replace your current nameservers with the Cloudflare nameservers
- Save the changes
Note: Nameserver propagation can take up to 24 hours, though it's usually much faster.
2.3 Verify Domain Ownership
- Return to your Cloudflare dashboard
- Click "Check nameservers" to verify the change
- Once verified, you'll see a "Great! Your site is now active on Cloudflare" message
Step 3: Enabling Web Application Firewall (WAF) Protection
3.1 Access WAF Settings
- From your Cloudflare dashboard, select your domain
- Navigate to Security → WAF
- You'll see several tabs: Managed Rules, Rate Limiting, Custom Rules, and Tools
3.2 Enable Managed Rules
- Click on the "Managed Rules" tab
- Toggle "Enable" for the "Cloudflare Managed Ruleset"
- Choose your sensitivity level:
- Low: Minimal false positives, basic protection
- Medium: Balanced protection (recommended)
- High: Maximum protection, may require fine-tuning
- Enable "Cloudflare OWASP Core Ruleset" for additional protection against OWASP Top 10 vulnerabilities
3.3 Configure Rule Actions
For each managed ruleset, you can configure actions:
- Block: Stop malicious requests
- Managed Challenge: Present an interactive challenge
- JS Challenge: Use JavaScript-based verification
- Log: Record events without blocking
Step 4: Creating Custom Security Rules for Specific Pages
This is where we'll implement targeted protection for sensitive areas like login, registration, and password reset pages.
4.1 Access Custom Rules
- Go to Security → WAF → Custom Rules
- Click "Create Custom Rule"
4.2 Create a Rule for Authentication Pages
Rule Name: Enhanced Protection for Auth Pages
Expression Builder:
(http.request.uri.path contains "/login" or http.request.uri.path contains "/register" or http.request.uri.path contains "/forgot-password" or http.request.uri.path contains "/reset-password")
Action: Managed Challenge
or JS Challenge
4.3 Detailed Rule Configuration
- Rule Name: Enter a descriptive name for easy identification
- Field: Select
URI Path
- Operator: Choose
contains
- Value: Enter the specific path (e.g.,
/login
)
To create a rule covering multiple paths:
- Use the "Or" condition between different URI paths
- Add each sensitive endpoint:
/login
/register
/signup
/forgot-password
/reset-password
/admin
/wp-admin
(for WordPress sites)
4.4 Advanced Rule Configuration
For more sophisticated protection, you can combine multiple conditions:
(http.request.uri.path contains "/login" or http.request.uri.path contains "/register") and (cf.threat_score gt 10)
This rule triggers enhanced protection for auth pages only when the visitor has a threat score above 10.
4.5 Choose Your Challenge Type
Managed Challenge (Recommended):
- Adaptive challenge based on visitor behavior
- Better user experience
- Effective against bots and automated attacks
JS Challenge:
- Requires JavaScript execution
- Good for blocking simple bots
- May impact users with JavaScript disabled
4.6 Save and Deploy
- Review your rule configuration
- Click "Deploy" to activate the rule
- The rule will be active within a few minutes globally
Step 5: Rate Limiting Configuration
5.1 Set Up Rate Limiting for Login Pages
- Navigate to Security → WAF → Rate Limiting
- Click "Create Rate Limiting Rule"
- Configure the rule:
Rule Name: Login Attempt Limiting
Request Matching:
(http.request.uri.path eq "/login") and (http.request.method eq "POST")
Rate Limit Configuration:
- Requests: 5 requests
- Period: 60 seconds
- Action: Block for 1 hour
This prevents brute force attacks by limiting login attempts to 5 per minute per IP.
Step 6: Testing and Verification
6.1 Test Your Security Rules
- Visit your protected pages (e.g.,
/login
, /register
)
- Verify that challenges appear as expected
- Test from different IP addresses and user agents
- Use incognito/private browsing mode for accurate testing
6.2 Monitor Security Events
- Go to Security → Events to view security activity
- Review blocked requests and challenges issued
- Look for patterns that might indicate attacks or false positives
6.3 Fine-tune Rules if Necessary
If you notice legitimate users being blocked:
- Review the security events log
- Identify common patterns in blocked requests
- Create exception rules for legitimate traffic
- Adjust challenge sensitivity if needed
Step 7: Additional Security Enhancements
7.1 Enable Bot Fight Mode
- Navigate to Security → Bots
- Enable "Bot Fight Mode" for additional bot protection
- Consider upgrading to "Super Bot Fight Mode" for advanced features
7.2 Configure Security Level
- Go to Security → Settings
- Set your Security Level:
- Essentially Off: Minimal protection
- Low: Basic threat detection
- Medium: Balanced protection (recommended)
- High: Aggressive protection
- I'm Under Attack: Emergency mode
7.3 Enable Browser Integrity Check
- In Security → Settings
- Toggle on "Browser Integrity Check"
- This blocks requests from known malicious browsers and bots
Best Practices and Recommendations
Monitor Regularly
- Check your security dashboard weekly
- Review security events for new threat patterns
- Adjust rules based on observed attack trends
Keep Rules Updated
- Review and update custom rules quarterly
- Remove obsolete rules to maintain performance
- Test rules thoroughly before deploying to production
Create Exceptions When Needed
- Whitelist trusted IP addresses (office, data centers)
- Create bypass rules for legitimate automated tools
- Document all exceptions for security audits
Performance Considerations
- Too many complex rules can impact page load times
- Use specific URI matching instead of broad patterns
- Consider rule ordering for optimal performance
Troubleshooting Common Issues
Issue: Legitimate Users Being Blocked
Solution:
- Review security events to identify the blocking rule
- Create an exception rule for legitimate traffic patterns
- Consider lowering the security sensitivity
Issue: Rules Not Triggering
Solution:
- Verify the URI path syntax matches your website structure
- Test rules using Cloudflare's rule expression editor
- Check that the rule is deployed and active
Issue: False Positives
Solution:
- Implement allowlist rules for known good traffic
- Use "Log" action initially to test rule effectiveness
- Gradually increase rule strictness based on observed patterns
Conclusion
Implementing Cloudflare protection with targeted WAF rules significantly enhances your website's security posture. By focusing enhanced protection on sensitive pages like login and registration forms, you can effectively block malicious attempts while maintaining a smooth experience for legitimate users.
The configuration we've outlined provides a robust foundation for website security. Remember that security is an ongoing process – regularly review your rules, monitor security events, and adjust your configuration as threats evolve.
Need Help?
Our support team is available 24/7 to assist with any questions about implementing these security measures. Don't hesitate to reach out if you need assistance with your Cloudflare configuration or have questions about protecting your specific use case.
Have questions about implementing these security measures? Contact our support team!