File tree Expand file tree Collapse file tree 2 files changed +29
-0
lines changed Expand file tree Collapse file tree 2 files changed +29
-0
lines changed Original file line number Diff line number Diff line change @@ -8,6 +8,10 @@ if ($http_x_amzn_waf_detection = "datacenter") {
8
8
return 429;
9
9
}
10
10
11
+ if ($invalid_real_ip = 1) {
12
+ return 429;
13
+ }
14
+
11
15
error_page 429 @malicious;
12
16
13
17
location @malicious {
Original file line number Diff line number Diff line change @@ -26,6 +26,31 @@ http {
26
26
{{env "EXTERNAL_ROUTE_ADMIN" }} {{env "INTERNAL_ROUTE_ADMIN" }};
27
27
}
28
28
29
+ # Extract first IP from X-Forwarded-For header
30
+ map $http_x_forwarded_for $first_forwarded_ip {
31
+ ~^([^,\s]+) $ 1;
32
+ default "" ;
33
+ }
34
+ # Check if first IP is invalid real ip
35
+ map $first_forwarded_ip $invalid_real_ip {
36
+ # RFC 1918 Private IP ranges
37
+ ~ ^10\. 1; # 10.0.0.0/8
38
+ ~ ^172\.(1[6-9]|2[0-9]|3[01])\. 1; # 172.16.0.0/12
39
+ ~ ^192\.168\. 1; # 192.168.0.0/16
40
+
41
+ # RFC 3927 Link-local addresses
42
+ ~ ^169\.254\. 1; # 169.254.0.0/16
43
+
44
+ # RFC 5735 Loopback
45
+ ~ ^127\. 1; # 127.0.0.0/8
46
+
47
+ # RFC 1122 Current network (only valid as source)
48
+ ~^0\.0\.0\.0$ 1 ; # 0.0.0.0/32
49
+
50
+ # Default case - public IP
51
+ default 0 ;
52
+ }
53
+
29
54
server {
30
55
listen {{port}};
31
56
root public;
You can’t perform that action at this time.
0 commit comments