monkeytype icon indicating copy to clipboard operation
monkeytype copied to clipboard

API Request is Blocked by Cloudfare (Likely Cloudfare's DDoS Protection) if Made from Github Action

Open vnphanquang opened this issue 2 years ago • 10 comments

Is there an existing issue for this?

  • [X] I have searched the existing issues

Current Behavior

The Public API is all good if request is made from end users themselves (Postman, browser, local dev, ...) but is blocked with a 503 response status ("Service Temporarily Unavailable") by cloudfare if made from github action. The response body is an HTML that renders to this:

cloudfare_ddos

Initial discussion on discord can be found here. I suspect this is Cloudfare DDoS blocking requests from servers with high traffic. In my case it was github action server, but I believe some other servers might also be subject to this.

This issue will potential become a blocker for users that rely on the public API running inside a deployed server elsewhere, especially as the apis grow and are used by more and more people.

Please take a look into this. If a workaround is not possible, it should be noted somewhere for others to know about.

Thanks a lot team!

Expected Behavior

The public API allows requests from servers such as github action.

Steps To Reproduce

  1. Setup a github action
  2. Call any monkeytype api endpoint in (1)
  3. Expect a 503 response

Environment

Github action

Anything else?

The github action I have basically does an equivalence to this in a unit test:

const response = await fetch(
            'https://api.monkeytype.com/users/personalBests?mode=time&mode2=30',
            {
                headers: {
                    Authorization: 'ApeKey ...',
                },
            }
        );

For completion, this is where the actual code is. The issue is initally reported in https://github.com/vnphanquang/monkeytype-readme/issues/1

vnphanquang avatar Apr 24 '22 02:04 vnphanquang

@Bruception sorry to drag you into this. I've talked about it in discord a while back. Just want to let you know I made an issue here for reference.

vnphanquang avatar Apr 24 '22 02:04 vnphanquang

Ive checked the logs and tried allowing some IP addresses through the firewall. Try now.

Miodec avatar Apr 24 '22 10:04 Miodec

@Miodec Thanks. Still no luck unfortunately. Have you try lifting firewalls for listed github action IPs? You can refer to this docs, which says a GET to https://api.github.com/meta returns a list of said IPs.

From my debugging, the IP of the server my particular action ran on was 20.242.116.228.

Hope that helps.

vnphanquang avatar Apr 24 '22 12:04 vnphanquang

From my debugging, the IP of the server my particular action ran on was 20.242.116.228.

Hmm, that address in not on the list https://api.github.com/meta

Miodec avatar Apr 24 '22 13:04 Miodec

Yeah, i'm not sure either. But that ip is likely to change every time the github action runs. I used @haythem/public-ip action to find the IP (which essentially queries https://api.ipify.org). I would just stick to the list from github api.

This stackoverflow thread is relevant, if of any help.

vnphanquang avatar Apr 25 '22 02:04 vnphanquang

Try now

Miodec avatar Apr 25 '22 15:04 Miodec

@Miodec thanks. I tried a couple of times just now, still failing though...

vnphanquang avatar Apr 25 '22 15:04 vnphanquang

Whats the exact request that youre making? Can you check if GET https://api.monkeytype.com/ also gets blocked?

Miodec avatar Apr 25 '22 17:04 Miodec

GET https://api.monkeytype.com/ is okay. The exact request is https://api.monkeytype.com/users/personalBests?mode=time&mode2=30

vnphanquang avatar Apr 25 '22 23:04 vnphanquang

Maybe its getting blocked because youve only been testing on that one endpoint? How long has it been since you last tried? Can you try again? Can you try the personal bests endpoint?

Miodec avatar Apr 28 '22 10:04 Miodec

@vnphanquang Can you test again?

Miodec avatar Aug 26 '22 20:08 Miodec

Maybe its getting blocked because youve only been testing on that one endpoint? How long has it been since you last tried? Can you try again? Can you try the personal bests endpoint?

Oh no sincerely apologies i missed the notification for this.

@vnphanquang Can you test again?

Just tested, it works again. Thanks a lot @Miodec !

vnphanquang avatar Aug 26 '22 23:08 vnphanquang