Skip to content

fix(security): firmware critical findings (8 of 10 fixed; 2 deferred) - #4

Merged
johnsonflix merged 1 commit into
evolights/mainfrom
fix/firmware-criticals
May 3, 2026
Merged

johnsonflix merged 1 commit into
evolights/mainfrom
fix/firmware-criticals

Conversation

@johnsonflix

Copy link
Copy Markdown
Owner

Summary

Fixes 8 of 10 critical/HIGH findings from the recent EvoLights security review of wled_cloud_auth.{cpp,h} and the AuthGate. Each fix is anchored with EVOLIGHTS-ANCHOR comments and matched by a positive check in tools/verify-evolights-integration.sh so a future merge can't silently regress them.

Fixes in this PR (FIXED)

# Issue Anchor
1 Cloud-trusted token forgeable from LAN cloud-token-loopback-only
2 AP-mode bypass exposed entire UI ap-setup-allowlist
3 /auth/setup race + post-factory-reset takeover auth-setup-mutex, auth-setup-presence
4 /cloud/pair and /cloud/unpair honoured cloud-trusted token cloud-pairing-session-only
7 PBKDF2 iters (4096 → 50000) pbkdf2-iters
8 Login timing oracle (username enumeration) login-timing-oracle-verify
9 Session table eviction always picked slot 0 session-lru-eviction
10 Cookie parser substring-matched EVOAUTHX= cookie-parse-anchored

Deferred

# Issue Reason
5 OTA accepts older signed manifests (downgrade) Lives in usermods/cloud_relay/ota_verifier.cpp, which is on feat/firmware-signed-ota (PR #2), not on evolights/main. Will follow up in that PR.
6 OTA CDN CA pinning Same: ota_verifier.cpp not in this base. The simplest implementation also requires editing cloud_relay.cpp (owned by PR #3 feat/cloud-relay-tls). Will follow up after #2 lands.

Verifier additions

New anchors enforced by tools/verify-evolights-integration.sh:

  • cloud-token-loopback-only, cloud-pairing-session-only (in cpp)
  • ap-setup-allowlist (in cpp)
  • auth-setup-mutex, auth-setup-presence (in cpp)
  • session-lru-eviction, cookie-parse-anchored, login-timing-oracle-verify (in cpp)
  • pbkdf2-iters (in header)

Plus positive security invariants:

  • PBKDF2_ITERS >= 50000
  • isLoopbackPeer symbol referenced
  • /cloud/pair and /cloud/unpair mentioned in isAuthorized
  • g_setupInProgress flag exists
  • Cookie parser contains anchored markers (atStart, afterDelim)

Compatibility

  • Stored hashes embed their iteration count (v1$<iters>$<salt>$<hash>), so existing 4096-iter accounts keep working until the user changes their password.
  • PBKDF2_ITERS widened from uint16_t to uint32_t; pbkdf2(), encodeHashBlob(), and decodeHashBlob() updated to match. Format string switched from %u to %lu. decodeHashBlob now uses strtoul instead of atoi.
  • AP-setup bypass is intentionally narrowed. WiFi setup flow uses /welcome, /settings/wifi, /settings.js, /settings/wifi.js, /style.css, /favicon.ico — all in the new allowlist.

Test plan

  • bash tools/verify-evolights-integration.sh (37 PASS / 0 FAIL locally)
  • CI: 3x firmware build envs (esp32dev, esp32_eth, esp32s3dev_8MB_qspi)
  • CI: verify-integration
  • Manual smoke once merged: AP-mode setup flow, post-setup login, /cloud/pair refusing cloud-trusted token, /auth/setup 403 after 5min uptime when not in AP mode

🤖 Generated with Claude Code

@johnsonflix

Copy link
Copy Markdown
Owner Author

CI status

The verify check (the EvoLights integration verifier — the security invariant set this PR adds to) is PASSING: 37 PASS / 0 FAIL. All eight new anchors and positive security checks are enforced.

The wled_build matrix (esp32dev / esp32_eth / esp32s3dev_8MB / etc.) and the EvoLights build (esp32dev|esp32_eth|esp32s3dev_8MB) matrix are failing, but those failures are pre-existing on evolights/main (same SHAs failing on the base branch HEAD aa0a3057 before this PR was opened):

  • wled00/wled_cloud_auth.h:82-83: error: using typedef-name 'ArduinoJson::JsonObject' after 'class' — the class JsonObject forward-decl that lives on evolights/main. PR feat: TLS for cloud relay MQTT (port 8883, pinned CA, fail closed) #3 (feat/cloud-relay-tls) already fixes this by including src/dependencies/json/ArduinoJson-v6.h and dropping the class keyword. Once feat: TLS for cloud relay MQTT (port 8883, pinned CA, fail closed) #3 lands, this PR's CI will go green.
  • wled00/cfg.cpp:1372:24: error: cannot bind non-const lvalue reference of type 'int&' to an rvalue of type 'int' — same root cause: the broken forward decl makes the compiler think JsonObject is int.
  • The EvoLights firmware-build workflow (build (esp32dev) etc.) hits a separate ProjectOptionValueError: Infinite recursion has been detected for 'build_flags' option in the 'env:esp32dev' section that's a pre-existing CI-config bug, also fixed on feat/cloud-relay-tls by switching to *_evolights envs.

Nothing in this PR changes the JsonObject forward decl, the cfg.cpp signature, or the firmware-build workflow — so those failures remain identical to base. The intended order of operations is to land PR #3 first, after which a rebase here will go fully green.

This PR's actual code changes are confined to wled_cloud_auth.{cpp,h} and tools/verify-evolights-integration.sh.

🤖 Generated with Claude Code

Eight related security fixes in wled_cloud_auth.{h,cpp}, plus matching
verifier invariants. Each is anchored with EVOLIGHTS-ANCHOR comments so a
future merge can't silently regress them.

1. cloud-token-loopback-only: cloud-trusted token only honoured when the
   request peer is 127.0.0.1. Previously any LAN client carrying a leaked
   or guessed token bypassed auth.

2. ap-setup-allowlist: replace blanket "AP + no WiFi configured" bypass
   with an explicit allowlist (welcome, /settings, /settings/wifi*, .js,
   .css, /favicon.ico). /edit, /update, /json/cfg, /settings/sec etc.
   now require auth even pre-setup.

3. auth-setup-mutex + auth-setup-presence: serialize concurrent
   /auth/setup POSTs (single-flight via volatile flag + RAII guard) AND
   require physical-presence proxy (request must be in AP mode OR within
   5 minutes of boot). Closes the post-factory-reset takeover window.

4. cloud-pairing-session-only: refuse the cloud-trusted token for
   /cloud/pair and /cloud/unpair. Those endpoints require a real local
   session so a remote actor with the bypass token can't wipe pairing.

7. pbkdf2-iters: bump PBKDF2 from 4096 -> 50000 (target ~600ms login
   latency on ESP32 @ 240MHz). Stored hashes embed the iter count so
   existing accounts keep working with their original iter count until
   the user changes their password.

8. login-timing-oracle-verify: always run PBKDF2 against a fixed dummy
   salt+hash on the unknown-user path, denying the attacker a
   username-enumeration timing oracle.

9. session-lru-eviction: when the session table fills, evict the slot
   with the smallest lastUsedAt (real LRU) instead of always slot 0,
   which used to boot the active admin out on a 9th login.

10. cookie-parse-anchored: cookie matcher now requires "EVOAUTH=" to be
    at the start of the Cookie header OR preceded by "; ", so a
    malicious cookie like "EVOAUTHX=junk" can't smuggle a token in.
    The parsed token is also trimmed before use.

Also: extend tools/verify-evolights-integration.sh with the eight new
anchors plus positive security checks (PBKDF2 floor, isLoopbackPeer
reference, /cloud/pair && /cloud/unpair mention in isAuthorized,
g_setupInProgress flag, anchored cookie parse markers).

Deferred from this PR (file lives in feat/firmware-signed-ota PR #2,
not in evolights/main):
- ota_verifier downgrade-attack (#5)
- ota_verifier CDN CA pinning (#6)

Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
@johnsonflix
johnsonflix force-pushed the fix/firmware-criticals branch from fec8b77 to 5799cde Compare May 3, 2026 15:15
@johnsonflix
johnsonflix merged commit f9683d4 into evolights/main May 3, 2026
19 of 28 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants