Skip to content

fix(command): validate a frontend hostname before committing it to the main-process state - #1315

Merged
FlorentinDUBOIS merged 1 commit into
mainfrom
fix/main-process-frontend-validation
Aug 27, 2026
Merged

FlorentinDUBOIS merged 1 commit into
mainfrom
fix/main-process-frontend-validation

Conversation

@FlorentinDUBOIS

Copy link
Copy Markdown
Collaborator

Problem

#1313: the main process records an Add(Http|Https)Frontend in its ConfigState before any worker judges it, and the LoadState replay path has no rollback at all — so a frontend the route table rejects (malformed hostname, since #1312 answered with Failure instead of a panic) is re-injected into ConfigState on every load, re-persisted by SaveState, and re-rejected by every worker on every replay, forever.

Fix

A main-process validator, on the #1301 listener-validation pattern: validate_frontend_request dry-runs the frontend through a throwaway Router — the exact code both worker arms run (to_frontend() + Router::add_http_front), so master-accepts ⇔ worker-router-accepts by construction, covering the DomainRule parse, the trie grammar, MAX_HOSTNAME_LENGTH, and all three rule positions — wired into:

  • the live command path, before state.dispatch and the fan-out: the client gets Failure, nothing enters ConfigState;
  • the LoadState replay and load_static_config: an invalid entry is skipped with a redacted warn! (byte lengths only) and counted (load_skipped_invalid), instead of poisoning the state — a load whose entries are all skipped still succeeds;
  • Remove* verbs are deliberately not validated, so cleanup of state poisoned before this fix stays possible.

Tests

  • frontend_validation unit suite (6 tests) + a new e2e (frontend_validate_before_commit_e2e) that round-trips a poisoned saved state through the real binary and proves the malformed entry is skipped and no longer re-persisted.
  • Seen red first by stubbing the validator to Ok(()): 5 unit tests fail and the e2e reproduces the exact LoadState replay has no rollback: a poisoned saved state re-injects rejected entries forever #1313 pathology (saved state carrying raat-app.cleverapps.io/); restored → all green. Independently re-executed by a second reviewer.

Commands run

  • cargo test -p sozu --locked → 72 passed
  • cargo clippy -p sozu --all-targets --locked -- -D warnings → clean
  • cargo +nightly fmt --all -- --check → clean

Notes

Based on #1312 — will be retargeted/rebased onto main once it merges.

Refs #1313 — input validation closes the poisoning class for hostnames, but the generic LoadStateTask rollback (for rejection reasons no validator can predict, e.g. the worker HTTP arm refusing hsts on a plain-HTTP listener before the router is consulted) deliberately stays open under this issue.

…ain-process state

`ConfigState` has no route-grammar check: `add_http_frontend` only reparses the
address and maps the position, so an `Add{Http,Https}Frontend` whose hostname
every worker's router refuses is still recorded by the main process. That state
is authoritative — `SaveState` re-serialises the malformed entry and every
replay re-injects it — and the replay path has no rollback at all, so the entry
survived a unanimous worker rejection and poisoned each subsequent restart.

The main process now runs the worker's OWN insertion path — the same
`Router::add_http_front`, against a disposable empty router — before
`ConfigState::dispatch`, on all three apply paths (`worker_request`,
`load_state`, `load_static_config`) through one shared `validate_request` entry
point that also keeps the #1301 listener check. A live frontend add is answered
with a failure and never fanned out; a malformed entry in a saved state file or
in the static configuration is skipped without entering the state, so it can
never be re-persisted nor re-injected.

Skipped entries — frontends and, as before, unbuildable listeners — are now
reported at `warn!` instead of `debug!`, because an entry silently dropped from
the state the operator saved must be visible at the default log level, and
`load_state` reports how many it skipped. The rejection strings are
`RouterError` / `RequestError` `Display` values, which carry byte lengths only,
never the operator-supplied hostname.

Based on #1312: the disposable-Router probe is only safe once
`Router::add_http_front` returns an error instead of aborting the process on
this hostname class, and once `convert_regex_domain_rule` no longer indexes out
of bounds. Without those the probe would panic the main process rather than a
worker.

The generic replay rollback — undoing entries the workers reject for reasons no
input validation can predict — stays out of scope and open in #1313: the probe
is the worker's own code, so an entry that passes it is not refused for
grammar, and the hostname class is now closed at the door on every path.

Refs #1313

Signed-off-by: Florentin Dubois <[email protected]>
@FlorentinDUBOIS
FlorentinDUBOIS force-pushed the fix/main-process-frontend-validation branch from b5b01e6 to 8137921 Compare August 27, 2026 21:24
@FlorentinDUBOIS
FlorentinDUBOIS merged commit 74913a9 into main Aug 27, 2026
16 of 17 checks passed
@FlorentinDUBOIS
FlorentinDUBOIS deleted the fix/main-process-frontend-validation branch August 28, 2026 06:33
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