
Prevent Panics in Rust DNS Parsers for Malformed SVCB and HTTPS Parameters
A malformed SVCB or HTTPS zone-file parameter can panic in affected versions of hickory-proto: the value alpn=" reaches quote stripping, where slicing the lone quote as [1..0] panics instead of returning a parse error. An attacker able to supply zone-file or record-text input can therefore trigger a denial of service. Upgrade to hickory-proto 0.26.2 or later, or reject a lone quote before slicing; add regression tests that verify malformed input returns an error without panicking. This issue does not affect DNS wire-format decoding.
Scope and affected behavior
RUSTSEC-2026-0489, also identified as CVE-2026-123573 and GHSA-wgfr-mphw-j5g4, describes a panic while parsing SVCB or HTTPS records from their text (zone-file) representation. The vulnerable operation removes surrounding double quotes from service parameter values. A value containing exactly one double quote passes the parser’s “starts and ends with a quote” check, but removing the first and last character attempts the invalid range [1..0].
This is an input-validation failure with a denial-of-service consequence: Rust bounds-checks string slices and panics on an invalid range. The advisory identifies versions 0.20.1 through 0.26.1 as the affected range and 0.26.2 as patched; versions below 0.20.1 are listed as unaffected. Check the advisory and your resolved dependency tree before drawing conclusions about a fork or backport.
The affected path is specifically text parsing. Records decoded from DNS wire format do not use this quote-stripping path and are not affected by this bug. That distinction matters when choosing tests: exercise the zone-file or record-text parser, not just wire-format decoding.
Environment and baseline
The examples target Rust 1.82+ (Edition 2021) and hickory-proto 0.26.2 or later. Use the version compatible with your application’s other Hickory crates; keep related Hickory dependencies aligned rather than upgrading only one crate without checking compatibility.
For a direct dependency, pin a patched compatible release in Cargo.toml:
[dependencies]
hickory-proto = "0.26.2"
Cargo’s caret requirement allows compatible later 0.26.x releases. For an application that receives zone files or record text from outside its trust boundary, also verify the resolved version in Cargo.lock or with cargo tree. A manifest requirement alone does not demonstrate which version is built in a deployed binary.
The panic mechanism: quote stripping on an empty interior
The vulnerable logic is equivalent to this simplified pattern:
fn strip_surrounding_quotes(value: &str) -> &str {
if value.starts_with('"') && value.ends_with('"') {
&value[1..value.len() - 1]
} else {
value
}
}
For a normal quoted value such as "h2", the slice selects the interior h2. For the one-character string ", both starts_with('"') and ends_with('"') are true. Its byte length is one, so the intended end index is zero and the expression becomes [1..0]. This is a reversed range, and indexing panics.
The same failure can be triggered by a parameter such as alpn=" when the SVCB or HTTPS text parser passes the parameter value to this operation. The parser must treat the input as malformed and return a parse error; it must not rely on callers catching a panic.
Production fix: upgrade first, validate before slicing
The preferred remediation for an application using the affected crate is to upgrade to hickory-proto 0.26.2 or later, as specified by the advisory. The patched parser rejects the lone quote with a parse error before attempting to slice.
If you maintain a fork, an older compatibility branch, or a wrapper that performs equivalent quote stripping, validate the shape before computing a slice. One clear implementation is:
fn strip_surrounding_quotes(value: &str) -> Result<&str, &'static str> {
if value.starts_with('"') && value.ends_with('"') {
// A one-byte value cannot contain a non-empty quoted interior.
if value.len() < 2 {
return Err("quoted parameter value is missing its contents");
}
Ok(&value[1..value.len() - 1])
} else {
Ok(value)
}
}
The length guard makes the slice range valid. Since the delimiter is ASCII, its byte length is one; slicing after that byte remains on a UTF-8 character boundary. The caller should convert this validation failure into the parser’s normal structured error type, including context such as the parameter key where practical. Do not map malformed input to a default value: that can silently change record semantics.
An alternative avoids manual end-index arithmetic:
fn strip_surrounding_quotes(value: &str) -> Result<&str, &'static str> {
match value.strip_prefix('"') {
Some(rest) => rest
.strip_suffix('"')
.ok_or("quoted parameter value has no closing quote"),
None if value.ends_with('"') => Err("quoted parameter value has no opening quote"),
None => Ok(value),
}
}
For a lone quote, strip_prefix produces an empty string and strip_suffix returns None; no invalid slice is formed. Choose the version that matches the parser’s established quoting rules. In particular, do not unintentionally reject or reinterpret unquoted values if the grammar permits them.
Regression tests for the actual boundary
A useful regression test asserts the public contract—malformed text produces an error—rather than merely asserting that a helper happens not to panic. For a wrapper around the vulnerable logic, test both the minimal failure and ordinary valid input:
#[test]
fn lone_quote_is_rejected_without_panicking() {
let result = strip_surrounding_quotes("\"");
assert!(result.is_err());
}
#[test]
fn quoted_parameter_keeps_its_interior() {
assert_eq!(strip_surrounding_quotes("\"h2\"").unwrap(), "h2");
}
For an application using Hickory, add a test at the same text-parsing entry point used in production. Construct an SVCB or HTTPS record-text fixture containing alpn=" and assert that parsing returns an error. The exact API and fixture syntax depend on the Hickory version and the application’s zone-file parser; keep the fixture as close as possible to the real input boundary. Testing only strip_surrounding_quotes would miss a later panic or a parser path that never calls the helper.
Avoid making catch_unwind the expected production behavior. A test may use it temporarily to demonstrate that an old dependency panics, but the fixed behavior should be an ordinary Err, not a caught panic. If parsing runs in a long-lived server, a panic can unwind through request handling or terminate a process depending on panic strategy and boundaries. Input validation should prevent the panic before it occurs.
Dependency verification and differential checks
First confirm what Cargo resolves and whether the advisory applies:
cargo tree -i hickory-proto
cargo tree -i hickory-proto --locked
cargo test --locked
After updating the manifest and lockfile, inspect the resolved version again. If a transitive dependency keeps an affected version in the graph, update the parent crate or use an appropriate, reviewed dependency override; do not assume that adding a second direct dependency replaces the version used by another crate.
For a focused regression workflow:
cargo test --locked lone_quote
cargo test --locked
cargo clippy --all-targets --all-features -- -D warnings
If supporting more than one Hickory release, run the same text-parser regression test against each supported dependency configuration in CI. A useful differential check compares old versus patched behavior for identical input: the affected release demonstrates the panic, while 0.26.2 or later must return a parse error. Keep such a reproducer isolated from production tests if the old version’s panic would otherwise disrupt the test process.
The check should also distinguish text parsing from wire decoding. A wire-decoding test is not a substitute for the text regression, because the advisory explicitly says wire-format records do not take the vulnerable path. For broader parser assurance, place the malformed fixture alongside valid quoted, unquoted (if allowed), empty, and mismatched-quote cases. See Advanced Unit Testing and Debugging in Rust for test-structure techniques, and Effective End-to-End Testing in Rust for exercising real application boundaries.
Trade-offs and coverage
The fix adds a small validation branch on a text-parsing path. It does not change the asymptotic cost of parsing and does not require allocating a new string when values are borrowed as slices. The table compares the relevant behaviors; timing varies by machine and benchmark setup, so it is more useful to state the operation and guarantee than to imply a universal nanosecond result.
| Approach | Work per parameter | Allocation for quote removal | Lone-quote result | Security outcome |
|---|---|---|---|---|
Vulnerable starts/ends check plus [1..len-1] | O(1) check | 0 | Panic: [1..0] | Malformed text can cause denial of service |
| Length guard before slicing | O(1) check | 0 | Parse error | Prevents this invalid-range panic |
strip_prefix / strip_suffix | O(1) checks | 0 | Parse error | Avoids manual range arithmetic |
Upgrade to patched hickory-proto 0.26.2+ | O(1) validation in parser | No extra quote-removal allocation required | Parse error | Uses the advisory’s upstream fix |
Do not remove the guard solely because inputs are “normally trusted.” Zone files and record text are often loaded from deployment pipelines, tenant configuration, APIs, or operational tooling; trust boundaries can change over time. If untrusted text is accepted, enforce resource limits separately as well: this fix addresses a panic, not oversized-record or general parser resource exhaustion.
Production pitfalls
- Parsing entry points differ. Verify the code path actually used by your service. A DNS message decoder and a zone-file parser can accept the same conceptual record through different implementations.
- Malformed quotes are not all equivalent. The lone quote is the reported trigger. Tests should also cover a missing closing quote, a missing opening quote, an empty quoted value (
""), and a normal value, according to the grammar your parser supports. - Keep errors structured. Return the parser’s normal error type, not a panic, silent fallback, or generic success. Include enough context to identify the parameter without echoing unsafe or excessive input.
- Check all resolved dependency paths. Workspaces and transitive dependencies can resolve differently from a developer’s single-crate build. Use
--lockedin CI and deploy the tested lockfile. - Do not confuse a regression test with full parser safety. This advisory concerns one precise panic. It does not establish that every malformed SVCB/HTTPS parameter or every text parser is safe.
Frequently Asked Questions (FAQ)
Which hickory-proto versions are affected by RUSTSEC-2026-0489?
The advisory lists hickory-proto versions 0.20.1 through 0.26.1 as affected, versions below 0.20.1 as unaffected, and 0.26.2 as patched. Confirm the dependency actually resolved in your build with cargo tree -i hickory-proto; transitive dependencies may select the version your application uses.
Does CVE-2026-123573 affect DNS wire-format decoding?
No. The advisory attributes the panic to parsing SVCB or HTTPS records from text, where surrounding quotes are removed from parameter values. It states that records decoded from DNS wire format do not use this path.
What input triggers the SVCB or HTTPS parser panic?
A service parameter with a value consisting of one double quote, such as alpn=", passes the starts-with and ends-with checks. The parser then attempts the invalid string slice [1..0], which panics instead of reporting malformed input.