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

fix(Third party Reddit clients): Spoof user agent to workaround Reddit API issues #3253

Merged

Conversation

OctoNezd
Copy link
Contributor

Reddit started blocking all requests that contain word "android" in them: https://old.reddit.com/r/redditdev/comments/1d3spoc/error_getting_submitted_with_mobile_useragent/

Apps started getting 400 or 503, if they have "android" in their User-Agent header:

image

image

Weirdly, 400 requests get "Internal Server Error":

image

While it might be possible it is temporary outage, but it happens only with "android" in user-agent, which is suspicious, at least.

@BoxxiDev
Copy link

BoxxiDev commented May 30, 2024

If you can extend this to Joey as well I'd be super-appreciative. Since Joey is based on Boost as far as I understand it I hope it is relatively similar. Great work regardless.

@LisoUseInAIKyrios LisoUseInAIKyrios changed the base branch from main to dev May 30, 2024 21:02
@oSumAtrIX oSumAtrIX requested review from oSumAtrIX and removed request for oSumAtrIX May 30, 2024 21:05
@oSumAtrIX
Copy link
Member

Sorry the approval was by mistake

@oSumAtrIX oSumAtrIX self-requested a review May 30, 2024 21:05
Copy link
Member

@oSumAtrIX oSumAtrIX left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This PR was made because Reddit broke their oAuth API for the Android platform. In the past Reddit has caused the same issue and every time it resolved itself after a while. Sometimes a desktop browser user agent was required to bypass issues with logging in for example. For that reason this PR might be obsolete soon, if Reddit fixes their issue. Until then, Reddit should be contacted first and asked about the issue.

@oSumAtrIX oSumAtrIX linked an issue May 30, 2024 that may be closed by this pull request
3 tasks
@oSumAtrIX oSumAtrIX changed the title feat(reddit): Fix platform blacklist by reddit by setting random platform fix(Third party Reddit clients): Spoof user agent to workaround Reddit API issues May 30, 2024
@OctoNezd
Copy link
Contributor Author

Perhaps make randomizing user-agent an option? In case reddit fixes it but then it might break it again which would require this PR again.

@oSumAtrIX
Copy link
Member

That would be overengineering around a problem ReVanced isn't supposed to look at, which is why I'm even hesitant with this PR. Reddit can make any unpredictable change, not just to the user agent.

Steven-Biro added a commit to Steven-Biro/revanced-patches that referenced this pull request May 30, 2024
https://old.reddit.com/r/redditdev/comments/1d3spoc/error_getting_submitted_with_mobile_useragent/

Docile-Alligator/Infinity-For-Reddit@07c9865

might be temp: ReVanced#3253 (review)

"oSumAtrIX left a comment
This PR was made because Reddit broke their oAuth API for the Android platform. In the past Reddit has caused the same issue and every time it resolved itself after a while. Sometimes a desktop browser user agent was required to bypass issues with logging in for example. For that reason this PR might be obsolete soon, if Reddit fixes their issue. Until then, Reddit should be contacted first and asked about the issue."
@oSumAtrIX oSumAtrIX mentioned this pull request May 30, 2024
3 tasks
@OctoNezd
Copy link
Contributor Author

If you can extend this to Joey as well I'd be super-appreciative. Since Joey is based on Boost as far as I understand it I hope it is relatively similar. Great work regardless.

Implemented in e1754f3

@oSumAtrIX
Copy link
Member

RiF seems to be partially affected (#3256), although I haven't checked, if it is related to the user agent and can be fixed with this PR

@thryyy
Copy link

thryyy commented May 30, 2024

I'm getting "Invalid Request to Oauth API" even after patching with the updated patch from this PR (boost)
EDIT: Also modified the patch to use a Dekstop user agent, but It din't work either
EDIT2: Nevermind, I created a new developer app in Reddit, used the new key and it works now. Thanks for the patch !

@Chezpuf
Copy link

Chezpuf commented May 30, 2024

I am having the same issues with Baconreader. Would this fix work there too?

@ianroberts-bizclik
Copy link

RiF seems to be partially affected (#3256), although I haven't checked, if it is related to the user agent and can be fixed with this PR

RIF needs line 55 changing from:

val userAgent = "android:app.revanced.$randomName:v1.0.0 (by /u/revanced)"

To:

val userAgent = "$randomName:app.revanced.$randomName:v1.0.0 (by /u/revanced)"

@oSumAtrIX
Copy link
Member

RiF is not included in this PR, not sure what file you are referencing.

@ianroberts-bizclik
Copy link

RiF is not included in this PR, not sure what file you are referencing.

val userAgent = "android:app.revanced.$randomName:v1.0.0 (by /u/revanced)"

Unsure why it wouldn't be included as the useragent from your previous patch includes "android"

oSumAtrIX added 2 commits May 31, 2024 01:10
…lacklist

# Conflicts:
#	src/main/kotlin/app/revanced/patches/reddit/customclients/redditisfun/api/SpoofClientPatch.kt
@BoxxiDev
Copy link

BoxxiDev commented May 30, 2024

Thank you for the Joey fix! I think maybe an elegant solution to this would be to let the user specify their own user-agent instead of accepting a random one (just like client ID is currently a manual input). That would make it more future-proof as well. But I think there's a lot of people that would love it as-is simply to get their Reddit apps working on mobile working again.

@Jo0
Copy link

Jo0 commented May 30, 2024

I think maybe an elegant solution to this would be to let the user specify their own user-agent instead of accepting a random one (just like client ID is currently a manual input).

This definitely feels like the play.

@oSumAtrIX
Copy link
Member

The way it is currently done is good enough. With patching your app, you compile a "new" application in context of Reddit oAuth applications which is why it receives your personal unique user agent.

@oSumAtrIX oSumAtrIX marked this pull request as ready for review May 30, 2024 23:47
@oSumAtrIX oSumAtrIX merged commit 495e6d6 into ReVanced:dev May 30, 2024
2 checks passed
Copy link

welcome bot commented May 30, 2024

Thank you for contributing to ReVanced. Join us on Discord to receive a role for your contribution.

revanced-bot pushed a commit that referenced this pull request May 30, 2024
## [4.8.3-dev.4](v4.8.3-dev.3...v4.8.3-dev.4) (2024-05-30)

### Bug Fixes

* **3rd-party Reddit apps:** Spoof user agent to work around Reddit API issues ([#3253](#3253)) ([495e6d6](495e6d6))
@kieraneglin
Copy link

@oSumAtrIX out of curiosity, is there a reason this PR went from waiting to see if Reddit will fix it to being merged in? Not that I'm complaining, just wondering if I missed anything!

@oSumAtrIX
Copy link
Member

Because a lot of reports are coming in. It's easier to merge this and then revert if necessary, than keep it broken and wait until its fixed by Reddit.

@zimmertr
Copy link

zimmertr commented May 31, 2024

FYI, RIF just started working for me again. If this patch would have to be re-applied for this change to take place, I did not do that. So maybe it has been resolved upstream.

@oSumAtrIX
Copy link
Member

As expected. Spoofing the user agent won't break it, but it's unnecessary if it doesn't fix anything.

@CodingDinosaur
Copy link

RIF is still not working for me, so I'm not sure if this has been adjusted by Reddit or not. I will update if it starts working.

@zimmertr
Copy link

You're correct, I was wrong. Comments still aren't loading.

I believe that when things originally broke, the app would not load a feed at all. When it started to do so, I thought the issue was resolved.

@kieraneglin
Copy link

@OctoNezd heads up, I have a bounty on this bug! Check out #3255

@TortoiseFather
Copy link

Hi all,
Sorry for noob question but will I need to make a new Reddit app to patch rif?

I'm just following [https://www.reddit.com/r/Android/comments/14niwgu/revanced_patches_for_boost_infinity_rif_is_fun/](this guide) but I imagine its out of date

@ianroberts-bizclik
Copy link

ianroberts-bizclik commented May 31, 2024

Forked the repo and forced a release live to test, working as expected for RIF with the new patch, thanks oSumAtrIX

@ksnaden
Copy link

ksnaden commented May 31, 2024

Thanks, I used revanced-cli and patched RiF. Works. Much appreciated.

@AElimrani
Copy link

Awesome!! Can confirm this works, just have to use the same patch as before. Maybe adding a new name might be helpful (instead of just spoof client Id). Thanks a lot!

@KoenLemmen
Copy link

Does this include a fix for baconreader?

@kokroo
Copy link

kokroo commented May 31, 2024

I'm confused. Could someone please explain how to apply this newest patch to RIF?

@CodingDinosaur
Copy link

CodingDinosaur commented May 31, 2024

The new patch hasn't been merged to main yet. See #3234.

You won't be able to use the patch until it's merged and released. (Unless you use an advanced method such as the cli or a fork, but if you're not sure how to do this just wait for the release)

@e-xception
Copy link

Any chance we could also get Slide for Reddit updated? Many thanks!

@Duramoin
Copy link

Duramoin commented May 31, 2024

@ksnaden hello, could you please post your whole command for rif? thanks.. I am getting error.. i use jars and integration with latest version and rif apk from apkmirror

java -jar cli.jar patch rif.apk -b patches.jar -m integrations.apk -o rif1.apk

INFO: Aligning APK

org.bouncycastle.jcajce.provider.keystore.bc.BcKeyStoreSpi$BCKeyStoreException: java.io.IOException: Error initialising store of key store: java.lang.SecurityException: JCE cannot authenticate the provider BC
at org.bouncycastle.jcajce.provider.keystore.bc.BcKeyStoreSpi.engineSetKeyEntry(Unknown Source)
at java.base/java.security.KeyStore.setKeyEntry(KeyStore.java:1191)
at app.revanced.library.ApkSigner.newKeyStore(ApkSigner.kt:56)
at app.revanced.library.ApkUtils.newPrivateKeyCertificatePair(ApkUtils.kt:114)
at app.revanced.library.ApkUtils.signApk(ApkUtils.kt:167)
at app.revanced.cli.command.PatchCommand.run(PatchCommand.kt:321)
at picocli.CommandLine.executeUserObject(CommandLine.java:2026)
at picocli.CommandLine.access$1500(CommandLine.java:148)
at picocli.CommandLine$RunLast.executeUserObjectOfLastSubcommandWithSameParent(CommandLine.java:2461)
at picocli.CommandLine$RunLast.handle(CommandLine.java:2453)
at picocli.CommandLine$RunLast.handle(CommandLine.java:2415)
at picocli.CommandLine$AbstractParseResultHandler.execute(CommandLine.java:2273)
at picocli.CommandLine$RunLast.execute(CommandLine.java:2417)
at picocli.CommandLine.execute(CommandLine.java:2170)
at app.revanced.cli.command.MainCommandKt.main(MainCommand.kt:12)
Caused by: java.io.IOException: Error initialising store of key store: java.lang.SecurityException: JCE cannot authenticate the provider BC
at org.bouncycastle.jcajce.provider.keystore.bc.BcKeyStoreSpi.makePBECipher(Unknown Source)
at org.bouncycastle.jcajce.provider.keystore.bc.BcKeyStoreSpi$StoreEntry.(Unknown Source)
... 15 more

@oSumAtrIX
Copy link
Member

For For support, move to one of our links at https://revanced.app.

@ReVanced ReVanced locked as resolved and limited conversation to collaborators May 31, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

bug: Sync for reddit returns an HTTP 400 when loading some pages [w/ bounty]