1
Fork 0
mmaker.moe/content/2025/01/niconico-geo-blocking/index.md
2025-12-02 23:49:51 -05:00

35 lines
3.5 KiB
Markdown

---
title: "Niconico geo-block & User-Agent spoofing"
date: 2025-01-31T16:01:12-05:00
draft: false
images:
- nicovideo-gay.png
---
Back in late October 2024, Niconico put in place access restrictions to prevent any device-restricted videos (likely containing sensitive content) from being viewed outside of Japan. [The full announcement can be read here.](https://web.archive.org/web/20241009073053/https://blog.nicovideo.jp/niconews/231350.html)
However, in practice, because much of the Internet's infrastructure is grounded in the US, this ended up breaking functionality even for users from Japan. One such example of this are [Open Graph embeds](https://en.wikipedia.org/wiki/Facebook_Platform#Open_Graph_protocol).
{{< img src="kannai-twitter.png" caption="Device-restricted video embeds have been broken on not only Twitter/X, but also Discord. [Source](https://x.com/kannai/status/1882074137742672015)" >}}
Because most social networking services proxy and cache their embeds via a web crawler, and most of these crawlers originate from an IP address located in the US, this causes embeds to break on almost every site. [Niconico has no interest in fixing this](https://x.com/kannai/status/1885215909176107041?newtwitter=true), so I decided to look into creating a service to resolve this myself, much like other "embed fixer" projects that have popped up for Discord such as [FxTwitter](https://github.com/FixTweet/FxTwitter).
{{< img src="nicovideo-gay.png" caption="Just replace '.jp' in a Niconico URL with '.gay'!" >}}
This service is available at https://www.nicovideo.gay/ --- the root URL will redirect to my own site, but any other link, such as one to a video, will directly send you to Niconico's site. Here's an example: https://www.nicovideo.gay/watch/sm29250555
Currently, this service only fixes the thumbnail and nothing more. No new functionality is added, but I may consider it later. The goal for now was just to fix what previously worked.
The thumbnail fix was pretty simple: in the initial HTTP response of a Niconico video's watch page, a JSON payload contained in a {{< inlinecode "<meta>" >}} tag with the name {{< inlinecode "server-response" >}} stores a bunch of data about the video, including the thumbnail URL. If you try to access a device-restricted video from a foreign IP, this data is absent. With a Japanese IP address, it is available.
---
Initially, I was under the assumption that true geo-blocking was implemented and I would in fact have to host this service in Japan and access Niconico with a IP address originating from Japan. It turns out, Niconico was extremely lazy implementing this. By simply spoofing the {{< inlinecode "User-Agent" >}} header with a common web crawler, i.e. {{< inlinecode "Googlebot/2.1" >}}, it completely bypasses the geo-block. This returns the JSON payload contained in the initial HTTP request.
What's even more insane about this though... is this works in any standard web browser. **No VPN is necessary.** Niconico geo-blocking can be defeated entirely by simply setting your user agent to that of a common web crawler.
That {{< inlinecode "server-response" >}} payload mentioned earlier? It doesn't contain only the thumbnail --- **it contains everything**. Right now, you can watch any device-resticted Niconico video directly from an IP address originating outside of Japan.
{{< img src="user-agent.gif" >}}
Who knows how long this will last. Or if Niconico even cares. But for now... go watch [American Gay Wrestling 2](https://www.nicovideo.jp/watch/sm200572) from America while you still can!