Skip to content

Commit 0430348

Browse files
jrx-codeclaude
andcommitted
fix: ingress double-slash 404, Supervisor API startup race, MQTT graceful fallback
- Redirect // → / in ingress middleware (Supervisor proxy sends GET //) - Retry loop waits for Supervisor API before reading config - MQTT service read with fallback when not configured Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
1 parent 5c69298 commit 0430348

4 files changed

Lines changed: 33 additions & 8 deletions

File tree

ha-sandbox/CHANGELOG.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,12 @@
11
# Changelog
22

3+
## [0.12.2] - 2026-03-10
4+
5+
### Fixed
6+
- **Ingress double-slash**`GET //` from Supervisor proxy now redirects to `/` (was returning 404)
7+
- **Startup race condition** — retry loop waits for Supervisor API before reading config (fixes "Unable to access the API, forbidden" on fresh install)
8+
- **MQTT graceful fallback** — no more error when MQTT service not configured in Supervisor
9+
310
## [0.12.1] - 2026-03-10
411

512
### Fixed

ha-sandbox/app/main.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,9 @@ async def ingress_middleware(request: Request, call_next):
6161
"""Support HA ingress by reading X-Ingress-Path header."""
6262
ingress_path = request.headers.get("X-Ingress-Path", "")
6363
request.state.ingress_path = ingress_path
64+
# Normalize double-slash from ingress proxy (GET // → redirect to /)
65+
if request.url.path != "/" and request.url.path.startswith("//"):
66+
return RedirectResponse(request.url.path.replace("//", "/", 1), status_code=301)
6467
response = await call_next(request)
6568
return response
6669

ha-sandbox/config.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
name: "HA Security Sandbox"
2-
version: "0.12.1"
2+
version: "0.12.2"
33
slug: ha_security_sandbox
44
description: "Security scanner for Home Assistant custom components — static analysis + AI review"
55
url: "https://github.com/jrx-code/ha-security-sandbox"

ha-sandbox/run.sh

Lines changed: 22 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,12 @@
44
if bashio::supervisor.ping 2>/dev/null; then
55
STANDALONE=false
66
bashio::log.info "Running as HA Add-on (Supervisor detected)"
7+
# Wait for Supervisor API to be fully ready (avoids "forbidden" on fresh install)
8+
for i in 1 2 3; do
9+
if bashio::config 'log_level' &>/dev/null; then break; fi
10+
bashio::log.info "Waiting for Supervisor API... ($i/3)"
11+
sleep 2
12+
done
713
else
814
STANDALONE=true
915
bashio::log.info "Running standalone (no Supervisor)"
@@ -25,20 +31,29 @@ if [ "$STANDALONE" = "false" ]; then
2531
export SANDBOX_AI_PROVIDER="$AI_PROVIDER"
2632

2733
# MQTT — use HA Supervisor MQTT service if available
28-
if bashio::services.available "mqtt"; then
29-
export SANDBOX_MQTT_HOST="$(bashio::services mqtt 'host')"
30-
export SANDBOX_MQTT_PORT="$(bashio::services mqtt 'port')"
31-
export SANDBOX_MQTT_USER="$(bashio::services mqtt 'username')"
32-
export SANDBOX_MQTT_PASS="$(bashio::services mqtt 'password')"
34+
if bashio::services.available "mqtt" 2>/dev/null; then
35+
export SANDBOX_MQTT_HOST="$(bashio::services mqtt 'host' 2>/dev/null || echo '')"
36+
export SANDBOX_MQTT_PORT="$(bashio::services mqtt 'port' 2>/dev/null || echo '1883')"
37+
export SANDBOX_MQTT_USER="$(bashio::services mqtt 'username' 2>/dev/null || echo '')"
38+
export SANDBOX_MQTT_PASS="$(bashio::services mqtt 'password' 2>/dev/null || echo '')"
3339
export SANDBOX_MQTT_USE_TLS="false"
34-
bashio::log.info "Using Supervisor MQTT service at ${SANDBOX_MQTT_HOST}:${SANDBOX_MQTT_PORT}"
40+
if [ -n "${SANDBOX_MQTT_HOST}" ]; then
41+
bashio::log.info "Using Supervisor MQTT service at ${SANDBOX_MQTT_HOST}:${SANDBOX_MQTT_PORT}"
42+
else
43+
bashio::log.warning "MQTT service available but could not read config"
44+
fi
45+
else
46+
bashio::log.info "No MQTT service found in Supervisor"
3547
fi
3648
export SANDBOX_MQTT_ENABLED="$(bashio::config 'mqtt_enabled')"
3749
export SANDBOX_MQTT_TLS="$(bashio::config 'mqtt_tls')"
3850

3951
# HA API via Supervisor
4052
export SANDBOX_HA_URL="http://supervisor/core"
41-
export SANDBOX_HA_TOKEN="${SUPERVISOR_TOKEN}"
53+
export SANDBOX_HA_TOKEN="${SUPERVISOR_TOKEN:-}"
54+
if [ -z "${SANDBOX_HA_TOKEN}" ]; then
55+
bashio::log.warning "SUPERVISOR_TOKEN not set — HA API access disabled"
56+
fi
4257

4358
LOG_LEVEL="$(bashio::config 'log_level')"
4459
else

0 commit comments

Comments
 (0)