Skip to content

Commit a6d9307

Browse files
authored
[8.x] Protect against ambiguous columns (#43278)
* [8.x] Protect against ambiguous columns Resolving #43274 * Updating tests.
1 parent 97e68c6 commit a6d9307

File tree

2 files changed

+10
-6
lines changed

2 files changed

+10
-6
lines changed

src/Illuminate/Auth/EloquentUserProvider.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ public function retrieveById($identifier)
4949
$model = $this->createModel();
5050

5151
return $this->newModelQuery($model)
52-
->where($model->getAuthIdentifierName(), $identifier)
52+
->where($model->qualifyColumn($model->getAuthIdentifierName()), $identifier)
5353
->first();
5454
}
5555

@@ -65,7 +65,7 @@ public function retrieveByToken($identifier, $token)
6565
$model = $this->createModel();
6666

6767
$retrievedModel = $this->newModelQuery($model)->where(
68-
$model->getAuthIdentifierName(), $identifier
68+
$model->qualifyColumn($model->getAuthIdentifierName()), $identifier
6969
)->first();
7070

7171
if (! $retrievedModel) {

tests/Auth/AuthEloquentUserProviderTest.php

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,8 @@ public function testRetrieveByIDReturnsUser()
2222
$mock = m::mock(stdClass::class);
2323
$mock->shouldReceive('newQuery')->once()->andReturn($mock);
2424
$mock->shouldReceive('getAuthIdentifierName')->once()->andReturn('id');
25-
$mock->shouldReceive('where')->once()->with('id', 1)->andReturn($mock);
25+
$mock->shouldReceive('qualifyColumn')->with('id')->andReturn('users.id');
26+
$mock->shouldReceive('where')->once()->with('users.id', 1)->andReturn($mock);
2627
$mock->shouldReceive('first')->once()->andReturn('bar');
2728
$provider->expects($this->once())->method('createModel')->willReturn($mock);
2829
$user = $provider->retrieveById(1);
@@ -39,7 +40,8 @@ public function testRetrieveByTokenReturnsUser()
3940
$mock = m::mock(stdClass::class);
4041
$mock->shouldReceive('newQuery')->once()->andReturn($mock);
4142
$mock->shouldReceive('getAuthIdentifierName')->once()->andReturn('id');
42-
$mock->shouldReceive('where')->once()->with('id', 1)->andReturn($mock);
43+
$mock->shouldReceive('qualifyColumn')->with('id')->andReturn('users.id');
44+
$mock->shouldReceive('where')->once()->with('users.id', 1)->andReturn($mock);
4345
$mock->shouldReceive('first')->once()->andReturn($mockUser);
4446
$provider->expects($this->once())->method('createModel')->willReturn($mock);
4547
$user = $provider->retrieveByToken(1, 'a');
@@ -53,7 +55,8 @@ public function testRetrieveTokenWithBadIdentifierReturnsNull()
5355
$mock = m::mock(stdClass::class);
5456
$mock->shouldReceive('newQuery')->once()->andReturn($mock);
5557
$mock->shouldReceive('getAuthIdentifierName')->once()->andReturn('id');
56-
$mock->shouldReceive('where')->once()->with('id', 1)->andReturn($mock);
58+
$mock->shouldReceive('qualifyColumn')->with('id')->andReturn('users.id');
59+
$mock->shouldReceive('where')->once()->with('users.id', 1)->andReturn($mock);
5760
$mock->shouldReceive('first')->once()->andReturn(null);
5861
$provider->expects($this->once())->method('createModel')->willReturn($mock);
5962
$user = $provider->retrieveByToken(1, 'a');
@@ -78,7 +81,8 @@ public function testRetrieveByBadTokenReturnsNull()
7881
$mock = m::mock(stdClass::class);
7982
$mock->shouldReceive('newQuery')->once()->andReturn($mock);
8083
$mock->shouldReceive('getAuthIdentifierName')->once()->andReturn('id');
81-
$mock->shouldReceive('where')->once()->with('id', 1)->andReturn($mock);
84+
$mock->shouldReceive('qualifyColumn')->with('id')->andReturn('users.id');
85+
$mock->shouldReceive('where')->once()->with('users.id', 1)->andReturn($mock);
8286
$mock->shouldReceive('first')->once()->andReturn($mockUser);
8387
$provider->expects($this->once())->method('createModel')->willReturn($mock);
8488
$user = $provider->retrieveByToken(1, 'a');

0 commit comments

Comments
 (0)