Skip to content

Comments

Add option to change user agent and a cookie to send verified requests to Cloudflare protected websites.#91

Open
grous0 wants to merge 4 commits intothebuildcraft:mainfrom
grous0:cf-fix
Open

Add option to change user agent and a cookie to send verified requests to Cloudflare protected websites.#91
grous0 wants to merge 4 commits intothebuildcraft:mainfrom
grous0:cf-fix

Conversation

@grous0
Copy link

@grous0 grous0 commented Jan 12, 2026

This is a simple change to fix #90 but temporarily. It adds 2 options user agent and a field for cf_clearance cookie.

This does not use CookieManager because it adds extra complexity for just 1 cookie. If project ever needs to have more than 1 cookie (for example a cookie list option might be added) consider changing to CookieManager.

cf_clearance cookie has a life span of 6 months (at least that's what Cloudflare says when adding the cookie) so after 6 months cookie must be renewed.

This change is only tested in 1.21.10 Fabric. I didn't tested it for other versions or mod loaders because it is 1:00 AM...

Another solution is introducing something like Selenium to actually solve the Cloudflare challenge inside the mod. But this introduces lot more complexity and dependency.

Locales:

  • English
  • Chinese

@grous0
Copy link
Author

grous0 commented Jan 12, 2026

This commit

Messes up with the versions below 1.19.2 thing. idk why it did that probably IntelliJ "cleanup".

Signed-off-by: Ömer Ferhat Şenel <grousee@proton.me>
@thebuildcraft
Copy link
Owner

Sorry for the late reply. I currently don't have time to completely review, test, compile and release it. Once my exams are over I will work on this :)

@thebuildcraft
Copy link
Owner

I just tested it, but I can't get it to work. Cloudflare still returns 403 for some reason.
Can you please test it again if it still works for you?

@grous0
Copy link
Author

grous0 commented Feb 16, 2026

I just tested it, but I can't get it to work. Cloudflare still returns 403 for some reason. Can you please test it again if it still works for you?

Can you check that User Agent is also the same User Agent that cf-clearance issued with? It still works for me. You can also check it with an API client or cURL.

@thebuildcraft
Copy link
Owner

Yes. I also copied the User-Agent from my Firefox. What browser did you use? I will try some more isolated testing then.

@grous0
Copy link
Author

grous0 commented Feb 16, 2026

Yes. I also copied the User-Agent from my Firefox. What browser did you use? I will try some more isolated testing then.

I also used Firefox, Can you tell me the map website you're testing? I will test that out later when i come home.

@thebuildcraft
Copy link
Owner

The one from your config: https://map.atlantikmc.com
And thanks for your help :)

@grous0
Copy link
Author

grous0 commented Feb 16, 2026

The one from your config: https://map.atlantikmc.com And thanks for your help :)

Can you confirm that the IP address used to get cf_clearance is the same when you use the mod?

@thebuildcraft
Copy link
Owner

Yes. Its the same PC same OS right after I copied the cookie and user agent from firefox.

@grous0
Copy link
Author

grous0 commented Feb 16, 2026

So if it still returns 403 then i will test more, meanwhile can you test it with different servers? I will enhance the code and write a test for it.

@grous0
Copy link
Author

grous0 commented Feb 16, 2026

@thebuildcraft It seems like the website has a geoblock which is the reason why it works on me. I think you can try different websites and they'll work.

@thebuildcraft
Copy link
Owner

Yea, that's also what I thought. I only found 1 other Cloudflare protected map from an old Github Issue here... But that also seems to geoblock me. But maybe Cloudflare doesn't like my IP after all the testing anymore for today...

Do you think it's realistic that server owners add a way to decrease the Cloudflare security level for my mod so it can bypass the region block with just the cookie and user-agent combo?

@grous0
Copy link
Author

grous0 commented Feb 17, 2026

Yea, that's also what I thought. I only found 1 other Cloudflare protected map from an old Github Issue here... But that also seems to geoblock me. But maybe Cloudflare doesn't like my IP after all the testing anymore for today...

Do you think it's realistic that server owners add a way to decrease the Cloudflare security level for my mod so it can bypass the region block with just the cookie and user-agent combo?

I doubt server owners will do anything. But in the cases where server admin want to allow traffic for this mod, maybe Cloudflare filtering system has a User-Agent filter or something like that to allow traffic. So requests sent with User-Agent: MapLink will bypass the Cloudlflare protection.

Maybe i can spin up a "stub" Cloudflare-protected website for testing?

@thebuildcraft
Copy link
Owner

User-Agent-only-whitelisting would be very easy to exploit by real bots. One thing I saw on another server is that it blocks player position requests if you are not connected to the minecraft server (probably IP based).

If you want to make a testing site where Cloudflare doesn't escalate to the highest security level for IP addresses from other countries, sure :)
If that works reliably then, admins could just remove that geoblock and still have good protection.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Cloudflare bot protection blocks the mod

2 participants