Skip to content

fix(ads-client): panic on a malformed OHTTP preflight response - #7578

Merged
Almaju merged 1 commit into
mozilla:mainfrom
Almaju:ads-client-ordering-pass
Sep 22, 2026
Merged

Almaju merged 1 commit into
mozilla:mainfrom
Almaju:ads-client-ordering-pass

Conversation

@Almaju

@Almaju Almaju commented Sep 3, 2026 •

Copy link
Copy Markdown
Contributor

From<PreflightResponse> for Headers called .expect() on geo_location and normalized_ua, both echoed from the MARS /v1/ads-preflight response body. Header values must be printable ASCII, so a non-ASCII geo location or a CRLF panicked in the caller's process instead of failing the request — on every OHTTP ad request and click/impression/report callback.

Pull Request checklist

  • Breaking changes: none. From → TryFrom is on a private mars::preflight type; no binding API change.
  • Quality: fmt and clippy --all-targets clean, 105 unit tests pass.
  • Tests: four new in mars::preflight — happy path, empty UA, non-ASCII geo, CRLF injection.
  • Changelog: entry under ### Ads-Client in v158.0.
  • Dependencies: none added.

@Almaju
Almaju marked this pull request as ready for review September 3, 2026 03:19
@Almaju
Almaju requested a review from a team as a code owner September 3, 2026 03:19
@Almaju
Almaju requested review from mashalifshin and removed request for a team September 3, 2026 03:19
@Almaju
Almaju force-pushed the ads-client-ordering-pass branch from b9d71e2 to e9dfadc Compare September 21, 2026 23:33
@Almaju Almaju changed the title ads-client: alphabetical ordering pass + fix an OHTTP preflight panic fix(ads-client): panic on a malformed OHTTP preflight response Sep 21, 2026
…esponse

`From<PreflightResponse> for Headers` used `.expect("valid header")` on
`geo_location` and `normalized_ua`, both echoed verbatim out of the MARS
`/v1/ads-preflight` response body. `Headers::insert` rejects any value that
is not printable ASCII, so a preflight response carrying a non-ASCII geo
location — or CRLF — panicked inside the caller's process instead of
failing the request. Every OHTTP ad request and OHTTP click/impression/report
callback goes through this conversion.

It is now `TryFrom<PreflightResponse> for Headers` with
`Error = viaduct::ViaductError`. Both call sites in `MARSClient` already
return an error type that converts from `ViaductError` (`FetchAdsError` and
`CallbackRequestError`), so the failure propagates with `?` and surfaces to
the caller as a request error. Four unit tests cover the happy path, the
omitted-empty-UA path, non-ASCII, and CRLF injection.

The remaining `unwrap`/`expect`/`panic!` sites in this component were
audited at the same time. Three are `#[cfg(test)]`-gated and one — the
`path_segments_mut()` call in `Environment::into_url` — cannot fail because
every `base_url()` arm is an `https` URL, which `url` guarantees is
hierarchical. Only that last one is non-obvious from the code, so only it
gets a comment; no other code changes.
@Almaju
Almaju force-pushed the ads-client-ordering-pass branch from e9dfadc to be6a4df Compare September 21, 2026 23:38
@Almaju
Almaju added this pull request to the merge queue Sep 22, 2026
Merged via the queue into mozilla:main with commit ffdbb2b Sep 22, 2026
15 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