Skip to content

Commit

Permalink
Handle overlong icon values
Browse files Browse the repository at this point in the history
We skip the icon field during deserialization if it is too long.
Previously, we directly tried to deserialize a String<N> and ignored any
errors.  This means that we also ignored any other errors, e. g. for
invalid data types.

This patch changes the implementation to first deserialize a string
slice and handle errors occuring during the deserialization.  Then we
check if the string slice fits into String<N> or if we should ignore the
value.
  • Loading branch information
robin-nitrokey committed Feb 22, 2024
1 parent 084db87 commit 885bceb
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 2 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- Remove `AuthenticatorDataFlags::EMPTY` (use `AuthenticatorDataFlags::empty()` instead)
- Allow missing algorithms in COSE keys ([#8][])
- Remove unused `REALISTIC_MAX_MESSAGE_SIZE` constant
- Handle overlong `icon` values in `PublicKeyCredentialUserEntity` ([#27][])

[#8]: https://github.com/trussed-dev/ctap-types/pull/8
[#9]: https://github.com/solokeys/ctap-types/issues/9
Expand All @@ -24,6 +25,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
[#16]: https://github.com/trussed-dev/ctap-types/pull/16
[#17]: https://github.com/trussed-dev/ctap-types/pull/17
[#18]: https://github.com/trussed-dev/ctap-types/pull/18
[#27]: https://github.com/trussed-dev/ctap-types/pull/27

## [0.1.2] - 2022-03-07

Expand Down
6 changes: 4 additions & 2 deletions src/webauthn.rs
Original file line number Diff line number Diff line change
Expand Up @@ -71,8 +71,10 @@ fn deserialize_from_str_and_skip_if_too_long<'de, D, const L: usize>(
where
D: serde::Deserializer<'de>,
{
let result: Result<String<L>, D::Error> = serde::Deserialize::deserialize(deserializer);
match result {
let s: &'de str = Deserialize::deserialize(deserializer)?;
// String::from(s) could panic and is not really infallibe. It is removed in heapless 0.8.
#[allow(clippy::unnecessary_fallible_conversions)]
match String::try_from(s) {
Ok(string) => Ok(Some(string)),
Err(_err) => {
info_now!("skipping field: {:?}", _err);
Expand Down

0 comments on commit 885bceb

Please sign in to comment.