Skip to content
This repository was archived by the owner on May 31, 2024. It is now read-only.

Commit e4149a2

Browse files
derrabusnicolas-grekas
authored andcommitted
Leverage str_contains/str_starts_with
Signed-off-by: Alexander M. Turek <me@derrabus.de>
1 parent b9b8abc commit e4149a2

15 files changed

+18
-14
lines changed

Core/Authorization/Voter/RoleVoter.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ public function vote(TokenInterface $token, $subject, array $attributes)
4141
$attribute = $attribute->getRole();
4242
}
4343

44-
if (!\is_string($attribute) || 0 !== strpos($attribute, $this->prefix)) {
44+
if (!\is_string($attribute) || !str_starts_with($attribute, $this->prefix)) {
4545
continue;
4646
}
4747

Core/Encoder/Argon2iPasswordEncoder.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ public function isPasswordValid($encoded, $raw, $salt)
8383
{
8484
// If $encoded was created via "sodium_crypto_pwhash_str()", the hashing algorithm may be "argon2id" instead of "argon2i".
8585
// In this case, "password_verify()" cannot be used.
86-
if (\PHP_VERSION_ID >= 70200 && \defined('PASSWORD_ARGON2I') && (false === strpos($encoded, '$argon2id$'))) {
86+
if (\PHP_VERSION_ID >= 70200 && \defined('PASSWORD_ARGON2I') && (!str_contains($encoded, '$argon2id$'))) {
8787
return !$this->isPasswordTooLong($raw) && password_verify($raw, $encoded);
8888
}
8989
if (\function_exists('sodium_crypto_pwhash_str_verify')) {

Core/Encoder/MessageDigestPasswordEncoder.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ public function encodePassword($raw, $salt)
7373
*/
7474
public function isPasswordValid($encoded, $raw, $salt)
7575
{
76-
if (\strlen($encoded) !== $this->encodedLength || false !== strpos($encoded, '$')) {
76+
if (\strlen($encoded) !== $this->encodedLength || str_contains($encoded, '$')) {
7777
return false;
7878
}
7979

Core/Encoder/NativePasswordEncoder.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -97,9 +97,9 @@ public function isPasswordValid($encoded, $raw, $salt): bool
9797
return false;
9898
}
9999

100-
if (0 !== strpos($encoded, '$argon')) {
100+
if (!str_starts_with($encoded, '$argon')) {
101101
// BCrypt encodes only the first 72 chars
102-
return (72 >= \strlen($raw) || 0 !== strpos($encoded, '$2')) && password_verify($raw, $encoded);
102+
return (72 >= \strlen($raw) || !str_starts_with($encoded, '$2')) && password_verify($raw, $encoded);
103103
}
104104

105105
if (\extension_loaded('sodium') && version_compare(\SODIUM_LIBRARY_VERSION, '1.0.14', '>=')) {

Core/Encoder/Pbkdf2PasswordEncoder.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ public function encodePassword($raw, $salt)
8080
*/
8181
public function isPasswordValid($encoded, $raw, $salt)
8282
{
83-
if (\strlen($encoded) !== $this->encodedLength || false !== strpos($encoded, '$')) {
83+
if (\strlen($encoded) !== $this->encodedLength || str_contains($encoded, '$')) {
8484
return false;
8585
}
8686

Core/Encoder/SodiumPasswordEncoder.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -84,9 +84,9 @@ public function isPasswordValid($encoded, $raw, $salt): bool
8484
return false;
8585
}
8686

87-
if (0 !== strpos($encoded, '$argon')) {
87+
if (!str_starts_with($encoded, '$argon')) {
8888
// Accept validating non-argon passwords for seamless migrations
89-
return (72 >= \strlen($raw) || 0 !== strpos($encoded, '$2')) && password_verify($raw, $encoded);
89+
return (72 >= \strlen($raw) || !str_starts_with($encoded, '$2')) && password_verify($raw, $encoded);
9090
}
9191

9292
if (\function_exists('sodium_crypto_pwhash_str_verify')) {

Core/composer.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
"require": {
1919
"php": ">=7.1.3",
2020
"symfony/event-dispatcher-contracts": "^1.1|^2",
21+
"symfony/polyfill-php80": "^1.16",
2122
"symfony/service-contracts": "^1.1.6|^2"
2223
},
2324
"require-dev": {

Csrf/TokenStorage/SessionTokenStorage.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ public function removeToken($tokenId)
9898
public function clear()
9999
{
100100
foreach (array_keys($this->session->all()) as $key) {
101-
if (0 === strpos($key, $this->namespace.'/')) {
101+
if (str_starts_with($key, $this->namespace.'/')) {
102102
$this->session->remove($key);
103103
}
104104
}

Csrf/composer.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
],
1818
"require": {
1919
"php": ">=7.1.3",
20+
"symfony/polyfill-php80": "^1.16",
2021
"symfony/security-core": "^3.4|^4.0|^5.0"
2122
},
2223
"require-dev": {

Http/Firewall/ChannelListener.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ public function supports(Request $request): ?bool
5151
if (null !== $this->logger) {
5252
if ('https' === $request->headers->get('X-Forwarded-Proto')) {
5353
$this->logger->info('Redirecting to HTTPS. ("X-Forwarded-Proto" header is set to "https" - did you set "trusted_proxies" correctly?)');
54-
} elseif (false !== strpos($request->headers->get('Forwarded'), 'proto=https')) {
54+
} elseif (str_contains($request->headers->get('Forwarded'), 'proto=https')) {
5555
$this->logger->info('Redirecting to HTTPS. ("Forwarded" header is set to "proto=https" - did you set "trusted_proxies" correctly?)');
5656
} else {
5757
$this->logger->info('Redirecting to HTTPS.');

0 commit comments

Comments
 (0)