Skip to content

Commit

Permalink
[3.x] Replace removeSpecialCharacters method with Str Helper Equivale…
Browse files Browse the repository at this point in the history
…nt (#219)

* Bump support requirment to include new String transliteration helper

* Replace removeSpecialCharacters method with Str transliteration method

Co-authored-by: Liam Hackett <liamh@DESKTOP-RS5AQ35.localdomain>
  • Loading branch information
liamh101 and Liam Hackett authored Feb 5, 2022
1 parent e011981 commit bc44a9c
Show file tree
Hide file tree
Showing 3 changed files with 2 additions and 110 deletions.
84 changes: 1 addition & 83 deletions auth-backend/ThrottlesLogins.php
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ protected function fireLockoutEvent(Request $request)
*/
protected function throttleKey(Request $request)
{
return $this->removeSpecialCharacters(Str::lower($request->input($this->username())).'|'.$request->ip());
return Str::transliterate(Str::lower($request->input($this->username())).'|'.$request->ip());
}

/**
Expand Down Expand Up @@ -121,86 +121,4 @@ public function decayMinutes()
{
return property_exists($this, 'decayMinutes') ? $this->decayMinutes : 1;
}

/**
* Remove special characters that may allow users to bypass rate limiting.
*
* @param string $key
* @return string
*/
protected function removeSpecialCharacters($key)
{
$values = [
'' => 'a',
'' => 'b',
'' => 'c',
'' => 'd',
'' => 'e',
'' => 'f',
'' => 'g',
'' => 'h',
'' => 'i',
'' => 'j',
'' => 'k',
'' => 'l',
'' => 'm',
'' => 'n',
'' => 'o',
'' => 'p',
'' => 'q',
'' => 'r',
'' => 's',
'' => 't',
'' => 'u',
'' => 'v',
'' => 'w',
'' => 'x',
'' => 'y',
'' => 'z',
'' => '1',
'' => '2',
'' => '3',
'' => '4',
'' => '5',
'' => '6',
'' => '7',
'' => '8',
'' => '9',
'' => '10',
'' => '11',
'' => '12',
'' => '13',
'' => '14',
'' => '15',
'' => '16',
'' => '17',
'' => '18',
'' => '19',
'' => '20',
'' => '0',
'' => '1',
'' => '2',
'' => '3',
'' => '4',
'' => '5',
'' => '6',
'' => '7',
'' => '8',
'' => '9',
'' => '10',
'' => '11',
'' => '12',
'' => '13',
'' => '14',
'' => '15',
'' => '16',
'' => '17',
'' => '18',
'' => '19',
'' => '20',
'' => '0',
];

return strtr($key, $values);
}
}
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
"php": "^7.3|^8.0",
"illuminate/console": "^8.42|^9.0",
"illuminate/filesystem": "^8.42|^9.0",
"illuminate/support": "^8.42|^9.0",
"illuminate/support": "^8.82|^9.0",
"illuminate/validation": "^8.42|^9.0"
},
"require-dev": {
Expand Down
26 changes: 0 additions & 26 deletions tests/AuthBackend/ThrottleLoginsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,32 +9,6 @@

class ThrottleLoginsTest extends TestCase
{
/**
* @test
* @dataProvider specialCharacterProvider
*/
public function it_can_replace_special_characters(string $value, string $expected): void
{
$throttle = $this->getMockForTrait(ThrottlesLogins::class);
$reflection = new \ReflectionClass($throttle);
$method = $reflection->getMethod('removeSpecialCharacters');
$method->setAccessible(true);

$this->assertSame($expected, $method->invoke($throttle, $value));
}

public function specialCharacterProvider(): array
{
return [
['ⓐⓑⓒⓓⓔⓕⓖⓗⓘⓙⓚⓛⓜⓝⓞⓟⓠⓡⓢⓣⓤⓥⓦⓧⓨⓩ', 'abcdefghijklmnopqrstuvwxyz'],
['⓪①②③④⑤⑥⑦⑧⑨⑩⑪⑫⑬⑭⑮⑯⑰⑱⑲⑳', '01234567891011121314151617181920'],
['⓵⓶⓷⓸⓹⓺⓻⓼⓽⓾', '12345678910'],
['⓿⓫⓬⓭⓮⓯⓰⓱⓲⓳⓴', '011121314151617181920'],
['abcdefghijklmnopqrstuvwxyz', 'abcdefghijklmnopqrstuvwxyz'],
['0123456789', '0123456789'],
];
}

/**
* @test
* @dataProvider emailProvider
Expand Down

0 comments on commit bc44a9c

Please sign in to comment.