Deal with `private-user-images` when Fetching GitHub Discussion Body

Published in Blog/en on 12/9/2023, last edited on 1/1/1970.

When I built the new version of this blog, I used the bodyHTML that was provided by the GitHub Discussions API to improve performance. Everything went well at first, but when I set a cache for the content, the images were all broken. I found maybe caused this problem. This blog will introduce how I dealt with it.

Broken Images

I set a cache for the API to improve the performance and avoid extra requests. At first, I set the max-age to 60 * 60 which means an hour. However, about 5 more minutes later, all the images in the article were broken. When I opened the developer panel in my browser, I found that the source URLs of these images were not the original URL.

In the editor of the discussion body, my image URL was:


However, when it was rendered to HTML by the API, it turned into:

<img src="" alt="" style="max-width: 100%;">

The URL became super long with a token in it, and the source domain became I found the token was in JWT format (and also the query key mentioned that).

Decode JWT

Okay, let's figure out this from the ?jwt=.

Open , and paste the full token into the Encoded.


Then, we can find there are several useful pieces of information in the payload.

For example, the exp is for the expiration time, and the nbf is for the not valid before.


So we can infer that the expiration time for the image is 5 minutes. Because we set an hour cache at first, after the first 5 minutes, the images will be unavailable.


We can set the cache to 5 minutes to avoid the expiration happening. It will work and this is the easiest way to solve this issue.

We can also fetch body with the API to return the raw markdown format body. Then, we'll need to match and get all the source images' URLs to replace them (although this is not a good idea).

Or we can render the markdown content by ourselves or call /markdown API on