fix(komga): keep the reader inside the ingress panel (#2995)

* fix(komga): keep the reader inside the ingress panel

Komga's ui opens the reader with window.open(url, '_blank'). The Home
Assistant companion apps hand such a popup to an external browser, which
carries no ingress session cookie, so Home Assistant answers 401 before
Komga is reached.

Nginx now injects a small script into the ui shell that turns same origin
popups into a navigation in the current tab. The OAuth2 login popup, which
passes a window name and a feature string, and cross origin links are left
untouched.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>

* fix(komga): only intercept popups when resourceBaseUrl is known

Review feedback : the '/' fallback meant that if Komga ever stopped
setting window.resourceBaseUrl, every same origin _blank popup would be
captured -- and ingress shares the Home Assistant origin. Require the
base, and give it a trailing slash so a sibling path such as
<entry>/komgaX is not treated as being below <entry>/komga.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>

---------

Co-authored-by: Claude Opus 5 <noreply@anthropic.com>
This commit is contained in:
Alexandre
2026-08-19 07:30:47 +02:00
committed by GitHub
parent 29ce08c162
commit 9302fc9a51
3 changed files with 24 additions and 2 deletions

View File

@@ -1,4 +1,7 @@
## 1.26.3.1 (19-08-2026)
- Fix : tapping `Read` in the Home Assistant companion app opened the reader in an external browser, which carries no ingress session cookie, so Home Assistant answered `401 Unauthorized` before Komga was reached ([#2994](https://github.com/alexbelgium/hassio-addons/issues/2994)). Komga opens the reader with `window.open(url, '_blank')` ; nginx now injects a script that turns that popup into a navigation of the ingress panel itself. Only http(s) urls below Komga's own base path are affected, so the OAuth2 login popup and links out of Komga keep their own window
## 1.26.3 (2026-08-13)
- Update to latest version from gotson/komga (changelog : https://github.com/gotson/komga/releases)
## 1.26.1.4 (12-08-2026)

View File

@@ -101,4 +101,4 @@ schema:
slug: komga
udev: true
url: https://github.com/alexbelgium/hassio-addons/tree/master/komga
version: "1.26.3"
version: "1.26.3.1"

View File

@@ -60,6 +60,25 @@ server {
# Only the json/xml document types are added here, so book pages are
# never scanned.
sub_filter "http://127.0.0.1:25600/komga" "%%ingress_entry%%/komga";
# Komga opens the reader with window.open(url, '_blank'). In the Home
# Assistant companion apps the ingress panel is a webview, which hands
# such a popup to an external browser : that browser carries no ingress
# session cookie, so Home Assistant answers 401 before Komga is even
# reached. Turn that popup into a navigation of the panel itself, but
# only for the call shape Komga uses (name _blank, no feature string)
# and only for http(s) urls below window.resourceBaseUrl. That leaves
# the OAuth2 login popup (window.open(url, 'oauth2Login', '<features>'),
# which needs its own window), blob urls and links out of Komga alone,
# and if Komga ever stopped setting resourceBaseUrl the popup is left
# untouched rather than widened to the whole Home Assistant origin,
# which ingress shares. Anchored on the single page app mount point :
# both Komga ui shells carry it once, and only a book served as
# text/html rather than the xhtml the epub spec mandates could collide
# with it -- the same exposure the /komga filter above already has, and
# Komga sends script-src 'none' on that endpoint.
sub_filter "<div id=\"app\">" "<script>(function(){var o=window.open;window.open=function(u,n,f){try{var b=window.resourceBaseUrl;if(u&&n==='_blank'&&!f&&b){if(b.slice(-1)!=='/')b+='/';var t=new URL(u,location.href);if((t.protocol==='http:'||t.protocol==='https:')&&t.origin===location.origin&&t.pathname.indexOf(b)===0){location.assign(t.href);return window}}}catch(e){}return o.apply(window,arguments)}})();</script><div id=\"app\">";
sub_filter_types application/json application/webpub+json
application/divina+json application/opds+json
application/atom+xml;