Skip to content

Commit bc44a9c

Browse files
liamh101Liam Hackett
and
Liam Hackett
authoredFeb 5, 2022
[3.x] Replace removeSpecialCharacters method with Str Helper Equivalent (#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>
1 parent e011981 commit bc44a9c

File tree

3 files changed

+2
-110
lines changed

3 files changed

+2
-110
lines changed
 

‎auth-backend/ThrottlesLogins.php

+1-83
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ protected function fireLockoutEvent(Request $request)
8989
*/
9090
protected function throttleKey(Request $request)
9191
{
92-
return $this->removeSpecialCharacters(Str::lower($request->input($this->username())).'|'.$request->ip());
92+
return Str::transliterate(Str::lower($request->input($this->username())).'|'.$request->ip());
9393
}
9494

9595
/**
@@ -121,86 +121,4 @@ public function decayMinutes()
121121
{
122122
return property_exists($this, 'decayMinutes') ? $this->decayMinutes : 1;
123123
}
124-
125-
/**
126-
* Remove special characters that may allow users to bypass rate limiting.
127-
*
128-
* @param string $key
129-
* @return string
130-
*/
131-
protected function removeSpecialCharacters($key)
132-
{
133-
$values = [
134-
'' => 'a',
135-
'' => 'b',
136-
'' => 'c',
137-
'' => 'd',
138-
'' => 'e',
139-
'' => 'f',
140-
'' => 'g',
141-
'' => 'h',
142-
'' => 'i',
143-
'' => 'j',
144-
'' => 'k',
145-
'' => 'l',
146-
'' => 'm',
147-
'' => 'n',
148-
'' => 'o',
149-
'' => 'p',
150-
'' => 'q',
151-
'' => 'r',
152-
'' => 's',
153-
'' => 't',
154-
'' => 'u',
155-
'' => 'v',
156-
'' => 'w',
157-
'' => 'x',
158-
'' => 'y',
159-
'' => 'z',
160-
'' => '1',
161-
'' => '2',
162-
'' => '3',
163-
'' => '4',
164-
'' => '5',
165-
'' => '6',
166-
'' => '7',
167-
'' => '8',
168-
'' => '9',
169-
'' => '10',
170-
'' => '11',
171-
'' => '12',
172-
'' => '13',
173-
'' => '14',
174-
'' => '15',
175-
'' => '16',
176-
'' => '17',
177-
'' => '18',
178-
'' => '19',
179-
'' => '20',
180-
'' => '0',
181-
'' => '1',
182-
'' => '2',
183-
'' => '3',
184-
'' => '4',
185-
'' => '5',
186-
'' => '6',
187-
'' => '7',
188-
'' => '8',
189-
'' => '9',
190-
'' => '10',
191-
'' => '11',
192-
'' => '12',
193-
'' => '13',
194-
'' => '14',
195-
'' => '15',
196-
'' => '16',
197-
'' => '17',
198-
'' => '18',
199-
'' => '19',
200-
'' => '20',
201-
'' => '0',
202-
];
203-
204-
return strtr($key, $values);
205-
}
206124
}

‎composer.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
"php": "^7.3|^8.0",
1414
"illuminate/console": "^8.42|^9.0",
1515
"illuminate/filesystem": "^8.42|^9.0",
16-
"illuminate/support": "^8.42|^9.0",
16+
"illuminate/support": "^8.82|^9.0",
1717
"illuminate/validation": "^8.42|^9.0"
1818
},
1919
"require-dev": {

‎tests/AuthBackend/ThrottleLoginsTest.php

-26
Original file line numberDiff line numberDiff line change
@@ -9,32 +9,6 @@
99

1010
class ThrottleLoginsTest extends TestCase
1111
{
12-
/**
13-
* @test
14-
* @dataProvider specialCharacterProvider
15-
*/
16-
public function it_can_replace_special_characters(string $value, string $expected): void
17-
{
18-
$throttle = $this->getMockForTrait(ThrottlesLogins::class);
19-
$reflection = new \ReflectionClass($throttle);
20-
$method = $reflection->getMethod('removeSpecialCharacters');
21-
$method->setAccessible(true);
22-
23-
$this->assertSame($expected, $method->invoke($throttle, $value));
24-
}
25-
26-
public function specialCharacterProvider(): array
27-
{
28-
return [
29-
['ⓐⓑⓒⓓⓔⓕⓖⓗⓘⓙⓚⓛⓜⓝⓞⓟⓠⓡⓢⓣⓤⓥⓦⓧⓨⓩ', 'abcdefghijklmnopqrstuvwxyz'],
30-
['⓪①②③④⑤⑥⑦⑧⑨⑩⑪⑫⑬⑭⑮⑯⑰⑱⑲⑳', '01234567891011121314151617181920'],
31-
['⓵⓶⓷⓸⓹⓺⓻⓼⓽⓾', '12345678910'],
32-
['⓿⓫⓬⓭⓮⓯⓰⓱⓲⓳⓴', '011121314151617181920'],
33-
['abcdefghijklmnopqrstuvwxyz', 'abcdefghijklmnopqrstuvwxyz'],
34-
['0123456789', '0123456789'],
35-
];
36-
}
37-
3812
/**
3913
* @test
4014
* @dataProvider emailProvider

0 commit comments

Comments
 (0)
Please sign in to comment.