Closed H3RSKO closed 1 year ago
Figured out the issue.
I'm using postgres, and when storing the raw credentialPublicKey
Uint8Array as a BYTEA, it get's modified. Pulling it from the db as a buffer and then converting back to a Uint8Array for verification will result in a different (much larger) Uint8Array.
The fix is the make sure to convert the Uint8Array to a buffer before saving it to the db. This will maintain the Uint8Array's integrity throughout the flow.
Hope this helps anyone else who may encounter this issue.
...when storing the raw
credentialPublicKey
Uint8Array as a BYTEA...
@H3RSKO I'm glad you were able to figure this out. Is there bad advice in the comments of the data structures I lay out in the docs for RP's to define in their DB?
// SQL: Store raw bytes as `BYTEA`/`BLOB`/etc...
credentialPublicKey: Uint8Array;
https://simplewebauthn.dev/docs/packages/server#additional-data-structures
If so, I'd welcome suggestions for improvement here. I don't want to continue steering people into a common problem with my recommendations if this is bad advice.
@MasterKale Yeah, I think we just need to be clear about how the datatypes need to be modified based on where we are using them in the flow. For example the credentialPublicKey
is going through the following changes:
Verified as a Uint8Array.
In my specific case, Uint8Array > BYTEA was changing the Uint8Array, but Uint8Array > Buffer > BYTEA worked.
Also, another issue I ran into that others have encountered is that even though we are storing credentialID
as a base64Url, generateAuthenticationOptions
requires it to be a buffer, and then converts it back to a base64Url
. If it is passed in as a base64Url it will return the authenticator with and empty id
field.
Maybe update generateAuthenticationOptions
to something like this so it works for both base64url and buffer.
allowCredentials: allowCredentials?.map((cred) => ({
...cred,
id: typeof(cred.id !== 'string') ? index_js_1.isoBase64URL.fromBuffer(cred.id) : cred.id,
})),
If you like i can put together a PR on the docs for those datatype issues, not sure what you want to do with the generateAuthenticationOptions
one.
was running into same issue until I realized the library I'm using stores blob data as Buffer type, so when I stored I changed to Buffer.from(publicKey)
Describe the issue
When trying to verify an authenticator with
verifyAuthenticationResponse
, i'm gettingTypeError: cosePublicKey.get is not a function
.Stack trace:
Reproduction Steps
The registration flow works as expected, but I cannot complete the final
verifyAuthenticationResponse
step.This is the data i am passing into
verifyAuthenticationResponse
:The parsed credentials from the
startRegistration()
JSON output.Additionally, I occasionally run into this error, I assume it is connected.
RangeError: Offset is outside the bounds of the DataView
Expected behavior
It should correctly verify the passkey.
Code Samples + WebAuthn Options and Responses
Dependencies
SimpleWebAuthn Libraries
Additional context
Thank you!