Open Bug 2064129 Opened 3 months ago Updated 1 month ago

"WebAuthn:AddCredential" doesn't fail with "invalid argument" when "isResidentCredential == true" and "userHandle" is not specified

Categories

(Remote Protocol :: Marionette, defect, P3)

defect

Tracking

(Not tracked)

ASSIGNED

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.

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?

Flags: needinfo?(jschanck)
Mentor: hskupin
Priority: -- → P3
Whiteboard: [webdriver:backlog][lang=js]
Flags: needinfo?(jschanck) → needinfo?(micolous+moz)

(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);
}
Severity: -- → S4
Flags: needinfo?(micolous+moz)
Assignee: nobody → micolous+moz
Status: NEW → ASSIGNED

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.

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.

(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_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.

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.

Mentor: hskupin
Whiteboard: [webdriver:backlog][lang=js] → [webdriver:backlog]
Attachment #9647742 - Attachment description: WIP: Bug 2064129: Make `WebAuthn:AddCredential` return "invalid argument" for resident credential without a user handle r=jschanck → WIP: Bug 2064129: Re-throw XPCOM errors from `nsIWebAuthnService` as WebDriver errors r=jschanck

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 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.

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.

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.

(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 InvalidArgumentError we should re-throw as InvalidArgumentError.

Thanks! I've done this in https://phabricator.services.mozilla.com/D328714.

You need to log in before you can comment on or make changes to this bug.

Attachment

General

Created:
Updated:
Size: