mirror of
https://github.com/alexbelgium/hassio-addons.git
synced 2026-09-28 12:24:01 +02:00
fix(calibre-web): trust the supervisor range for the ingress auth header (#3010)
* fix(calibre-web): trust the supervisor range for the ingress auth header Reimplements #3004 from the code as it stood before it, in one statement. #3004 derived the addon's own address and wrote it unconditionally on every start. That address changes across restarts, so the value had to be rewritten each boot, which erased anything the user had added to the same field from the calibre-web admin page -- and a follow-up that preserved their entries needed a merge pass and a record of what had been injected, because a preserved stale address stays trusted after supervisor hands it to another addon. Trusting 172.30.32.0/23 removes the reason for all of it: the range covers whichever address the addon gets, so the value is constant and can be written once. Both forms are listed because calibre-web listens dual-stack and an ipv4 entry never matches an ipv4-mapped address; /119 is the mapped equivalent of /23. The WHERE clause is what keeps it out of the user's way. The list is written only when the range is absent, which is true on a fresh 0.6.27 install and on an install still carrying #3004's per-address list, and false afterwards -- so an entry added in the admin page for a reverse proxy outside the supervisor network survives every later start. The trade-off is that any addon on the supervisor network can now present X-WebAuth-User to port 8083 and be logged in. Maintainer's call, taken knowingly in preference to the machinery the narrow list required. The tolerated failure from #3004 is kept: the column only exists once calibre-web 0.6.27+ has migrated app.db and cont-init runs first, so the statement is allowed to fail and the next start applies it. The sqlite error is now included in the warning rather than dropped. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com> * fix(calibre-web): guard on the mapped range and keep existing entries Addresses the review on #3010, both findings inside the one statement. Codex, Copilot and CodeRabbit all noted the WHERE clause tested only 172.30.32.0/23, so a value carrying the ipv4 range without the mapped form would skip the update forever while ingress stayed rejected -- a plausible state, since that is exactly what someone adds by hand after reading that the supervisor network is the source. Rather than test both, the guard now tests ::ffff:172.30.32.0/119 alone. That is the form ingress actually needs, given calibre-web listens dual-stack, and the form nobody types by hand, so it serves as the marker that this already ran. One substring either way. Copilot and CodeRabbit also noted the assignment replaced the whole column, losing an administrator entry on the first start. The required list is now prepended to the existing value instead of replacing it. No case expression is needed for the empty and NULL cases : the trailing comma that leaves behind is an empty entry, which calibre-web's parser skips. Both together cost one `||coalesce(...)` and a different substring. The statement still runs at most once, and the duplicates it can leave behind are entries calibre-web skips, or addresses inside the range now trusted anyway. Checked against a transcription of cps/reverse_proxy_auth.py from 0.6.27 : every produced value parses with nothing ignored, ::ffff:172.30.33.10 is trusted and ::ffff:192.168.1.99 is not. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com> --------- Co-authored-by: Claude Opus 5 <noreply@anthropic.com>
This commit is contained in:
@@ -1,4 +1,7 @@
|
||||
|
||||
## 0.6.27.2 (2026-08-23)
|
||||
- Fix: trust the whole supervisor network range for the ingress auth header instead of the addon's own address, which changes across restarts. The list is only written when that range is missing, so an entry added in the calibre-web admin page is no longer erased on every start (https://github.com/alexbelgium/hassio-addons/pull/3010)
|
||||
|
||||
## 0.6.27.1 (2026-08-23)
|
||||
- Fix: Ingress login was rejected since 0.6.27, which only accepts the reverse proxy auth header from trusted source addresses. The addon now adds its own ip to that list (https://github.com/alexbelgium/hassio-addons/issues/3003)
|
||||
|
||||
|
||||
@@ -116,5 +116,5 @@ schema:
|
||||
slug: calibre-web
|
||||
udev: true
|
||||
url: https://github.com/alexbelgium/hassio-addons/tree/master/calibre_web
|
||||
version: "0.6.27.1"
|
||||
version: "0.6.27.2"
|
||||
video: true
|
||||
|
||||
@@ -19,25 +19,19 @@ if [ ! -f /config/app.db ]; then
|
||||
else
|
||||
sqlite3 /config/app.db 'update settings set config_reverse_proxy_login_header_name="X-WebAuth-User",config_allow_reverse_proxy_header_login=1'
|
||||
|
||||
# Calibre-web 0.6.27 only accepts the ingress auth header from a trusted source address, and
|
||||
# defaults that list to "127.0.0.1,::1". Nginx binds its upstream socket to the addon ip
|
||||
# (proxy_bind $server_addr in ingress.conf) and calibre-web listens dual-stack, so it sees
|
||||
# ::ffff:<addon ip> and drops the header. Both the plain and the ipv4-mapped forms are listed
|
||||
# because an ipv4 entry never matches an ipv6-mapped address on the calibre-web side.
|
||||
# The column only exists once calibre-web 0.6.27+ has migrated app.db, so a failure here is
|
||||
# not fatal : the next start applies it.
|
||||
addon_ip=$(bashio::addon.ip_address)
|
||||
trusted_ips="127.0.0.1,::1,::ffff:127.0.0.1"
|
||||
if bashio::var.has_value "${addon_ip}"; then
|
||||
trusted_ips="${trusted_ips},${addon_ip},::ffff:${addon_ip}"
|
||||
fi
|
||||
trusted_ips_error=$(sqlite3 /config/app.db "update settings set config_reverse_proxy_trusted_ips='${trusted_ips}'" 2>&1) || {
|
||||
if echo "${trusted_ips_error}" | grep -q "no such column"; then
|
||||
bashio::log.warning "Could not set the ingress trusted ip list, it will be applied at next start"
|
||||
else
|
||||
bashio::log.warning "Could not set the ingress trusted ip list: ${trusted_ips_error}"
|
||||
fi
|
||||
}
|
||||
# Calibre-web 0.6.27 only accepts that header from a trusted source address, and defaults the
|
||||
# list to "127.0.0.1,::1". Ingress reaches calibre-web from the addon's own address on the
|
||||
# supervisor network (proxy_bind $server_addr in ingress.conf) and calibre-web listens
|
||||
# dual-stack, so it sees ::ffff:<addon ip> and drops the header. The supervisor range is
|
||||
# listed in both forms because an ipv4 entry never matches an ipv4-mapped address.
|
||||
# Prepended to whatever is already there, and only when the mapped form is missing : that form
|
||||
# is the one ingress needs and the one nobody types by hand, so it doubles as the marker that
|
||||
# this already ran. Anything the user added is kept, the statement runs at most once, and the
|
||||
# duplicates it can leave behind are entries calibre-web skips or already trusts.
|
||||
# The column only exists once calibre-web 0.6.27+ has migrated app.db and cont-init runs
|
||||
# before calibre-web, so a failure here is not fatal : the next start applies it.
|
||||
trusted_ips_error=$(sqlite3 /config/app.db "update settings set config_reverse_proxy_trusted_ips='127.0.0.1,::1,::ffff:127.0.0.1,172.30.32.0/23,::ffff:172.30.32.0/119,'||coalesce(config_reverse_proxy_trusted_ips,'') where coalesce(config_reverse_proxy_trusted_ips,'') not like '%::ffff:172.30.32.0/119%'" 2>&1) ||
|
||||
bashio::log.warning "Could not set the ingress trusted ip list, it will be applied at next start (${trusted_ips_error})"
|
||||
fi
|
||||
|
||||
bashio::log.info "Default username:password is admin:admin123"
|
||||
|
||||
Reference in New Issue
Block a user