fix(webauthn): escape clientDataJSON strings per CCDToString#196
Open
AlfioEmanueleFresta wants to merge 1 commit into
Open
fix(webauthn): escape clientDataJSON strings per CCDToString#196AlfioEmanueleFresta wants to merge 1 commit into
AlfioEmanueleFresta wants to merge 1 commit into
Conversation
7faa08f to
c57ce4f
Compare
ClientData::to_json hand-rolled a JSON object with format!(), concatenating the origin and topOrigin strings unescaped. An origin containing a double quote, backslash, or U+0000-U+001F produced malformed JSON, and a hostile origin like 'https://example.com","origin":"https://attacker.com' yielded a document with two 'origin' keys. WebAuthn L3 §5.8.1.2 requires strings be encoded via CCDToString, which is a strict subset of RFC 8259 string-escape rules. Route serialization through a serde-derived struct that mirrors the spec field order (type, challenge, origin, topOrigin?, crossOrigin) so serde_json applies the correct escapes. Add regression tests covering hostile origins and topOrigins (double quote, backslash, control characters), spec-conformant field ordering with and without topOrigin, and a full round-trip.
de3d393 to
2fbfa63
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.
WebAuthn L3 §5.8.1.2 specifies that
clientDataJSONstrings must be escaped viaCCDToString(a strict subset of ECMA-262 / RFC 8259 string-escape rules).ClientData::to_jsoncurrently hand-rolls a JSON object viaformat!(), concatenating theoriginandtopOriginstrings unescaped, which produces malformed or attacker-injectable JSON when those strings contain",\, or U+0000-U+001F.Empirical repro on the base branch: setting
origintohttps://example.com","origin":"https://attacker.comyields a document with twooriginkeys.Stacked on top of #190 (which is stacked on #188 / #186). The
RequestOriginplumbing introduced by #188 already correctly populatesClientData::originandClientData::top_originfrom the URL origin; that work is preserved unchanged here.Changes
format!()inClientData::to_jsonwith a#[derive(Serialize)]wire struct that mirrors the spec field order (type,challenge,origin,topOrigin?,crossOrigin).serde_json's RFC 8259 string encoder is a strict superset ofCCDToString.topOriginis omitted from the output entirely when absent (viaskip_serializing_if), preserving the existing behaviour.", origin containing\, origin containing U+0000-U+001F control characters, hostiletopOrigin, spec field order with and withouttopOrigin, and a full round-trip.Test plan
cargo buildcargo test --lib(159 passed, including 11 inclient_data::tests)cargo fmt --checkcargo clippy --lib --all-features --no-deps -- -D warningsRefs: WebAuthn L3 §5.8.1.2 (
CCDToString); audit dossiers D-01, D-02, D-04, B-10, H-04, H-05.