Commit 17e91f6
authored
## Motivation
Closes #185.
`WebAuthnIDL::from_json` currently takes a `&RelyingPartyId`, which
forces callers (e.g. credentialsd) to override `request.origin` and
`request.cross_origin` after parsing because the bare host is not a
valid origin string and we have no place to record the top-level origin.
This replaces that parameter with a `RequestOrigin` that carries the
actual origin context, so the parsed request comes out correct without a
post-parse fixup.
## What changes
- New `Origin` and `RequestOrigin` types in
`libwebauthn::ops::webauthn`. `Origin` is a struct with `host:
OriginHost` and `port: Option<u16>`; `RequestOrigin` wraps it with an
optional `top_origin`. Convenience constructors:
`RequestOrigin::new(origin)`, `RequestOrigin::new_cross_origin(origin,
top_origin)`, `RequestOrigin::try_from(&str | String)` for one-shot
parsing of `"https://host[:port]"`.
- Host validation goes through `url::Host` so we follow the WHATWG URL
Standard host parser (domain / IPv4 / bracketed IPv6). Errors are
wrapped into a local `HostParseError` / `OriginParseError` so the `url`
crate's error type does not leak into the public API.
- `WebAuthnIDL::from_json` and `FromIdlModel::from_idl_model` now take
`&RequestOrigin`. The parsed `request.origin` is the full URL string
(`"https://example.org"`, no longer the bare host), and
`request.top_origin: Option<String>` replaces the old `cross_origin:
Option<bool>`.
- `ClientData` drops `cross_origin: Option<bool>` and derives
`crossOrigin` in the JSON from `top_origin.is_some()`. `topOrigin` is
now emitted when present.
- Bumps libwebauthn to `0.4.0` since the public `from_json` signature
and the request struct fields are breaking changes.
## Intentional non-changes
- `Origin` is a plain struct, not an enum. We only support `https`. If
we need to support a second scheme later it can become an enum without
breaking call-site field access.
- `rp.id` validation against the origin is still strict equality. The
spec actually wants a registrable-suffix check (WebAuthn L3 §5.1.3 /
§5.1.7); that is tracked separately in #187 and can build on the PSL
helpers from #173.
## Test plan
- [x] `cargo build -p libwebauthn` and `cargo build -p libwebauthn
--features virt`
- [x] `cargo build --workspace --all-targets --all-features`
- [x] `cargo fmt --all -- --check`
- [x] `cargo clippy --workspace --all-targets --all-features -- -D
warnings`
- [x] `cargo test --workspace` (149 tests, 14 new origin parser tests)
- [x] `cargo publish --dry-run -p libwebauthn` (no working-tree hacks)
1 parent a98b730 commit 17e91f6
22 files changed
Lines changed: 681 additions & 132 deletions
File tree
- libwebauthn-tests/tests
- libwebauthn
- examples
- src
- ops
- webauthn
- idl
- proto/ctap2/model
- webauthn
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
40 | 40 | | |
41 | 41 | | |
42 | 42 | | |
43 | | - | |
| 43 | + | |
44 | 44 | | |
45 | 45 | | |
46 | 46 | | |
| |||
66 | 66 | | |
67 | 67 | | |
68 | 68 | | |
69 | | - | |
| 69 | + | |
70 | 70 | | |
71 | 71 | | |
72 | 72 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
49 | 49 | | |
50 | 50 | | |
51 | 51 | | |
52 | | - | |
| 52 | + | |
53 | 53 | | |
54 | 54 | | |
55 | 55 | | |
| |||
71 | 71 | | |
72 | 72 | | |
73 | 73 | | |
74 | | - | |
| 74 | + | |
75 | 75 | | |
76 | 76 | | |
77 | 77 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
116 | 116 | | |
117 | 117 | | |
118 | 118 | | |
119 | | - | |
| 119 | + | |
120 | 120 | | |
121 | 121 | | |
122 | 122 | | |
| |||
175 | 175 | | |
176 | 176 | | |
177 | 177 | | |
178 | | - | |
| 178 | + | |
179 | 179 | | |
180 | 180 | | |
181 | 181 | | |
| |||
494 | 494 | | |
495 | 495 | | |
496 | 496 | | |
497 | | - | |
| 497 | + | |
498 | 498 | | |
499 | 499 | | |
500 | 500 | | |
| |||
561 | 561 | | |
562 | 562 | | |
563 | 563 | | |
564 | | - | |
| 564 | + | |
565 | 565 | | |
566 | 566 | | |
567 | 567 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1 | 1 | | |
2 | 2 | | |
3 | 3 | | |
4 | | - | |
| 4 | + | |
5 | 5 | | |
6 | 6 | | |
7 | 7 | | |
| |||
32 | 32 | | |
33 | 33 | | |
34 | 34 | | |
| 35 | + | |
35 | 36 | | |
36 | 37 | | |
37 | 38 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
149 | 149 | | |
150 | 150 | | |
151 | 151 | | |
152 | | - | |
| 152 | + | |
153 | 153 | | |
154 | 154 | | |
155 | 155 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
130 | 130 | | |
131 | 131 | | |
132 | 132 | | |
133 | | - | |
| 133 | + | |
134 | 134 | | |
135 | 135 | | |
136 | 136 | | |
| |||
170 | 170 | | |
171 | 171 | | |
172 | 172 | | |
173 | | - | |
| 173 | + | |
174 | 174 | | |
175 | 175 | | |
176 | 176 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
109 | 109 | | |
110 | 110 | | |
111 | 111 | | |
112 | | - | |
| 112 | + | |
113 | 113 | | |
114 | 114 | | |
115 | 115 | | |
| |||
149 | 149 | | |
150 | 150 | | |
151 | 151 | | |
152 | | - | |
| 152 | + | |
153 | 153 | | |
154 | 154 | | |
155 | 155 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
121 | 121 | | |
122 | 122 | | |
123 | 123 | | |
124 | | - | |
| 124 | + | |
125 | 125 | | |
126 | 126 | | |
127 | 127 | | |
| |||
160 | 160 | | |
161 | 161 | | |
162 | 162 | | |
163 | | - | |
| 163 | + | |
164 | 164 | | |
165 | 165 | | |
166 | 166 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
8 | 8 | | |
9 | 9 | | |
10 | 10 | | |
11 | | - | |
| 11 | + | |
12 | 12 | | |
13 | 13 | | |
14 | 14 | | |
| |||
79 | 79 | | |
80 | 80 | | |
81 | 81 | | |
82 | | - | |
| 82 | + | |
| 83 | + | |
83 | 84 | | |
84 | 85 | | |
85 | 86 | | |
| |||
105 | 106 | | |
106 | 107 | | |
107 | 108 | | |
108 | | - | |
| 109 | + | |
109 | 110 | | |
110 | 111 | | |
111 | 112 | | |
| |||
157 | 158 | | |
158 | 159 | | |
159 | 160 | | |
160 | | - | |
| 161 | + | |
161 | 162 | | |
162 | 163 | | |
163 | 164 | | |
| |||
0 commit comments