"WebAuthn:AddCredential" doesn't fail with "invalid argument" when "isResidentCredential == true" and "userHandle" is not specified
Categories
(Remote Protocol :: Marionette, defect, P3)
Tracking
(Not tracked)
People
(Reporter: whimboo, Assigned: mfarrell)
References
(Blocks 1 open bug)
Details
(Whiteboard: [webdriver:backlog])
Attachments
(1 external file)
Based on https://github.com/web-platform-tests/wpt/issues/61546 the WebAuthn:AddCredential command needs to fail with invalid argument when "isResidentCredential == true" and "userHandle" is not specified. A test was added upstream and synced via bug 2059909.
| Reporter | ||
Comment 1•3 months ago
|
||
Hi John, regarding this change is it just an extra check that we should do or if not done should platform code actually fail under such a condition?
| Reporter | ||
Updated•3 months ago
|
Updated•2 months ago
|
| Assignee | ||
Comment 2•2 months ago
|
||
(In reply to Henrik Skupin [:whimboo][⌚️UTC+2] from comment #1)
Hi John, regarding this change is it just an extra check that we should do or if not done should platform code actually fail under such a condition?
This only affects the test virtual authenticator; such a credential wouldn't actually work with a real authenticator.
It's not clear to me what the current state of the test is, besides "failed"... "failed" how? That it works? Or the error is wrong? :)
This needs an extra check, probably before this line: https://searchfox.org/firefox-main/rev/f9a73919fe039381777330403e5f94918735a5e7/dom/webauthn/authrs_bridge/src/lib.rs#1490
Like:
if is_resident_credential && user_handle.is_empty() {
return Err(NS_ERROR_INVALID_ARG);
}
| Assignee | ||
Comment 3•1 month ago
|
||
| Assignee | ||
Updated•1 month ago
|
| Assignee | ||
Comment 4•1 month ago
|
||
I started writing a patch, and I think there may be more to this:
[task 2026-09-24T03:20:21.329+00:00] 03:20:21 INFO - TEST-UNEXPECTED-FAIL | /webdriver/tests/classic/external/webauthn/add_credential/invalid.py | test_user_handle_missing_for_resident_credential - assert 500 == 400
[task 2026-09-24T03:20:21.329+00:00] 03:20:21 INFO - session = <Session 4172a1d9-eab4-4bb6-8c54-c254362b30c0>
[task 2026-09-24T03:20:21.329+00:00] 03:20:21 INFO - authenticator = 'No4qzDnKhXMgCtGTGjyOsDQuMBc5HDz1YcaDlO-QtFw'
[task 2026-09-24T03:20:21.329+00:00] 03:20:21 INFO -
[task 2026-09-24T03:20:21.329+00:00] 03:20:21 INFO - def test_user_handle_missing_for_resident_credential(session, authenticator):
[task 2026-09-24T03:20:21.329+00:00] 03:20:21 INFO - credential = create_credential(is_resident_credential=True)
[task 2026-09-24T03:20:21.329+00:00] 03:20:21 INFO - assert "userHandle" not in credential
[task 2026-09-24T03:20:21.329+00:00] 03:20:21 INFO - response = add_credential(session, authenticator, credential)
[task 2026-09-24T03:20:21.329+00:00] 03:20:21 INFO - > assert_error(response, "invalid argument")
[task 2026-09-24T03:20:21.329+00:00] 03:20:21 INFO -
[task 2026-09-24T03:20:21.329+00:00] 03:20:21 INFO - authenticator = 'No4qzDnKhXMgCtGTGjyOsDQuMBc5HDz1YcaDlO-QtFw'
[task 2026-09-24T03:20:21.329+00:00] 03:20:21 INFO - credential = {'credentialId': 'Y3JlZC0x',
[task 2026-09-24T03:20:21.329+00:00] 03:20:21 INFO - 'isResidentCredential': True,
[task 2026-09-24T03:20:21.329+00:00] 03:20:21 INFO - 'privateKey': 'MIGHAgEAMBMGByqGSM49AgEGCCqGSM49AwEHBG0wawIBAQQg8_zMDQDYAxlU-Qhk1Dwkf0v18GZca1DMF3SaJ9HPdmShRANCAASNYX5lyVCOZLzFZzrIKmeZ2jwURmgsJYxGP__fWN_S-j5sN4tT15XEpN_7QZnt14YvI6uvAgO0uJEboFaZlOEB',
[task 2026-09-24T03:20:21.329+00:00] 03:20:21 INFO - 'rpId': 'example.com',
[task 2026-09-24T03:20:21.329+00:00] 03:20:21 INFO - 'signCount': 0}
[task 2026-09-24T03:20:21.329+00:00] 03:20:21 INFO - response = <Response status=500 error=<UnknownErrorException http_status=500>>
[task 2026-09-24T03:20:21.329+00:00] 03:20:21 INFO - session = <Session 4172a1d9-eab4-4bb6-8c54-c254362b30c0>
...
[task 2026-09-24T03:20:23.780+00:00] 03:20:23 INFO - PID 1558 | Marionette threw an error: [Exception... "Component returned failure code: 0x80070057 (NS_ERROR_ILLEGAL_VALUE) [nsIWebAuthnService.addCredential]" nsresult: "0x80070057 (NS_ERROR_ILLEGAL_VALUE)" location: "JS frame :: chrome://remote/content/marionette/webauthn.sys.mjs :: webauthn.addCredential :: line 82" data: no]
[task 2026-09-24T03:20:23.780+00:00] 03:20:23 INFO - PID 1558 | webauthn.addCredential@chrome://remote/content/marionette/webauthn.sys.mjs:82:24
[task 2026-09-24T03:20:23.781+00:00] 03:20:23 INFO - PID 1558 | webAuthn_addCredential@chrome://remote/content/marionette/driver.sys.mjs:4095:19
[task 2026-09-24T03:20:23.782+00:00] 03:20:23 INFO - PID 1558 | dispatch@chrome://remote/content/marionette/server.sys.mjs:317:49
[task 2026-09-24T03:20:23.782+00:00] 03:20:23 INFO - PID 1558 | execute@chrome://remote/content/marionette/server.sys.mjs:289:16
[task 2026-09-24T03:20:23.783+00:00] 03:20:23 INFO - PID 1558 | onPacket/<@chrome://remote/content/marionette/server.sys.mjs:262:20
[task 2026-09-24T03:20:23.784+00:00] 03:20:23 INFO - PID 1558 | onPacket@chrome://remote/content/marionette/server.sys.mjs:263:9
[task 2026-09-24T03:20:23.784+00:00] 03:20:23 INFO - PID 1558 | _onJSONObjectReady/<@chrome://remote/content/marionette/transport.sys.mjs:493:20
I suspect that userHandle is required due to the way it is passed across the XPCOM boundary.
| Assignee | ||
Comment 5•1 month ago
|
||
I made userHandle an [optional] in ACString, and the Rust bindings use Option<&nsACString>, but the missing userHandle still gets turned into Some("") on the other side of the XPCOM boundary.
Also, even with the fix (shown in the log above), Marionette doesn't know how to handle the NS_ERROR_ILLEGAL_VALUE / NS_ERROR_INVALID_ARG error thrown on the other side of the XPCOM boundary (where all the argument validation happens). So this gets turned into UnknownError, but this test expects InvalidArgumentError.
| Reporter | ||
Comment 6•1 month ago
|
||
(In reply to Michael Farrell [:mfarrell] from comment #5)
Also, even with the fix (shown in the log above), Marionette doesn't know how to handle the
NS_ERROR_ILLEGAL_VALUE/NS_ERROR_INVALID_ARGerror thrown on the other side of the XPCOM boundary (where all the argument validation happens). So this gets turned intoUnknownError, but this test expectsInvalidArgumentError.
Yes, this is because its a XPCOM error that we would have to catch when calling WebAuthn APIs in Gecko. We should put try/catch statements around those calls and in case of a InvalidArgumentError we should re-throw as InvalidArgumentError. I think that we can do that in https://searchfox.org/firefox-main/source/remote/marionette/webauthn.sys.mjs. Only one caveat is that we do not know the exact underlying reason for a proper error message. So if we could do some validation upfront before calling the API like these assertions it would work better.
Updated•1 month ago
|
| Assignee | ||
Comment 7•1 month ago
|
||
I got most of the way to a fix for this, but I've hit some issues that will make fixing this more complicated.
(In reply to Michael Farrell [:mfarrell] from comment #5)
I made
userHandlean[optional] in ACString, and the Rust bindings useOption<&nsACString>, but the missinguserHandlestill gets turned intoSome("")on the other side of the XPCOM boundary.
Answering my own question, the reason for this is Bug 665409 / Bug 1659200 - when an argument is not specified, XPCOM treats it as the default value.
This is a problem, because userHandle = null is handled differently to userHandle = "".
When making userHandle [optional], I swapped it with signCount (per convention to put [optional] arguments last). However, WebAuthn-3 changes how signCount = null is handled (Bug 2066804), so that should be [optional] too. In WebAuthn-2, it was:
Associate a signature counter counter to the credential with a starting value equal to the parameters’ signCount or 0 if signCount is null.
In the current WebAuthn-3 draft, it is now:
Otherwise, if signCount is null, do not associate a signature counter to the credential.
So having XPCOM coerce that to 0 is going to be a problem too!
I think that the better way option may be to make addCredential take a nsICredentialParameters, and make its nullable fields nsIVariant or jsval.
| Reporter | ||
Comment 8•1 month ago
|
||
Alternatively we could catch such a situation for now by asserting already in our WebDriver implementation and raise that invalid argument error, then a follow-up could update it afterward.
| Assignee | ||
Comment 9•1 month ago
|
||
(In reply to Henrik Skupin [:whimboo][⌚️UTC+2] from comment #6)
Yes, this is because its a XPCOM error that we would have to catch when calling WebAuthn APIs in Gecko. We should put try/catch statements around those calls and in case of a
InvalidArgumentErrorwe should re-throw asInvalidArgumentError.
Thanks! I've done this in https://phabricator.services.mozilla.com/D328714.
| Assignee | ||
Updated•1 month ago
|
Description
•