Skip to content

fix: encode referer header to fix #1206#1268

Open
yingyu5658 wants to merge 3 commits into
ReadYouApp:mainfrom
yingyu5658:fix-referer-header
Open

fix: encode referer header to fix #1206#1268
yingyu5658 wants to merge 3 commits into
ReadYouApp:mainfrom
yingyu5658:fix-referer-header

Conversation

@yingyu5658
Copy link
Copy Markdown

Encode referer header to avoid crashing when header includes non-ASCII characters.

@Ashinch
Copy link
Copy Markdown
Member

Ashinch commented May 15, 2026

Could you provide some example cases for this?
As far as I know, domain names normally shouldn’t contain non-ASCII characters directly.🤔

@yingyu5658
Copy link
Copy Markdown
Author

Hi,

You are right that standard domain name shouldn't contain non-ASCII characters. However, the Referer string extracted from some wild RSS feed often contains the entire image URL or a relative path with Chinese/Japanese characters.

When these non-ASCII strings are passed directly into OkHttp's headers, OkHttp strictly validates them and throws a fatal IllgealArgumentExcepetion, causing the entire app to crash immediately.

Here is a real-world example case. If we subscribe to https://taxodium.ink/album.xml and click on it, the app crashes:

java.lang.IllegalArgumentException: Unexpected char 0x6d77 at 17 in Referer value: 20251226T173833--海马森林__20240423_mimikbanka_albumwall_image_表情银行.webp

    at okhttp3.internal._HeadersCommonKt.headersCheckValue(-HeadersCommon.kt:121)

    at okhttp3.Headers$Builder.add(Headers.kt:14)

    at me.ash.reader.ui.component.base.RYAsyncImageKt.RYAsyncImage(RYAsyncImage.kt:444)

    at me.ash.reader.ui.page.home.flow.ArticleItemKt.ArticleItem(ArticleItem.kt:272)

    at me.ash.reader.ui.page.home.flow.ArticleItemKt.ArticleItem(ArticleItem.kt:24)

    at me.ash.reader.ui.page.home.flow.ArticleItemKt.SwipeableArticleItem$lambda$41(ArticleItem.kt:192)

    at me.ash.reader.ui.page.home.flow.ArticleItemKt.$r8$lambda$rmqIUc46DiG9exB2wkJsiW7rhyA(ArticleItem.kt:1)

    at me.ash.reader.ui.page.home.flow.ArticleItemKt$$ExternalSyntheticLambda12.invoke(R8$$SyntheticClass:41) 

...

To be honest, my previous PR didn't work properly as I'm not very familiar with Android or Kotlin development, and I don't have a complete local environment on this machine to fully test it.

I'm not quite sure how to implement the most idiomatic fix for ReadYou, but my basic idea is to use Uri.encode() to percent-encode the non-ASCII characters before passing them to OkHttp.

Since there is definitely a crash bug here, I would be very grateful if you could take over and implement a proper fix, or give me some guidance/suggestions on how to write it correctly. Thanks for your time : )

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.

2 participants