Skip to content

Commit dc3ffda

Browse files
authored
Fix, follow spec, response.userHandle allow null (#114)
* userhandle allow null * fix lint trailing comma
1 parent adaab4d commit dc3ffda

File tree

3 files changed

+30
-3
lines changed

3 files changed

+30
-3
lines changed

lib/parser.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -371,7 +371,7 @@ async function parseAuthnrAssertionResponse(msg) {
371371
}
372372

373373
let userHandle;
374-
if (msg.response.userHandle !== undefined) {
374+
if (msg.response.userHandle !== undefined && msg.response.userHandle !== null) {
375375
userHandle = coerceToArrayBuffer(msg.response.userHandle, "response.userHandle");
376376
if (userHandle.byteLength === 0) {
377377
userHandle = undefined;

lib/validator.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -220,7 +220,7 @@ function validateAssertionResponse() {
220220

221221
if (typeof req.response.userHandle !== "string" &&
222222
!(req.response.userHandle instanceof ArrayBuffer) &&
223-
req.response.userHandle !== undefined) {
223+
req.response.userHandle !== undefined && req.response.userHandle !== null) {
224224
throw new TypeError("expected 'response.userHandle' to be base64 String, ArrayBuffer, or undefined");
225225
}
226226

test/main.test.js

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -687,7 +687,34 @@ describe("Fido2Lib", function() {
687687
clientDataJSON: h.lib.assertionResponse.response.clientDataJSON,
688688
authenticatorData: h.lib.assertionResponse.response.authenticatorData,
689689
signature: h.lib.assertionResponse.response.signature,
690-
// userHandle: h.lib.assertionResponse.response.userHandle
690+
},
691+
};
692+
693+
return serv.assertionResult(assertionResponse, expectations).then(
694+
(res) => {
695+
assert.instanceOf(res, Fido2AssertionResult);
696+
return res;
697+
},
698+
);
699+
});
700+
701+
it("valid assertion with null userHandle", function() {
702+
const expectations = {
703+
challenge: "eaTyUNnyPDDdK8SNEgTEUvz1Q8dylkjjTimYd5X7QAo-F8_Z1lsJi3BilUpFZHkICNDWY8r9ivnTgW7-XZC3qQ",
704+
origin: "https://localhost:8443",
705+
factor: "either",
706+
publicKey: h.lib.assnPublicKey,
707+
prevCounter: 362,
708+
userHandle: null,
709+
};
710+
711+
const assertionResponse = {
712+
rawId: h.lib.assertionResponse.rawId,
713+
response: {
714+
clientDataJSON: h.lib.assertionResponse.response.clientDataJSON,
715+
authenticatorData: h.lib.assertionResponse.response.authenticatorData,
716+
signature: h.lib.assertionResponse.response.signature,
717+
userHandle: null,
691718
},
692719
};
693720

0 commit comments

Comments
 (0)