Laragear / WebAuthn

Authenticate users with Passkeys: fingerprints, patterns and biometric data.
MIT License
309 stars 37 forks source link

[2.x] Column not found: 1054 Unknown column 'rawId' in 'where clause' #87

Closed aaronpk closed 5 months ago

aaronpk commented 5 months ago

PHP & Platform

8.3.7 MacOS

Database

MariaDB 11.3.2

Laravel version

11.7.0

Have you done this?

Expectation

I've gone through the README steps in a brand new Laravel install.

I've configured the user provider to eloquent-webauthn as described in the readme:

    'providers' => [
        'users' => [
            'driver' => 'eloquent-webauthn',
            'model' => App\Models\User::class,
            'password_fallback' => false,
        ],
    ],

I ran the install and migrate scripts

php artisan webauthn:install
php artisan migrate

Description

When attempting to log in, I get a database error:

Column not found: 1054 Unknown column 'rawId' in 'where clause'

Looking at my database, I don't see that column on the users table either.

Reproduction

await Webpass.assert("/webauthn/login/options", "/webauthn/login")


### Stack trace & logs

```shell
[2024-05-18 17:50:12] local.ERROR: SQLSTATE[42S22]: Column not found: 1054 Unknown column 'rawId' in 'where clause' (Connection: mysql, SQL: select * from `users` where `id` = QnWxGTtsch2q8KZef5SOl7Z2yYHSVdvhQ_JP7vLH9tk and `rawId` = QnWxGTtsch2q8KZef5SOl7Z2yYHSVdvhQ_JP7vLH9tk and `response` in (SZYN5YgOjGh0NBcPZHZgW4_krrmihjLHmVzzuoMdl2MFAAAAAA, eyJ0eXBlIjoid2ViYXV0aG4uZ2V0IiwiY2hhbGxlbmdlIjoib3JMd21VTVA1VjFQdWo4cXBsVjVDQSIsIm9yaWdpbiI6Imh0dHA6Ly9sb2NhbGhvc3Q6ODAwMCIsImNyb3NzT3JpZ2luIjpmYWxzZX0, MEUCIQDjh1bTeARNmaNiWSmv4jp7EtRsPVfCHala0-PXkYEJNgIgIXsv10E1GwTp410zovTsXxOMVgu9rZXrOQwhu7Co0i4, ��]�G����=�\�Oz{��ۭu) and `type` = public-key limit 1) {"exception":"[object] (Illuminate\\Database\\QueryException(code: 42S22): SQLSTATE[42S22]: Column not found: 1054 Unknown column 'rawId' in 'where clause' (Connection: mysql, SQL: select * from `users` where `id` = QnWxGTtsch2q8KZef5SOl7Z2yYHSVdvhQ_JP7vLH9tk and `rawId` = QnWxGTtsch2q8KZef5SOl7Z2yYHSVdvhQ_JP7vLH9tk and `response` in (SZYN5YgOjGh0NBcPZHZgW4_krrmihjLHmVzzuoMdl2MFAAAAAA, eyJ0eXBlIjoid2ViYXV0aG4uZ2V0IiwiY2hhbGxlbmdlIjoib3JMd21VTVA1VjFQdWo4cXBsVjVDQSIsIm9yaWdpbiI6Imh0dHA6Ly9sb2NhbGhvc3Q6ODAwMCIsImNyb3NzT3JpZ2luIjpmYWxzZX0, MEUCIQDjh1bTeARNmaNiWSmv4jp7EtRsPVfCHala0-PXkYEJNgIgIXsv10E1GwTp410zovTsXxOMVgu9rZXrOQwhu7Co0i4, ��]�G\u001b׍���=�\\�Oz{��ۭu) and `type` = public-key limit 1) at /Users/aaronpk/Code/Laravel/vendor/laravel/framework/src/Illuminate/Database/Connection.php:813)
[stacktrace]
#0 /Users/aaronpk/Code/Laravel/vendor/laravel/framework/src/Illuminate/Database/Connection.php(767): Illuminate\\Database\\Connection->runQueryCallback('select * from `...', Array, Object(Closure))
#1 /Users/aaronpk/Code/Laravel/vendor/laravel/framework/src/Illuminate/Database/Connection.php(398): Illuminate\\Database\\Connection->run('select * from `...', Array, Object(Closure))
#2 /Users/aaronpk/Code/Laravel/vendor/laravel/framework/src/Illuminate/Database/Query/Builder.php(2993): Illuminate\\Database\\Connection->select('select * from `...', Array, true)
#3 /Users/aaronpk/Code/Laravel/vendor/laravel/framework/src/Illuminate/Database/Query/Builder.php(2978): Illuminate\\Database\\Query\\Builder->runSelect()
#4 /Users/aaronpk/Code/Laravel/vendor/laravel/framework/src/Illuminate/Database/Query/Builder.php(3566): Illuminate\\Database\\Query\\Builder->Illuminate\\Database\\Query\\{closure}()
#5 /Users/aaronpk/Code/Laravel/vendor/laravel/framework/src/Illuminate/Database/Query/Builder.php(2977): Illuminate\\Database\\Query\\Builder->onceWithColumns(Array, Object(Closure))
#6 /Users/aaronpk/Code/Laravel/vendor/laravel/framework/src/Illuminate/Database/Eloquent/Builder.php(749): Illuminate\\Database\\Query\\Builder->get(Array)
#7 /Users/aaronpk/Code/Laravel/vendor/laravel/framework/src/Illuminate/Database/Eloquent/Builder.php(731): Illuminate\\Database\\Eloquent\\Builder->getModels(Array)
#8 /Users/aaronpk/Code/Laravel/vendor/laravel/framework/src/Illuminate/Database/Concerns/BuildsQueries.php(335): Illuminate\\Database\\Eloquent\\Builder->get(Array)
#9 /Users/aaronpk/Code/Laravel/vendor/laravel/framework/src/Illuminate/Auth/EloquentUserProvider.php(139): Illuminate\\Database\\Eloquent\\Builder->first()
#10 /Users/aaronpk/Code/Laravel/vendor/laragear/webauthn/src/Auth/WebAuthnUserProvider.php(59): Illuminate\\Auth\\EloquentUserProvider->retrieveByCredentials(Array)
#11 /Users/aaronpk/Code/Laravel/vendor/laravel/framework/src/Illuminate/Auth/SessionGuard.php(393): Laragear\\WebAuthn\\Auth\\WebAuthnUserProvider->retrieveByCredentials(Array)
#12 /Users/aaronpk/Code/Laravel/vendor/laragear/webauthn/src/Http/Requests/AssertedRequest.php(57): Illuminate\\Auth\\SessionGuard->attempt(Array, false)
#13 /Users/aaronpk/Code/Laravel/app/Http/Controllers/WebAuthn/WebAuthnLoginController.php(33): Laragear\\WebAuthn\\Http\\Requests\\AssertedRequest->login()
#14 /Users/aaronpk/Code/Laravel/vendor/laravel/framework/src/Illuminate/Routing/ControllerDispatcher.php(46): App\\Http\\Controllers\\WebAuthn\\WebAuthnLoginController->login(Object(Laragear\\WebAuthn\\Http\\Requests\\AssertedRequest))
#15 /Users/aaronpk/Code/Laravel/vendor/laravel/framework/src/Illuminate/Routing/Route.php(260): Illuminate\\Routing\\ControllerDispatcher->dispatch(Object(Illuminate\\Routing\\Route), Object(App\\Http\\Controllers\\WebAuthn\\WebAuthnLoginController), 'login')
#16 /Users/aaronpk/Code/Laravel/vendor/laravel/framework/src/Illuminate/Routing/Route.php(206): Illuminate\\Routing\\Route->runController()
#17 /Users/aaronpk/Code/Laravel/vendor/laravel/framework/src/Illuminate/Routing/Router.php(806): Illuminate\\Routing\\Route->run()
#18 /Users/aaronpk/Code/Laravel/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(144): Illuminate\\Routing\\Router->Illuminate\\Routing\\{closure}(Object(Illuminate\\Http\\Request))
#19 /Users/aaronpk/Code/Laravel/vendor/laravel/framework/src/Illuminate/Routing/Middleware/SubstituteBindings.php(50): Illuminate\\Pipeline\\Pipeline->Illuminate\\Pipeline\\{closure}(Object(Illuminate\\Http\\Request))
#20 /Users/aaronpk/Code/Laravel/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(183): Illuminate\\Routing\\Middleware\\SubstituteBindings->handle(Object(Illuminate\\Http\\Request), Object(Closure))
#21 /Users/aaronpk/Code/Laravel/vendor/laravel/framework/src/Illuminate/Foundation/Http/Middleware/VerifyCsrfToken.php(88): Illuminate\\Pipeline\\Pipeline->Illuminate\\Pipeline\\{closure}(Object(Illuminate\\Http\\Request))
#22 /Users/aaronpk/Code/Laravel/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(183): Illuminate\\Foundation\\Http\\Middleware\\VerifyCsrfToken->handle(Object(Illuminate\\Http\\Request), Object(Closure))
#23 /Users/aaronpk/Code/Laravel/vendor/laravel/framework/src/Illuminate/View/Middleware/ShareErrorsFromSession.php(49): Illuminate\\Pipeline\\Pipeline->Illuminate\\Pipeline\\{closure}(Object(Illuminate\\Http\\Request))
#24 /Users/aaronpk/Code/Laravel/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(183): Illuminate\\View\\Middleware\\ShareErrorsFromSession->handle(Object(Illuminate\\Http\\Request), Object(Closure))
#25 /Users/aaronpk/Code/Laravel/vendor/laravel/framework/src/Illuminate/Session/Middleware/StartSession.php(121): Illuminate\\Pipeline\\Pipeline->Illuminate\\Pipeline\\{closure}(Object(Illuminate\\Http\\Request))
#26 /Users/aaronpk/Code/Laravel/vendor/laravel/framework/src/Illuminate/Session/Middleware/StartSession.php(64): Illuminate\\Session\\Middleware\\StartSession->handleStatefulRequest(Object(Illuminate\\Http\\Request), Object(Illuminate\\Session\\Store), Object(Closure))
#27 /Users/aaronpk/Code/Laravel/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(183): Illuminate\\Session\\Middleware\\StartSession->handle(Object(Illuminate\\Http\\Request), Object(Closure))
#28 /Users/aaronpk/Code/Laravel/vendor/laravel/framework/src/Illuminate/Cookie/Middleware/AddQueuedCookiesToResponse.php(37): Illuminate\\Pipeline\\Pipeline->Illuminate\\Pipeline\\{closure}(Object(Illuminate\\Http\\Request))
#29 /Users/aaronpk/Code/Laravel/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(183): Illuminate\\Cookie\\Middleware\\AddQueuedCookiesToResponse->handle(Object(Illuminate\\Http\\Request), Object(Closure))
#30 /Users/aaronpk/Code/Laravel/vendor/laravel/framework/src/Illuminate/Cookie/Middleware/EncryptCookies.php(75): Illuminate\\Pipeline\\Pipeline->Illuminate\\Pipeline\\{closure}(Object(Illuminate\\Http\\Request))
#31 /Users/aaronpk/Code/Laravel/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(183): Illuminate\\Cookie\\Middleware\\EncryptCookies->handle(Object(Illuminate\\Http\\Request), Object(Closure))
#32 /Users/aaronpk/Code/Laravel/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(119): Illuminate\\Pipeline\\Pipeline->Illuminate\\Pipeline\\{closure}(Object(Illuminate\\Http\\Request))
#33 /Users/aaronpk/Code/Laravel/vendor/laravel/framework/src/Illuminate/Routing/Router.php(805): Illuminate\\Pipeline\\Pipeline->then(Object(Closure))
#34 /Users/aaronpk/Code/Laravel/vendor/laravel/framework/src/Illuminate/Routing/Router.php(784): Illuminate\\Routing\\Router->runRouteWithinStack(Object(Illuminate\\Routing\\Route), Object(Illuminate\\Http\\Request))
#35 /Users/aaronpk/Code/Laravel/vendor/laravel/framework/src/Illuminate/Routing/Router.php(748): Illuminate\\Routing\\Router->runRoute(Object(Illuminate\\Http\\Request), Object(Illuminate\\Routing\\Route))
#36 /Users/aaronpk/Code/Laravel/vendor/laravel/framework/src/Illuminate/Routing/Router.php(737): Illuminate\\Routing\\Router->dispatchToRoute(Object(Illuminate\\Http\\Request))
#37 /Users/aaronpk/Code/Laravel/vendor/laravel/framework/src/Illuminate/Foundation/Http/Kernel.php(200): Illuminate\\Routing\\Router->dispatch(Object(Illuminate\\Http\\Request))
#38 /Users/aaronpk/Code/Laravel/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(144): Illuminate\\Foundation\\Http\\Kernel->Illuminate\\Foundation\\Http\\{closure}(Object(Illuminate\\Http\\Request))
#39 /Users/aaronpk/Code/Laravel/vendor/laravel/framework/src/Illuminate/Foundation/Http/Middleware/TransformsRequest.php(21): Illuminate\\Pipeline\\Pipeline->Illuminate\\Pipeline\\{closure}(Object(Illuminate\\Http\\Request))
#40 /Users/aaronpk/Code/Laravel/vendor/laravel/framework/src/Illuminate/Foundation/Http/Middleware/ConvertEmptyStringsToNull.php(31): Illuminate\\Foundation\\Http\\Middleware\\TransformsRequest->handle(Object(Illuminate\\Http\\Request), Object(Closure))
#41 /Users/aaronpk/Code/Laravel/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(183): Illuminate\\Foundation\\Http\\Middleware\\ConvertEmptyStringsToNull->handle(Object(Illuminate\\Http\\Request), Object(Closure))
#42 /Users/aaronpk/Code/Laravel/vendor/laravel/framework/src/Illuminate/Foundation/Http/Middleware/TransformsRequest.php(21): Illuminate\\Pipeline\\Pipeline->Illuminate\\Pipeline\\{closure}(Object(Illuminate\\Http\\Request))
#43 /Users/aaronpk/Code/Laravel/vendor/laravel/framework/src/Illuminate/Foundation/Http/Middleware/TrimStrings.php(51): Illuminate\\Foundation\\Http\\Middleware\\TransformsRequest->handle(Object(Illuminate\\Http\\Request), Object(Closure))
#44 /Users/aaronpk/Code/Laravel/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(183): Illuminate\\Foundation\\Http\\Middleware\\TrimStrings->handle(Object(Illuminate\\Http\\Request), Object(Closure))
#45 /Users/aaronpk/Code/Laravel/vendor/laravel/framework/src/Illuminate/Http/Middleware/ValidatePostSize.php(27): Illuminate\\Pipeline\\Pipeline->Illuminate\\Pipeline\\{closure}(Object(Illuminate\\Http\\Request))
#46 /Users/aaronpk/Code/Laravel/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(183): Illuminate\\Http\\Middleware\\ValidatePostSize->handle(Object(Illuminate\\Http\\Request), Object(Closure))
#47 /Users/aaronpk/Code/Laravel/vendor/laravel/framework/src/Illuminate/Foundation/Http/Middleware/PreventRequestsDuringMaintenance.php(110): Illuminate\\Pipeline\\Pipeline->Illuminate\\Pipeline\\{closure}(Object(Illuminate\\Http\\Request))
#48 /Users/aaronpk/Code/Laravel/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(183): Illuminate\\Foundation\\Http\\Middleware\\PreventRequestsDuringMaintenance->handle(Object(Illuminate\\Http\\Request), Object(Closure))
#49 /Users/aaronpk/Code/Laravel/vendor/laravel/framework/src/Illuminate/Http/Middleware/HandleCors.php(49): Illuminate\\Pipeline\\Pipeline->Illuminate\\Pipeline\\{closure}(Object(Illuminate\\Http\\Request))
#50 /Users/aaronpk/Code/Laravel/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(183): Illuminate\\Http\\Middleware\\HandleCors->handle(Object(Illuminate\\Http\\Request), Object(Closure))
#51 /Users/aaronpk/Code/Laravel/vendor/laravel/framework/src/Illuminate/Http/Middleware/TrustProxies.php(57): Illuminate\\Pipeline\\Pipeline->Illuminate\\Pipeline\\{closure}(Object(Illuminate\\Http\\Request))
#52 /Users/aaronpk/Code/Laravel/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(183): Illuminate\\Http\\Middleware\\TrustProxies->handle(Object(Illuminate\\Http\\Request), Object(Closure))
#53 /Users/aaronpk/Code/Laravel/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(119): Illuminate\\Pipeline\\Pipeline->Illuminate\\Pipeline\\{closure}(Object(Illuminate\\Http\\Request))
#54 /Users/aaronpk/Code/Laravel/vendor/laravel/framework/src/Illuminate/Foundation/Http/Kernel.php(175): Illuminate\\Pipeline\\Pipeline->then(Object(Closure))
#55 /Users/aaronpk/Code/Laravel/vendor/laravel/framework/src/Illuminate/Foundation/Http/Kernel.php(144): Illuminate\\Foundation\\Http\\Kernel->sendRequestThroughRouter(Object(Illuminate\\Http\\Request))
#56 /Users/aaronpk/Code/Laravel/vendor/laravel/framework/src/Illuminate/Foundation/Application.php(1172): Illuminate\\Foundation\\Http\\Kernel->handle(Object(Illuminate\\Http\\Request))
#57 /Users/aaronpk/Code/Laravel/public/index.php(17): Illuminate\\Foundation\\Application->handleRequest(Object(Illuminate\\Http\\Request))
#58 /Users/aaronpk/Code/Laravel/vendor/laravel/framework/src/Illuminate/Foundation/resources/server.php(16): require_once('/Users/aaronpk/...')
#59 {main}```
DarkGhostHunter commented 5 months ago

Typical problem where your user does not implements WebAuthnAuthenticatable.

You're getting that query because the User class is not WebAuthnAuthenticatable, so it skips the webauthn query and pushes a normal Eloquent Query to the user itself.