capgo icon indicating copy to clipboard operation
capgo copied to clipboard

Find a better way to block google play test device

Open riderx opened this issue 2 years ago โ€ข 46 comments

For a period i did set a ip ban for google IP sadly it was also blocking some user with vpn. i need to find a better option

riderx avatar May 11 '23 15:05 riderx

/bounty $100

riderx avatar Aug 09 '23 14:08 riderx

๐Ÿ’Ž $100 bounty โ€ข Capgo

Steps to solve:

  1. Start working: Comment /attempt #229 with your implementation plan
  2. Submit work: Create a pull request including /claim #229 in the PR body to claim the bounty
  3. Receive payment: 100% of the bounty is received 2-5 days post-reward. Make sure you are eligible for payouts

Additional notes:

โ„น๏ธ If something is not clear ask before working on it, otherwise your chance to rework it is high ๐ŸŽฅ To claim you need to provide in your PR a demo video of the change ๐Ÿ‘จโ€๐Ÿ‘ฉโ€๐Ÿ‘งโ€๐Ÿ‘ฆ Join the Discord to get help ๐Ÿ“ Check all Bounty rules

Thank you for contributing to Cap-go/capgo!

Add a bounty โ€ข Share on socials

Attempt Started (GMT+0) Solution
๐Ÿ”ด @rishi-raj-jain Aug 13, 2023, 6:21:48 PM WIP
๐Ÿ”ด @ologbonowiwi Oct 13, 2023, 7:19:17 PM WIP
๐Ÿ”ด @WcaleNieWolny Oct 13, 2023, 7:24:33 PM WIP

algora-pbc[bot] avatar Aug 09 '23 14:08 algora-pbc[bot]

/attempt #229

where do we want the ban to be applied? on the web? more details would help!

Options

rishi-raj-jain avatar Aug 13 '23 18:08 rishi-raj-jain

this is for the update endpoint. when users have CI/CD to publish to google play store then google play is starting the app and request live update. who are counted in users billing plan. So the goal is to be able to know what is a google bot device and block the update, to not count in billing

riderx avatar Aug 14 '23 11:08 riderx

On it!

rishi-raj-jain avatar Aug 14 '23 12:08 rishi-raj-jain

This is partially fixed by https://github.com/Cap-go/capgo/pull/314 correct?

if redis does get merged can I just add a fn in the updates_cached that will call supabase, check if device exists in cache and if it does not then return the cached version (if possible). Here is how I see it:

1. Only if app exists in redis and the requested version is cached
2. Check if device exists in cache, if it does not create it as `standard` (not overwritten) and set some sort of value that indicates the requests (like for example `device_{ID}_usage` to 1
3. When this usage > 5 (or any other threshold) then call the update endpoint

This will fix this by forcing the google devices to never exceed this threshold thus the user will not be billed for them

The downside of this is that if a device does not send at least 5 requests then it cannot be overwritten in the dashboard. Also if app calls setChannel then we need to ensure that it will work even if there is not such device in the supabase db. setChannel is a gigantic pain when caching

WcaleNieWolny avatar Sep 02 '23 18:09 WcaleNieWolny

@WcaleNieWolny isn't that the same as I've been suggesting in https://github.com/Cap-go/capgo/pull/267 to @riderx?

rishi-raj-jain avatar Sep 02 '23 18:09 rishi-raj-jain

Perhaps, I was not sure what "forever blocked" ment. I proposed this as I submitted a PR with redis and it was just a thought

WcaleNieWolny avatar Sep 02 '23 18:09 WcaleNieWolny

@riderx mentions in https://github.com/Cap-go/capgo/pull/267#issuecomment-1678265784 that redis isn't an option, but anyways he refers to storing lot of IPs as an expensive operation. In any case, of rate limiting by 5 attempts or rate limiting by 1 attempt (that is within the last time vs new time wherever the user should be able to update), we're storing IPs with unique param (say app_id) of each update request that comes. But if Redis becomes part of the stack, the cost of Upstash is like 0.2$ per 100K which I think would be fine for @riderx?

rishi-raj-jain avatar Sep 02 '23 18:09 rishi-raj-jain

Perhaps, I was not sure what "forever blocked" ment. I proposed this as I submitted a PR with redis and it was just a thought

Hope you didn't take me the wrong way, I was just confirming

rishi-raj-jain avatar Sep 02 '23 18:09 rishi-raj-jain

that redis isn't an option

A lot of things happened after that comment. Capgo got a gigantic client that caused a lot of downtime as capgo was not able to scale. Since then adding redis became an option.

I already implemented caching for /updates and I wanted to build upon that. This implementation works with device id and NOT the IP. I believe using this device_id is enough. Why would we store the ip if we can just respond with the cached response without ever calling the updates endpoint for new devices that have not yer made at least 5 requests? This would essentially create zero records in supabase and remove the unnecessary cost from the users bill.

Regardless, I am sorry if I appeared as if I was trying to steal your idea

WcaleNieWolny avatar Sep 02 '23 19:09 WcaleNieWolny

Regardless, I am sorry if I appeared as if I was trying to steal your idea

Nah, that's why I clarified here at https://github.com/Cap-go/capgo/issues/229#issuecomment-1703913414

rishi-raj-jain avatar Sep 02 '23 19:09 rishi-raj-jain

Go ahead, rock it!

rishi-raj-jain avatar Sep 02 '23 19:09 rishi-raj-jain

Thanks guys for putting your 2 brain on it ! I value your opinion but I wonder if such practices ( the 5 first request idea ) Will not reduce the accuracy of stats about usage, and also bring weird behavior for set channel like happening too late when user expect instant update. For me the best idea for Google issue is more finding a way to identify and ban the right IP

riderx avatar Sep 03 '23 00:09 riderx

Yeah, for that, @riderx we can tweak my solution of storing into redis as 1 or forever flag to storing the "hot" IPs by using redis keys with expiry. Shall I elaborate more?

rishi-raj-jain avatar Sep 04 '23 08:09 rishi-raj-jain

So imagine only 10 hot IPs and 1M not so hot IPs,

We store all of them in the redis with set to expiry say X (an inbuilt functionality of redis). If the time crosses X and we see no re-occurence the key is dropped automatically from your database. If we do receive, it's kept in your database for an increased number of the count.

This takes care of the database maintaining itself.

Also, note, we have to decide what is considered as a hot IP. Let's say if any IP gets above Y updates refs in the period X, we'll blacklist it.

rishi-raj-jain avatar Sep 04 '23 08:09 rishi-raj-jain

That's what I meant, let me know if this makes sense or needs a POC, I'm good at those :D

rishi-raj-jain avatar Sep 04 '23 08:09 rishi-raj-jain

There is no way to do a PoC right now, redis is still not merged

WcaleNieWolny avatar Sep 04 '23 08:09 WcaleNieWolny

You could expand on my redis branch but right now I am not sure when will it get merged

WcaleNieWolny avatar Sep 04 '23 08:09 WcaleNieWolny

I mean we don't need the whole redis PR to be merged for this, this'll be super quick with just using the upstash package in the update endpoint.

rishi-raj-jain avatar Sep 04 '23 08:09 rishi-raj-jain

Okay, go for the PoC ๐Ÿ‘

WcaleNieWolny avatar Sep 04 '23 08:09 WcaleNieWolny

Awesome! I'll be on it in a day.

rishi-raj-jain avatar Sep 04 '23 22:09 rishi-raj-jain

What still needs to be done on this one?

I'm up to it @WcaleNieWolny @riderx.

/attempt #229

Options

wesleymatosdev avatar Oct 13 '23 19:10 wesleymatosdev

Mainly a actual test run with a published play store app if I understand correctly

WcaleNieWolny avatar Oct 13 '23 19:10 WcaleNieWolny

So we're already blocking it, we only need to check if the block is working?

wesleymatosdev avatar Oct 13 '23 19:10 wesleymatosdev

I'm on it! Had a discussion with @riderx where I need to add an endpoint for this

rishi-raj-jain avatar Oct 13 '23 19:10 rishi-raj-jain

On it after the CF thing we're doing today

rishi-raj-jain avatar Oct 13 '23 19:10 rishi-raj-jain

Oh sorry for it, your pr was closed I thought you canceled your attempt.

Go for it mate!

wesleymatosdev avatar Oct 13 '23 19:10 wesleymatosdev

wait what

rishi-raj-jain avatar Oct 13 '23 19:10 rishi-raj-jain

omg I deleted the cap-go/capgo for a fork shit

rishi-raj-jain avatar Oct 13 '23 19:10 rishi-raj-jain