Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cloudflare Workers unreliable due to Discord's Cloudflare bans (easy fix) #7146

Open
wnelson03 opened this issue Sep 16, 2024 · 5 comments
Open
Labels
bug synced Synced to internal tracker

Comments

@wnelson03
Copy link

wnelson03 commented Sep 16, 2024

Description

Brought this issue up in #7137 and many agreed, including Cloudflare employees. though I think the Discord employee misunderstood me, he never replied after clarification given.

Experienced by myself and several others #7040

Cloudflare Workers serverless uses Shared IPs to accomplish their massive scale. There are millions of developers sharing Cloudflare's IPs, and Discord's current configuration of their Cloudflare rate limiting rule makes using serverless unreliable with Discord.

Cloudflare Workers is a popular platform used by Discord bot developers. Cloudflare has a very active presence on Discord, assisting developers with Discord integrations on a daily basis.

Discord documentation recommended developers to use Cloudflare Workers numerous times, which makes this issue more surprising.

Cloudflare has a very strong IP reputation, and they do a great job at mitigating spam and DDoS through their platform. Discord wouldn't be using Cloudflare if it wasn't secure in this manner.

Fix

The IP address 2a06:98c0:3600::103 is used always for Worker requests to other Cloudflare websites (Discord is a Cloudflare website) https://developers.cloudflare.com/fundamentals/reference/http-request-headers/#cf-connecting-ip-in-worker-subrequests (thank you @Skye-31)

Additionally, there is a cf-worker HTTP header which is only permitted use by Cloudflare workers. I tested sending header manually with my normal IP and a Cloudflare WARP IP, the header was stripped both times #7137 (comment)

Steps to Reproduce

Send an API request to Discord from a high-load Cloudflare datacenter location. Here are the Cloudflare datacenters with problems so far:

  • GRU (São Paulo, Brazil)
  • CDG (Paris, France)
  • FRA (Frankfurt, Germany)
  • WAW (Warsaw, Poland)
    image

The requested URL was https://discord.com/api/oauth2/token to exchange OAuth2 code

Expected Behavior

It would be expected that Discord API requests would succeed, with HTTP 200 code.

Current Behavior

Cloudflare Error 1015 (Global Rate Limit), when requesting the Discord API from Cloudflare datacenters that are high-load on Discord's API.

HTTP 429 code, because of Discord's configuration https://discord.com/developers/docs/topics/rate-limits#invalid-request-limit-aka-cloudflare-bans

Screenshots/Videos

Has occurred at least 1 time per week, for months.
I can be sure our software isn't hitting these limits by itself, it's not that large. Even the total requests during that time period are under the limit, and Brazil is not even in our top locations for traffic to our software. It just so happens a lot of other Discord API developers have apps running in Brazil, it seems.

366284557-2bff1d0b-91f0-4d8b-bcf7-9c3864898cb4-1
366280297-1048ebcc-85ee-431a-b566-0c4dd9ad0673

Client and System Information

Cloudflare Workers
AS13335

IP address: 2a06:98c0:3600::103

@wnelson03 wnelson03 added the bug label Sep 16, 2024
@afgiel
Copy link
Contributor

afgiel commented Sep 16, 2024

our suggested approach to avoid IP bans from shared environments like Cloudflare Workers is to use a dedicated static egress IP. we will not be making Cloudflare Workers exempt from global rate limits.

@afgiel afgiel added the synced Synced to internal tracker label Sep 16, 2024
@Le0Developer
Copy link
Contributor

Do note that is the wrong Cloudflare product and does not apply to workers.
Closests would be Aegis, but that'd require a special orange-to-orange setup or Enterprise magic.

Needless to say, both products are enterprise only. If you have that much money, you can dedicate a server for proxying traffic instead.

I don't think there is a proper solution for this except special logic that replaces the IP address with the cf-worker header for global ratelimits.

@afgiel
Copy link
Contributor

afgiel commented Sep 16, 2024

please consult this documentation https://discord.com/developers/docs/topics/rate-limits#invalid-request-limit-aka-cloudflare-bans

@wnelson03
Copy link
Author

our suggested approach to avoid IP bans from shared environments like Cloudflare Workers is to use a dedicated static egress IP. we will not be making Cloudflare Workers exempt from global rate limits.

Thank you for responding. It would be good if Discord looked into a separate, higher threshold for Cloudflare workers. Discord has the ability to add several different rate limiting rules on Cloudflare as an enterprise customer.

Also the cf-worker header is unique to each Workers website, so it's a good property to rate-limit by. That would prevent a few sites on Cloudflare workers getting spammed from affecting everyone on Cloudflare workers as a whole.

@afgiel
Copy link
Contributor

afgiel commented Sep 17, 2024

we are investigating using cf-worker as a rate limit key, but it may not be feasible for us. in the meantime a dedicated static IP is our best suggestion.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug synced Synced to internal tracker
Projects
None yet
Development

No branches or pull requests

3 participants