Crazy amount of guests

I spent today adding a lot of countries to the managed challenge in Cloudflare, which was working well for Singapore (with a rule that excluded Google, Bing et al).
It is pretty useless to tune your CF setup as long as CF can be circumvented - waste of time.

I'm now trying to work out the best way to do IP blocking within Xenforo as I don't want to mess anything up by overloading the server doing that.
There is no way to block IPs within XF. The only options you have are either .htaccess (which typically neither supports ASN blocking or country blocking on shared hosts plus it becomes very messy and prone to failures if it grows too big) or the IP Threat Monitor add on which supports ASN and country blocking plus blocks quite a bunch of scrapers through the proxy check API. Block nasty countries and nasty ASNs within Threat Monitor, add more nasty ASNs over time and install the Bot Guard add on on top of that. Almost there.

I haven't done anything with permissions.
Then you missed the fastest and most effective way to lower your server load. "What's new" and search are both very costly. If you have thousands of bots running into those your load will be up. It goes down if you disallow search and "what's new" for guests. It is that simple.

Apparently there are only 4.3 million IPV4 addresses in the world.

Not really. Billions, not millions.
 
How I reduced the huge guest/bot traffic with Cloudflare and protected the origin server

After experiencing the same huge increase in guest traffic described in this thread, I thought I would document exactly what I did, step by step, in case it helps other XenForo administrators.

This is not intended as a universal set of blocking rules. The important part is the method:

  1. Analyse the server access logs.
  2. Put the website behind Cloudflare.
  3. Create targeted Cloudflare rules based on what the logs actually show.
  4. Prevent direct access to the origin server, so Cloudflare cannot simply be bypassed.

1. What we found in the access logs

The forum suddenly went from normal guest numbers to several hundred concurrent guests, sometimes close to 1,000, including during the night.

The raw web server logs made the problem much easier to understand.

During one period we analysed:

  • 25,055 HTTP requests reached the origin.
  • 22,938 of them (91.6%) used exactly the same suspicious User-Agent.
  • The requests were distributed across thousands of different IP addresses.

So blocking individual IP addresses was clearly not going to be an effective solution.

In our case, we also found some heavily represented ASNs and a very specific browser User-Agent being reused across thousands of IPs.

Your traffic will probably be different, so I strongly recommend analysing your own access logs instead of copying someone else's IP/ASN blocking rules.


2. Put the website behind Cloudflare

The first step was to proxy the website through Cloudflare.

Instead of:

Code:
Visitor → Origin server → XenForo

we now have:

Code:
Visitor → Cloudflare → Origin server → XenForo

Only the web hostnames need to be proxied.

Mail, FTP, control panel and other services can remain DNS-only if required by your hosting setup.

Once DNS propagation is complete, normal HTTP/HTTPS traffic should therefore reach Cloudflare before reaching the web server.


3. Create targeted Cloudflare security rules

I did NOT immediately challenge the entire XenForo installation.

Instead, I looked at the access logs and created targeted rules.

In our case these included:

  • Blocking one ASN responsible for a significant amount of the abusive traffic.
  • Managed Challenge for /whats-new/.
  • Managed Challenge for /search/.
  • Managed Challenge for the exact suspicious User-Agent identified in the access logs.

For example, a path rule can look like:

Code:
starts_with(http.request.uri.path, "/search/") and not cf.client.bot

Action:

Code:
Managed Challenge

The not cf.client.bot part allows Cloudflare verified bots to be excluded from the rule.

For the suspicious User-Agent, I used an exact match rather than challenging all visitors to XenForo threads.

That rule alone eventually recorded more than 18,000 events with a 0% Challenge Solve Rate.

I would NOT recommend blindly copying a User-Agent, ASN or country block from another forum.

Use your own logs to identify what is actually attacking your site.


4. The remaining problem: Cloudflare can potentially be bypassed

This is the part that I think is particularly important.

Putting your DNS behind Cloudflare does not necessarily make your origin server inaccessible.

If someone knows the origin IP, they may potentially connect directly to it while supplying the correct hostname.

Instead of:

Code:
Bot
 |
 v
Cloudflare
 |
 v
Origin

the bot could attempt:

Code:
Bot ──────────────> Origin

In that situation, your Cloudflare WAF/challenge rules are irrelevant because Cloudflare never sees the request.

Ideally, this should be prevented at firewall/server level by only allowing Cloudflare to access HTTP/HTTPS.

However, this was not possible with my shared hosting environment.

So I used a Cloudflare custom request header combined with .htaccess.


5. Create a secret header in Cloudflare

In Cloudflare, go to the rules section and create a Request Header Transform Rule.

The terminology may vary slightly depending on the Cloudflare interface, but the objective is:

Code:
Incoming requests: All requests

Modify request header:

Operation: Set static
Header name: X-My-Origin-Auth
Value: <LONG RANDOM SECRET>

Do NOT use X-My-Origin-Auth as your real production header name just because it appears in this example.

Choose your own header name.

More importantly, generate a long random value and keep it secret.

Conceptually Cloudflare will now send this to the origin:

Code:
X-My-Origin-Auth: a-long-random-secret-value

Do not put the blocking rule into .htaccess yet.

First test that this actually works.


6. Create a temporary PHP test

Create a temporary file in the web root, for example:

test-cloudflare.php

Contents:

PHP:
<?php

if (!empty($_SERVER['HTTP_X_MY_ORIGIN_AUTH'])) {
    echo 'CLOUDFLARE_OK';
} else {
    echo 'CLOUDFLARE_ABSENT';
}

If you chose a different HTTP header name, adjust the PHP variable accordingly.

For example:

Code:
X-My-Origin-Auth

becomes:

Code:
HTTP_X_MY_ORIGIN_AUTH

in PHP's $_SERVER array.

This PHP file does NOT display the secret. It only tells us whether the header exists.


7. Test normal access through Cloudflare

Visit:

Code:
https://www.example.com/test-cloudflare.php

through your normal browser.

You should see:

Code:
CLOUDFLARE_OK

If you see:

Code:
CLOUDFLARE_ABSENT

STOP HERE.

Do not add the blocking rule.

Your Cloudflare Transform Rule is either not working or the header is not reaching the origin.


8. Test direct access to the origin

Now we want to deliberately bypass Cloudflare.

You need to know your origin server IP for this test.

With curl, you can force a connection directly to the origin while preserving the correct hostname/SNI.

For example:

Code:
curl --resolve www.example.com:443:ORIGIN_IP https://www.example.com/test-cloudflare.php

On Windows you may need:

Code:
curl.exe --resolve www.example.com:443:ORIGIN_IP https://www.example.com/test-cloudflare.php

This request goes directly to the origin rather than resolving the hostname normally through Cloudflare.

The expected result is:

Code:
CLOUDFLARE_ABSENT

So before doing any blocking, you should have successfully demonstrated:

Code:
Normal access through Cloudflare:

CLOUDFLARE_OK


Forced direct access to origin:

CLOUDFLARE_ABSENT


9. Only now block direct access in .htaccess

Once BOTH tests above are successful, the origin can be configured to reject requests that do not contain the correct secret.

Near the beginning of .htaccess, before the normal XenForo rewrite rules, add:

Code:
<IfModule mod_rewrite.c>
    RewriteEngine On

    RewriteCond %{HTTP:X-My-Origin-Auth} !^YOUR_RANDOM_SECRET$
    RewriteRule ^ - [F,L]
</IfModule>

Replace:

X-My-Origin-Auth

with your own header name, and:

YOUR_RANDOM_SECRET

with EXACTLY the same random value configured in Cloudflare.

The check should validate the actual secret, not simply check whether the header exists.

Otherwise somebody could potentially bypass the protection simply by adding an empty/fake header with the correct name.


10. Test the website immediately

First visit the forum normally.

It should work exactly as before:

Code:
Visitor
   |
   v
Cloudflare
   |
   | Adds secret
   v
Origin
   |
   | Secret accepted
   v
XenForo

If the website returns 403 through normal access, immediately remove/disable the new .htaccess rule and check the Cloudflare header configuration.


11. Verify that direct origin access is now blocked

Repeat the direct-origin curl test, this time against the homepage:

Code:
curl -I --resolve www.example.com:443:ORIGIN_IP https://www.example.com/

On Windows:

Code:
curl.exe -I --resolve www.example.com:443:ORIGIN_IP https://www.example.com/

The expected result is now:

Code:
HTTP/1.1 403 Forbidden

while:

Code:
https://www.example.com/

continues to work normally.

At that point you have effectively achieved:

Code:
                         INTERNET
                            |
                            v
                       CLOUDFLARE
                            |
                    WAF / Challenges
                            |
                  Adds secret header
                            |
                            v
                         ORIGIN
                            |
                    Is secret valid?
                       /         \
                     YES          NO
                      |            |
                      v            v
                   XenForo        403

And a crawler trying to bypass Cloudflare gets:

Code:
Bot → Origin IP → No valid secret → 403 Forbidden


12. Clean up

Once everything has been verified, delete:

test-cloudflare.php

It is no longer needed.

Keep a copy of the working .htaccess before making future changes, and obviously keep the Cloudflare secret private.


Important considerations

This method is useful when you cannot restrict the origin to Cloudflare IP ranges at firewall/server level, for example on some shared hosting platforms.

It also means that Cloudflare becomes part of the availability path for the website. If the Cloudflare Transform Rule is removed or stops adding the header while the .htaccess restriction remains active, the origin will return 403.

So document the setup somewhere for yourself. Six months from now it is very easy to forget why that strange custom header exists in .htaccess. :)

Also be careful if the same document root serves other hostnames that are NOT proxied through Cloudflare. The .htaccess rule above would block them too. In that situation the rule should be scoped to the appropriate hostname(s).

Finally, this doesn't magically identify or eliminate every crawler.

What it does is ensure that automated traffic can no longer simply bypass the filtering layer by connecting directly to the origin.

From there, Cloudflare rules can actually do their job, and you can adjust them based on what your own access logs show.

In our case this has been considerably more effective than trying to chase thousands of rotating IP addresses.
Thank you for that. I've saved it. I've been doing some of that (checking server logs) which helped me establish a few things but there was a lot to look through.

Funnily enough AI suggested to me to do the same thing as you're suggesting in .htaccess - because as you say, just looking for a header isn't enough, it could be spoofed I guess.

Personally I'm just annoyed my IP appears to have been leaked before when I've only just been given it and am wondering about changing server again. But I guess I could get another leaked IP then.
 
It is pretty useless to tune your CF setup as long as CF can be circumvented - waste of time.
Not really. It has reduced the numbers so some are getting caught. It does help to reduce the load. And also helps see which ones are still getting through.
 
Thank you for that. I've saved it. I've been doing some of that (checking server logs) which helped me establish a few things but there was a lot to look through.

Funnily enough AI suggested to me to do the same thing as you're suggesting in .htaccess - because as you say, just looking for a header isn't enough, it could be spoofed I guess.

Personally I'm just annoyed my IP appears to have been leaked before when I've only just been given it and am wondering about changing server again. But I guess I could get another leaked IP then.
Yes, that's pretty much the conclusion I came to as well.

Changing the origin IP would certainly stop anyone using the old one, but I don't think I would change server solely for that reason. There is always a possibility that the new origin IP eventually gets discovered again.

In my case I decided to assume that the origin IP should be considered public/compromised and make that irrelevant instead.

That's really the main reason I added the secret header check.

Even if somebody knows the origin IP, they can connect to it, send the correct Host header and even spoof something called X-My-Origin-Auth if they want — but without knowing the random value Cloudflare adds, the request still gets a 403.

So effectively:

Code:
Origin IP unknown + unprotected = safe until discovered

Origin IP known + protected = still unusable without going through Cloudflare

I much prefer the second situation.

Of course, if there are other services exposed on the same IP, that's a separate consideration. But as far as bypassing Cloudflare to reach XenForo over HTTP/HTTPS is concerned, I'm now treating the origin IP itself as non-secret information.

And yes, going through the access logs was probably the most tedious part! :)

Once I found that more than 90% of the requests shared exactly the same User-Agent despite coming from thousands of different IPs, things became much easier to understand. Looking at individual IPs had initially made the traffic look far more random than it actually was.
 
more than 90% of the requests shared exactly the same User-Agent despite coming from thousands of different IPs
That seems pretty unusual for the bot waves that have been going on for ages now. What amount and what time frame are we talking about? From my experience they frequently change, even within the same wave and cannot be trusted anyway. But it seems also highly probable, that there is probably only a small hand full of actors behind the huge scraping waves, using loads or rented (and sometimes hacked) infrastructure. Given the patterns it is however more than one.
 
That seems pretty unusual for the bot waves that have been going on for ages now. What amount and what time frame are we talking about? From my experience they frequently change, even within the same wave and cannot be trusted anyway. But it seems also highly probable, that there is probably only a small hand full of actors behind the huge scraping waves, using loads or rented (and sometimes hacked) infrastructure. Given the patterns it is however more than one.
Yes, I found it unusual too, which is why it caught my attention.

To give you the actual numbers, in one access log covering roughly 00:13 to 17:41, I had:

  • 25,055 total requests
  • 22,938 requests using exactly the same User-Agent
  • 91.6% of all requests in that log

Those requests were also spread across thousands of different IP addresses.

What was particularly interesting was that the traffic wasn't constant. The wave almost disappeared at one point:

Code:
16:00 → 94 total requests / 1 with that User-Agent

Then it came back a few hours later:

Code:
19:00 → 766 total requests / 707 with that User-Agent

So I don't necessarily think this means there is a single bot/operator behind all of this. I agree that there could easily be several actors involved.

What surprised me was simply how consistent this particular signature was across such a large number of different IPs.

1788898572945.webp

I'm therefore treating the User-Agent as a useful temporary fingerprint rather than a reliable long-term way of identifying the crawler.

I certainly wouldn't rely on the User-Agent rule alone. If they change it tomorrow, that rule becomes useless. :)

That's why I've also put the other layers in place: challenges on some XenForo paths, ASN filtering where the logs justify it, and preventing direct access to the origin so that the Cloudflare rules cannot simply be bypassed.
 
Yes, that's pretty much the conclusion I came to as well.

Changing the origin IP would certainly stop anyone using the old one, but I don't think I would change server solely for that reason. There is always a possibility that the new origin IP eventually gets discovered again.

In my case I decided to assume that the origin IP should be considered public/compromised and make that irrelevant instead.

That's really the main reason I added the secret header check.

Even if somebody knows the origin IP, they can connect to it, send the correct Host header and even spoof something called X-My-Origin-Auth if they want — but without knowing the random value Cloudflare adds, the request still gets a 403.

So effectively:

Code:
Origin IP unknown + unprotected = safe until discovered

Origin IP known + protected = still unusable without going through Cloudflare

I much prefer the second situation.

Of course, if there are other services exposed on the same IP, that's a separate consideration. But as far as bypassing Cloudflare to reach XenForo over HTTP/HTTPS is concerned, I'm now treating the origin IP itself as non-secret information.

And yes, going through the access logs was probably the most tedious part! :)

Once I found that more than 90% of the requests shared exactly the same User-Agent despite coming from thousands of different IPs, things became much easier to understand. Looking at individual IPs had initially made the traffic look far more random than it actually was.
It wasn't Chinanet was it?! That seems to be my big one and apparently it has millions of IP addresses.
 
Yes, I found it unusual too, which is why it caught my attention.

To give you the actual numbers, in one access log covering roughly 00:13 to 17:41, I had:

  • 25,055 total requests
  • 22,938 requests using exactly the same User-Agent
  • 91.6% of all requests in that log

Those requests were also spread across thousands of different IP addresses.

What was particularly interesting was that the traffic wasn't constant. The wave almost disappeared at one point:

Code:
16:00 → 94 total requests / 1 with that User-Agent

Then it came back a few hours later:

Code:
19:00 → 766 total requests / 707 with that User-Agent

So I don't necessarily think this means there is a single bot/operator behind all of this. I agree that there could easily be several actors involved.

What surprised me was simply how consistent this particular signature was across such a large number of different IPs.

View attachment 344323

I'm therefore treating the User-Agent as a useful temporary fingerprint rather than a reliable long-term way of identifying the crawler.

I certainly wouldn't rely on the User-Agent rule alone. If they change it tomorrow, that rule becomes useless. :)

That's why I've also put the other layers in place: challenges on some XenForo paths, ASN filtering where the logs justify it, and preventing direct access to the origin so that the Cloudflare rules cannot simply be bypassed.
Yes and in my Cloudflare events log today having set a challenge for an awful lot of countries (all in the guest list) I was surprised to see a United States challenge as I hadn't put the Us in the challenge list, for obvious reasons. But when I checked the IP it was Tencent from China. So that is also why just blocking China doesn't work - they operate out of different countries at times.
 
It wasn't Chinanet was it?! That seems to be my big one and apparently it has millions of IP addresses.
No, not in my case.

I did see some traffic from ChinaNet (AS4134) in the Cloudflare logs, but it wasn't one of the main sources of the wave I was seeing.

The ASN that really stood out in my logs was Alibaba / AS45102. In particular, I was seeing a lot of traffic from the 43.119.x.x and 47.82.x.x ranges.

That was significant enough that I eventually blocked AS45102 at Cloudflare.

ChinaNet was present, but I didn't see enough evidence in my own traffic to justify blocking the whole ASN.

With networks that large I'm trying to be fairly conservative with ASN blocks and only add one when the logs show a very clear pattern.
 
I blocked all Alibaba's ASN's in Cloudflare - and it still comes through - so it is bypassing Cloudflare. Out of all the ASN's I blocked only Tencent and Huawei were caught. The rest were nearly all Chinese telecom types and they all bypassed Cloudflare. So I took a break from China today and decided to reduce all the other countries in the guest list with a challenge in Cloudflare. So blocking ASN's didn't help me much (a bit) but did confirm most of these Chinese bots were going direct to the origin IP.
 
@smallwheels could you explain to me how IP threat monitor works please, because I was concerned at doing anything that might increase requests to the server, at a time it was getting overloaded by the bot requests. So I couldn't quite work out what to do first for a while. But am currently going the route that @badabugs1 has posted about.
 
Just to add one thing which might be useful given the scale of your forum and the number of guests you're dealing with: I used AI to analyse the actual raw server access logs.

Rather than copying a few suspicious lines into it, I gave it the complete log files and asked it to look for patterns.

That was probably one of the most useful things I did, because even on my much smaller forum there was simply too much data to analyse comfortably by hand.

I also gave it successive log files taken at different times, which made it possible to compare how the traffic evolved and whether changes I made were actually having an effect.

With the amount of traffic you're seeing, I think this could be particularly useful. Instead of trying to follow individual IP addresses, you could ask it to correlate things like ASN, User-Agent, requested paths, frequency, response codes and timing.

It might also help answer the question you raised earlier about whether you're dealing with a small number of actors using lots of different IPs, or several genuinely different crawling patterns.

Obviously I wouldn't blindly act on everything an AI concludes from the logs, but as a tool for finding patterns in a huge amount of access-log data, I found it extremely useful.

In your case, with several thousand guests appearing at times, I'd be very interested to see what comes out of analysing a few complete logs from different periods.
 
Just to add one thing which might be useful given the scale of your forum and the number of guests you're dealing with: I used AI to analyse the actual raw server access logs.

Rather than copying a few suspicious lines into it, I gave it the complete log files and asked it to look for patterns.

That was probably one of the most useful things I did, because even on my much smaller forum there was simply too much data to analyse comfortably by hand.

I also gave it successive log files taken at different times, which made it possible to compare how the traffic evolved and whether changes I made were actually having an effect.

With the amount of traffic you're seeing, I think this could be particularly useful. Instead of trying to follow individual IP addresses, you could ask it to correlate things like ASN, User-Agent, requested paths, frequency, response codes and timing.

It might also help answer the question you raised earlier about whether you're dealing with a small number of actors using lots of different IPs, or several genuinely different crawling patterns.

Obviously I wouldn't blindly act on everything an AI concludes from the logs, but as a tool for finding patterns in a huge amount of access-log data, I found it extremely useful.

In your case, with several thousand guests appearing at times, I'd be very interested to see what comes out of analysing a few complete logs from different periods.
I did something similar but only with a section of a log, with Claude, for some reason I couldn't upload or paste the whole log but it was just for one day and I also got bogged down at that point.

My forum is actually small. And I haven't had nearly as many as a lot of others have had, but 5,000 was a heck of a lot more than my usual 180 or so and it was affecting server cpu and resources.
 
Just to add one thing which might be useful given the scale of your forum and the number of guests you're dealing with: I used AI to analyse the actual raw server access logs.

Rather than copying a few suspicious lines into it, I gave it the complete log files and asked it to look for patterns.

That was probably one of the most useful things I did, because even on my much smaller forum there was simply too much data to analyse comfortably by hand.

I also gave it successive log files taken at different times, which made it possible to compare how the traffic evolved and whether changes I made were actually having an effect.

With the amount of traffic you're seeing, I think this could be particularly useful. Instead of trying to follow individual IP addresses, you could ask it to correlate things like ASN, User-Agent, requested paths, frequency, response codes and timing.

It might also help answer the question you raised earlier about whether you're dealing with a small number of actors using lots of different IPs, or several genuinely different crawling patterns.

Obviously I wouldn't blindly act on everything an AI concludes from the logs, but as a tool for finding patterns in a huge amount of access-log data, I found it extremely useful.

In your case, with several thousand guests appearing at times, I'd be very interested to see what comes out of analysing a few complete logs from different periods.
Going back to the Cloudflare secret password and code in .htaccess. This is what AI gave me. I was wary to trust that and was going to check on here if and when I got to that stage. So it was reassuring to see that is what you had done. This was actually from Google AI - does the code look ok?

It is to paste after the existing Rewrite Engine On and before #If you are having problems ...etc

# Allow internal server requests safely
RewriteCond %{REMOTE_ADDR} ^127\.0\.0\.1$ [OR]
RewriteCond %{REMOTE_ADDR} ^::1$
RewriteRule ^ - [L]

# Block any request missing your unique Cloudflare secret word
RewriteCond %{HTTP:X-Origin-Secret-Key} !^MySuperSecretForumPass123!$
RewriteRule ^ - [F,L]
 
Going back to the Cloudflare secret password and code in .htaccess. This is what AI gave me. I was wary to trust that and was going to check on here if and when I got to that stage. So it was reassuring to see that is what you had done. This was actually from Google AI - does the code look ok?

It is to paste after the existing Rewrite Engine On and before #If you are having problems ...etc

# Allow internal server requests safely
RewriteCond %{REMOTE_ADDR} ^127\.0\.0\.1$ [OR]
RewriteCond %{REMOTE_ADDR} ^::1$
RewriteRule ^ - [L]

# Block any request missing your unique Cloudflare secret word
RewriteCond %{HTTP:X-Origin-Secret-Key} !^MySuperSecretForumPass123!$
RewriteRule ^ - [F,L]
Yes, the basic idea is correct, but I would make a couple of changes.

The important part is this:

Code:
RewriteCond %{HTTP:X-Origin-Secret-Key} !^MySuperSecretForumPass123!$
RewriteRule ^ - [F,L]

That does the same thing as my setup: if the request does not contain the expected secret value, Apache returns a 403 before XenForo processes it.

However, personally I would not add the localhost exception unless you actually know that you need it:

Code:
RewriteCond %{REMOTE_ADDR} ^127\.0\.0\.1$ [OR]
RewriteCond %{REMOTE_ADDR} ^::1$
RewriteRule ^ - [L]

That deliberately allows requests originating locally on the server to bypass the secret check.

There may be hosting setups where that is useful, but I prefer not to create an exception unless something genuinely requires it. In my case I didn't need one.

So I would start with simply:

Code:
RewriteEngine On

RewriteCond %{HTTP:X-Origin-Secret-Key} !^YOUR_SECRET_HERE$
RewriteRule ^ - [F,L]

placed before the normal XenForo rewrite rules.

One other thing to be aware of: the value in RewriteCond is interpreted as a regular expression.

So if your secret contains characters such as:

Code:
. + * ? ( ) [ ] { } ^ $ | \

they may have a special meaning.

The simplest option is to generate a long random secret using only letters and numbers, or make sure any regex characters are escaped correctly.

Also, I would definitely test it before enabling the 403 rule, exactly as I described earlier.

Create the temporary PHP test file first and confirm:

Code:
Normal request through Cloudflare
→ header present

Direct request to origin
→ header absent

Only then add the .htaccess restriction.

And obviously don't use MySuperSecretForumPass123! as the real secret now that it has been posted publicly. :)
 
Yes, the basic idea is correct, but I would make a couple of changes.

The important part is this:

Code:
RewriteCond %{HTTP:X-Origin-Secret-Key} !^MySuperSecretForumPass123!$
RewriteRule ^ - [F,L]

That does the same thing as my setup: if the request does not contain the expected secret value, Apache returns a 403 before XenForo processes it.

However, personally I would not add the localhost exception unless you actually know that you need it:

Code:
RewriteCond %{REMOTE_ADDR} ^127\.0\.0\.1$ [OR]
RewriteCond %{REMOTE_ADDR} ^::1$
RewriteRule ^ - [L]

That deliberately allows requests originating locally on the server to bypass the secret check.

There may be hosting setups where that is useful, but I prefer not to create an exception unless something genuinely requires it. In my case I didn't need one.

So I would start with simply:

Code:
RewriteEngine On

RewriteCond %{HTTP:X-Origin-Secret-Key} !^YOUR_SECRET_HERE$
RewriteRule ^ - [F,L]

placed before the normal XenForo rewrite rules.

One other thing to be aware of: the value in RewriteCond is interpreted as a regular expression.

So if your secret contains characters such as:

Code:
. + * ? ( ) [ ] { } ^ $ | \

they may have a special meaning.

The simplest option is to generate a long random secret using only letters and numbers, or make sure any regex characters are escaped correctly.

Also, I would definitely test it before enabling the 403 rule, exactly as I described earlier.

Create the temporary PHP test file first and confirm:

Code:
Normal request through Cloudflare
→ header present

Direct request to origin
→ header absent

Only then add the .htaccess restriction.

And obviously don't use MySuperSecretForumPass123! as the real secret now that it has been posted publicly. :)
That is incredibly helpful - thank you!
 
Is this vibination thing contagious? Let us know if we should keep some distance, just to make sure we don't catch it :P

Personally I'm just annoyed my IP appears to have been leaked before when I've only just been given it and am wondering about changing server again. But I guess I could get another leaked IP then.
Don't fret over it. Basically, all IPs exist and can be targeted from the moment the IPv4 standard was implemented. Maybe some IPs are assigned to some device, maybe not, but there is absolutely nothing stopping some script from trying randomly or sequentially or whatever to access anything between 1.0.0.0 and 255.255.255.254 (yeah I know not all of them are routable IPs, let's keep things simple here).

Also, an IP is not yours. It is owned by the organization (ISP, hosting, corporation) which bought it from one of the regional IP registries. These organizations then lease the IPs temporarily to others to use. Sometimes this is more of a permanent assignment, other times it is fully dynamic.

The point is, the IP your server obtained from your host wasn't suddenly created just for you, and is not tied up with you personally or your domain. It can be tested by bots with or without the knowledge of whether the IP is assigned to some device or not, what kind of device is using it, and what services is that device exposing to the internet. We don't normally see this traffic, but it's been more than 25 years since the internet was no longer "quiet" because it started to be probed, scanned and tested randomly by all sorts of bots.

And it's not all for nefarious purposes. shodan.io for example is crawling the entire internet every week to gather information about what's connected and possibly vulnerable. My parents' ISP notified them last year that the Mikrotik router I put there was not properly configured and was responding to DNS queries from the internet, which could have been abused in a DDoS; this was based on a regular shodan scan on the ISP's IP addresses they leased to their customers. I fixed the configuration, shodan refreshed their scan after a few days, all was good. But the same database can be queried by uuhhhhh Cisco let's say, to find out how many of its devices are connected by customers directly to the internet and potentially at risk when a new critical vulnerability is found and a patch is published.

Anyway, long story short - changing IP won't fix anything, won't hide you any better, it's at most the illusion of "security through obscurity". Focus on smarter things you can control and which do make a difference.
 
Back
Top Bottom