Error prone toUint8Array method
See original GitHub issueI’ve faced that toUint8Array
method treats input as ASCII string: https://github.com/MasterKale/SimpleWebAuthn/blob/bc9ad0f68fc49c4ac23cd22428248faa26d3f9b6/packages/browser/src/helpers/toUint8Array.ts#L6
It is impossible to change transformation of challenge
on the client.
- Attestation https://github.com/MasterKale/SimpleWebAuthn/blob/bc9ad0f68fc49c4ac23cd22428248faa26d3f9b6/packages/browser/src/methods/startAttestation.ts#L27
- Assertion https://github.com/MasterKale/SimpleWebAuthn/blob/bc9ad0f68fc49c4ac23cd22428248faa26d3f9b6/packages/browser/src/methods/startAssertion.ts#L27
Whats wrong?
First: Challenge verification will fail if challenge string contains non ASCII character. For example: abcж
yep, ж
occupy 2 bytes.
const value = 'abcж';
const array = Uint8Array.from(value, c => c.charCodeAt(0));
const string = String.fromCharCode.apply(null, array);
/// 'abcж' !== 'abc6'
value !== string
Second: user may want to transfer challenge from server in different format:
- ASCII string - current assumption
- HEX string - I prefer this format
- OCTET string
- base64 or base64url strings
- and so on
So it would be better to allow user configure challenge encoding or move conversion and appropriate helper(s) to userland instead hard coded into the lib.
Issue Analytics
- State:
- Created 3 years ago
- Comments:28 (16 by maintainers)
Top Results From Across the Web
JS: Type not convertible to Uint8Array · Issue #97 - GitHub
I'm creating a Uint8Array but protobuf errors because the Uint8Array ... The only way I have found so far to deserialize a buffer...
Read more >Uint8Array - JavaScript - MDN Web Docs
Chrome Edge
Uint8Array Full support. Chrome7. Toggle history Full support. Edge12...
Uint8Array() constructor Full support. Chrome7. Toggle history Full support. Edge12...
Constructor without parameters Full support....
Read more >How to convert uint8 Array to base64 Encoded String?
I tried to use that in a Word Web AddIn with Edge and got an error 'TextDecoder' is not defined. Fortunately I needed...
Read more >Buffer | Node.js v19.3.0 Documentation
The Buffer class is a subclass of JavaScript's Uint8Array class and extends it with methods that cover additional use cases. Node.js APIs accept...
Read more >StringView - Archive of obsolete content
method to read the bytes from the data buffer. However, this is slow and error-prone, due to the need for multiple conversions (especially...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
PR #42 has been merged in with a fix for this issue. It is available in the newly released v0.8.0.
@mahnunchik #42 is the PR containing my tentative solution to this issue. Fortunately it’s not as breaking a change as I described earlier, and more importantly it manages a variety of values for
challenge
includingascii
strings,utf-8
strings, andcrypto.randomBytes(64)
.And for good measure I hand-checked the values being passed to authenticators by
startAttestation()
/startAssertion()
to confirm that they were the actual strings/buffers I was passing in aschallenge
togenerateAttesationOptions()
andgenerateAssertionOptions()
respectively.