Create a Cloudflare WAF rule
Step 1: Create a WAF Rule to Match Sensitive URIs
-
Log in to Cloudflare:
- Go to Cloudflare (opens in a new tab) and log in with your credentials.
-
Select the Domain:
- Choose the domain where your Laravel application is hosted.
-
Navigate to the WAF Section:
- Go to the
Security
tab and selectWAF
.
- Go to the
-
Create a New WAF Rule:
- Click on
Create a Firewall Rule
.
- Click on
-
Configure the Rule:
- Rule Name: Give your rule a descriptive name, like
Match Sensitive File Requests
. - When incoming requests match...:
-
Use the Field dropdown to select
URI Path
. -
Set the Operator to
contains
. -
Add the sensitive paths you want to match:
(http.request.uri.path contains ".env") or (http.request.uri.path contains "env")
-
- Rule Name: Give your rule a descriptive name, like
-
Choose the Action:
- Set the action to
Challenge
.
- Set the action to
-
Deploy the Rule:
- Save and deploy the rule.
Step 2: Set Up a Rate Limiting Rule
-
Navigate to the Rate Limiting Section:
- Go to the
Rules
tab and selectRate Limiting
.
- Go to the
-
Create a New Rate Limiting Rule:
- Click on
Create a Rate Limiting Rule
.
- Click on
-
Configure the Rule:
-
Rule Name: Give your rule a descriptive name, like
Rate Limit Sensitive File Requests
. -
When incoming requests match...:
-
Set the Field to
URI Path
. -
Set the Operator to
contains
. -
Add the path you want to match:
.env
-
-
Request URL: Match the request URL as per your need.
-
Threshold: Set to
10
. -
Period: Set to
10 minutes
. -
Action: Choose
Block
and set the duration for how long you want to block the IP, e.g.,1 hour
.
-
-
Deploy the Rule:
- Save and deploy the rule.
Example WAF Rule Expression
Here's how the WAF rule expression might look:
(http.request.uri.path contains ".env") or
(http.request.uri.path contains "env")
OR
(http.request.uri contains ".aws" or
http.request.uri contains ".env" or
http.request.uri contains ".log" or
http.request.uri contains "storage" or
http.request.uri contains ".svn" or
http.request.uri contains ".DS_Store" or
http.request.uri contains "backup" or
http.request.uri contains "phpinfo" or
http.request.uri contains ".htaccess" or
http.request.uri contains ".htpasswd" or
http.request.uri contains ".git" or
http.request.uri contains ".docker" or
http.request.uri contains ".vscode" or
http.request.uri contains ".ssh" or
http.request.uri contains "adminer.php" or
http.request.uri contains "node_modules" or
http.request.uri contains "error.log" or
http.request.uri contains "debug.log" or
http.request.uri contains ".config" or
http.request.uri contains ".idea" or
http.request.uri contains ".bash_history" or
http.request.uri contains ".bashrc" or
http.request.uri contains ".profile" or
http.request.uri contains ".db" or
http.request.uri contains ".sqlite" or
http.request.uri contains "phpMyAdmin" or
http.request.uri contains "/execute-solution")
Example Rate Limiting Rule
-
When incoming requests match...:
- Field:
URI Path
- Operator:
contains
- Value:
.env
orenv
- Field:
-
Threshold:
10
-
Period:
10 minutes
-
Action:
Block
-
Duration:
1 hour
Save and Apply
- After configuring both the WAF and rate limiting rules, save and apply the changes.
These configurations will help you detect and block IPs that are attempting to access sensitive .env
files or similar paths multiple times, enhancing the security of your Laravel application.