Skip to content

fix: close the defects a fifth audit found - #6

Merged
dinhdev666 merged 1 commit into
mainfrom
fix/fifth-audit-defects
Nov 24, 2026
Merged

dinhdev666 merged 1 commit into
mainfrom
fix/fifth-audit-defects

Conversation

@dinhdev666

Copy link
Copy Markdown
Owner

A fresh audit of the engine, the gateway, the dashboard and the storage layer.

What was wrong

  • A client abort charged the provider a breaker failure and a full cooldown: five
    cancelled requests from one impatient tab retired a healthy provider. 404 did the same,
    retiring a fleet merely pointed at a model the provider no longer serves.
  • The SSRF guard saw only IPv4-mapped addresses. NAT64 (64:ff9b::/96,
    64:ff9b:1::/48), IPv4-compatible and 6to4 all carry a real IPv4 host — on an IPv6-only pod,
    http://[64:ff9b::7f00:1]/ is a working request to loopback.
  • Login lockout forgot its evidence. The counting window was a hard-coded hour while
    LOGIN_LOCKOUT_MS allows any duration, and the count was capped by LIMIT 50, which a
    threshold above fifty could never reach.
  • /api/* authenticated after the body was parsed, so an unauthenticated 50 MiB
    POST /api/providers was buffered before refusal — the hole invariant 4 closes for /v1.
  • Changing the dashboard password signed the operator out: the kept session still carried
    the old token_version, and /api/auth/session skipped the comparison entirely.
  • A 503 queue_full counted as an error and its 30 s wait as latency, contradicting
    invariant 8 on both charts read for provider health and speed.
  • A JSON body was masked by value shape, so LOG_BODIES=1 logged
    {"model":"[REDACTED]","error_code":"[REDACTED]"}.
  • The SSE scanner never resynchronised after an over-long line, losing [DONE] and every
    in-band error behind it.
  • A TRUSTED_PROXIES typo — ::ffff:10.0.0.0/8 — matched every address, turning the one
    setting whose purpose is to narrow trust into a fail-open.
  • An abandoned CSV export hung, holding the SQLite read cursor behind a hijacked reply.
  • A log search let its term act as a LIKE pattern; nextActiveAt had a tested
    implementation and no caller.

Verification

pnpm run check, pnpm run typecheck, pnpm test:unit (400 checks),
SMOKE_SLOW=1 pnpm run test:smoke (349 checks) and pnpm run build all pass, and the router
boots with /health 200, /v1/models public, /api/* 401 unauthenticated and a clean SIGTERM.

New tests cover the abort and 404 classifications, Retry-After: 0, the three additional SSRF
prefixes, the scanner resync, a lockout longer than an hour, a threshold above fifty, JSON
masking by name, LIKE metacharacters, the queue-full metric, the reissued session version, the
mapped-prefix refusal, and a refusal that arrives before the body is read.

A client hanging up was classified as a provider failure, with the same
breaker weight and cooldown as an unreachable host, so five cancelled
requests from one impatient tab retired a healthy provider. A 404 was
treated the same way, retiring a fleet that had merely been pointed at a
model the provider no longer serves. Both now fail over without charging
the provider.

The SSRF guard recognised only IPv4-mapped addresses. NAT64, the prefix an
IPv6-only pod uses to reach an IPv4 literal, carries 127.0.0.1 and
169.254.169.254 unchanged and was judged as ordinary IPv6.

The login lockout counted inside a hard-coded hour while the setting allows
any duration, so a two-hour lockout forgot its own evidence halfway
through; the count was also capped by `LIMIT 50`, which a threshold above
fifty could never reach.

The dashboard authenticated in its handlers, after the body had been
parsed, so an unauthenticated 50 MiB POST was buffered before refusal -
the hole invariant 4 closes for /v1. It now runs in preParsing, which also
lets the per-address limiter count the refusal; at onRequest the limiter's
hook had not run yet and a 401 was free.

Changing the dashboard password signed the operator out: the kept session
still carried the old token version, which the guard compares. The session
read route skipped that comparison entirely.

Elsewhere: a queue-full refusal was counted as an error and its 30 s wait
as latency; a JSON body was masked by value shape, hiding `model` and
`error_code`; the SSE scanner never resynchronised after an over-long line
and lost every later frame; a mapped TRUSTED_PROXIES entry with an
IPv4-sized prefix matched every address; an abandoned CSV export hung
holding the SQLite cursor; a log search let the term act as a LIKE pattern.

nextActiveAt had a tested implementation and no caller, so the Providers
tab could not say when an out-of-schedule provider returns.
@dinhdev666
dinhdev666 merged commit 5abcdd0 into main Nov 24, 2026
6 checks passed
@dinhdev666
dinhdev666 deleted the fix/fifth-audit-defects branch November 24, 2026 04:07
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.

1 participant