Skip to content

Commit 800d0c5

Browse files
committed
Don't fail on authenticatorAttachment in PublicKeyCredential JSON
1 parent 4e33a96 commit 800d0c5

File tree

3 files changed

+50
-0
lines changed

3 files changed

+50
-0
lines changed

NEWS

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,11 @@
1+
== Version 1.12.3 (unreleased) ==
2+
3+
Fixes:
4+
5+
* Fixed `PublicKeyCredential` failing to parse from JSON if an
6+
`"authenticatorAttachment"` attribute was present.
7+
8+
19
== Version 1.12.2 ==
210

311
Fixes:

webauthn-server-core/src/main/java/com/yubico/webauthn/data/PublicKeyCredential.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
package com.yubico.webauthn.data;
2626

2727
import com.fasterxml.jackson.annotation.JsonCreator;
28+
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
2829
import com.fasterxml.jackson.annotation.JsonProperty;
2930
import com.fasterxml.jackson.core.type.TypeReference;
3031
import com.yubico.internal.util.JacksonCodecs;
@@ -45,6 +46,7 @@
4546
*/
4647
@Value
4748
@Builder(toBuilder = true)
49+
@JsonIgnoreProperties({"authenticatorAttachment"})
4850
public class PublicKeyCredential<
4951
A extends AuthenticatorResponse, B extends ClientExtensionOutputs> {
5052

webauthn-server-core/src/test/scala/com/yubico/webauthn/data/JsonIoSpec.scala

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,8 @@ import com.yubico.webauthn.extension.appid.AppId
4747
import com.yubico.webauthn.extension.appid.Generators._
4848
import org.junit.runner.RunWith
4949
import org.scalacheck.Arbitrary
50+
import org.scalacheck.Arbitrary.arbitrary
51+
import org.scalacheck.Gen
5052
import org.scalatest.FunSpec
5153
import org.scalatest.Matchers
5254
import org.scalatestplus.junit.JUnitRunner
@@ -362,6 +364,44 @@ class JsonIoSpec
362364
]]() {}
363365
)
364366
}
367+
368+
it("allows and ignores an authenticatorAttachment attribute.") {
369+
def test[P <: PublicKeyCredential[_, _]](tpe: TypeReference[P])(implicit
370+
a: Arbitrary[P]
371+
): Unit = {
372+
forAll(
373+
a.arbitrary,
374+
Gen.oneOf(
375+
arbitrary[AuthenticatorAttachment].map(_.toJsonString),
376+
arbitrary[String],
377+
),
378+
) { (value: P, authenticatorAttachment: String) =>
379+
val tree: ObjectNode = json.valueToTree(value)
380+
tree.set(
381+
"authenticatorAttachment",
382+
new TextNode(authenticatorAttachment),
383+
)
384+
val encoded = json.writeValueAsString(tree)
385+
println(authenticatorAttachment)
386+
val decoded = json.readValue(encoded, tpe)
387+
388+
decoded should equal(value)
389+
}
390+
}
391+
392+
test(
393+
new TypeReference[PublicKeyCredential[
394+
AuthenticatorAssertionResponse,
395+
ClientAssertionExtensionOutputs,
396+
]]() {}
397+
)
398+
test(
399+
new TypeReference[PublicKeyCredential[
400+
AuthenticatorAttestationResponse,
401+
ClientRegistrationExtensionOutputs,
402+
]]() {}
403+
)
404+
}
365405
}
366406

367407
describe("The class PublicKeyCredentialCreationOptions") {

0 commit comments

Comments
 (0)