Repository navigation
fix(command): validate a frontend hostname before committing it to the main-process state - #1315
Merged
Merged
Conversation
FlorentinDUBOIS
changed the base branch from
fix/router-trie-insert-panic
to
main
August 27, 2026 21:03
FlorentinDUBOIS
enabled auto-merge
August 27, 2026 21:04
FlorentinDUBOIS
disabled auto-merge
August 27, 2026 21:09
FlorentinDUBOIS
enabled auto-merge (rebase)
August 27, 2026 21:09
…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
force-pushed
the
fix/main-process-frontend-validation
branch
from
August 27, 2026 21:24
b5b01e6 to
8137921
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
#1313: the main process records an
Add(Http|Https)Frontendin itsConfigStatebefore any worker judges it, and theLoadStatereplay path has no rollback at all — so a frontend the route table rejects (malformed hostname, since #1312 answered withFailureinstead of a panic) is re-injected intoConfigStateon every load, re-persisted bySaveState, and re-rejected by every worker on every replay, forever.Fix
A main-process validator, on the #1301 listener-validation pattern:
validate_frontend_requestdry-runs the frontend through a throwawayRouter— the exact code both worker arms run (to_frontend()+Router::add_http_front), so master-accepts ⇔ worker-router-accepts by construction, covering theDomainRuleparse, the trie grammar,MAX_HOSTNAME_LENGTH, and all three rule positions — wired into:state.dispatchand the fan-out: the client getsFailure, nothing entersConfigState;LoadStatereplay andload_static_config: an invalid entry is skipped with a redactedwarn!(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_validationunit 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.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 carryingraat-app.cleverapps.io/); restored → all green. Independently re-executed by a second reviewer.Commands run
cargo test -p sozu --locked→ 72 passedcargo clippy -p sozu --all-targets --locked -- -D warnings→ cleancargo +nightly fmt --all -- --check→ cleanNotes
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
LoadStateTaskrollback (for rejection reasons no validator can predict, e.g. the worker HTTP arm refusinghstson a plain-HTTP listener before the router is consulted) deliberately stays open under this issue.