Recover malformed JWT public key end marker
This commit is contained in:
@@ -166,6 +166,18 @@ class JwtAuthMiddleware
|
|||||||
. "-----END {$type}-----\n";
|
. "-----END {$type}-----\n";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (preg_match('/-----BEGIN ([A-Z ]*PUBLIC KEY)-----(.*)/s', $publicKey, $matches)) {
|
||||||
|
$type = $matches[1];
|
||||||
|
$bodySource = preg_split('/-----END|END\s+(?:RSA\s+)?PUBLIC\s+KEY/i', $matches[2], 2)[0];
|
||||||
|
$body = preg_replace('/[^A-Za-z0-9+\/=]/', '', $bodySource);
|
||||||
|
|
||||||
|
if (strlen($body) > 100) {
|
||||||
|
return "-----BEGIN {$type}-----\n"
|
||||||
|
. chunk_split($body, 64, "\n")
|
||||||
|
. "-----END {$type}-----\n";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if (!str_contains($publicKey, '-----BEGIN')) {
|
if (!str_contains($publicKey, '-----BEGIN')) {
|
||||||
$body = preg_replace('/[^A-Za-z0-9+\/=]/', '', $publicKey);
|
$body = preg_replace('/[^A-Za-z0-9+\/=]/', '', $publicKey);
|
||||||
|
|
||||||
|
|||||||
@@ -50,6 +50,17 @@ Route::get('/health-check-key', function () {
|
|||||||
$formattedPublicKey = "-----BEGIN {$pemType}-----\n"
|
$formattedPublicKey = "-----BEGIN {$pemType}-----\n"
|
||||||
. chunk_split($body, 64, "\n")
|
. chunk_split($body, 64, "\n")
|
||||||
. "-----END {$pemType}-----\n";
|
. "-----END {$pemType}-----\n";
|
||||||
|
} elseif (preg_match('/-----BEGIN ([A-Z ]*PUBLIC KEY)-----(.*)/s', $formattedPublicKey, $matches)) {
|
||||||
|
$pemType = $matches[1];
|
||||||
|
$bodySource = preg_split('/-----END|END\s+(?:RSA\s+)?PUBLIC\s+KEY/i', $matches[2], 2)[0];
|
||||||
|
$body = preg_replace('/[^A-Za-z0-9+\/=]/', '', $bodySource);
|
||||||
|
$bodyLength = strlen($body);
|
||||||
|
|
||||||
|
if ($bodyLength > 100) {
|
||||||
|
$formattedPublicKey = "-----BEGIN {$pemType}-----\n"
|
||||||
|
. chunk_split($body, 64, "\n")
|
||||||
|
. "-----END {$pemType}-----\n";
|
||||||
|
}
|
||||||
} elseif (!str_contains($formattedPublicKey, '-----BEGIN')) {
|
} elseif (!str_contains($formattedPublicKey, '-----BEGIN')) {
|
||||||
$body = preg_replace('/[^A-Za-z0-9+\/=]/', '', $formattedPublicKey);
|
$body = preg_replace('/[^A-Za-z0-9+\/=]/', '', $formattedPublicKey);
|
||||||
$bodyLength = strlen($body);
|
$bodyLength = strlen($body);
|
||||||
|
|||||||
@@ -37,6 +37,17 @@ Route::get('/health-check-key', function () {
|
|||||||
$formattedPublicKey = "-----BEGIN {$pemType}-----\n"
|
$formattedPublicKey = "-----BEGIN {$pemType}-----\n"
|
||||||
. chunk_split($body, 64, "\n")
|
. chunk_split($body, 64, "\n")
|
||||||
. "-----END {$pemType}-----\n";
|
. "-----END {$pemType}-----\n";
|
||||||
|
} elseif (preg_match('/-----BEGIN ([A-Z ]*PUBLIC KEY)-----(.*)/s', $formattedPublicKey, $matches)) {
|
||||||
|
$pemType = $matches[1];
|
||||||
|
$bodySource = preg_split('/-----END|END\s+(?:RSA\s+)?PUBLIC\s+KEY/i', $matches[2], 2)[0];
|
||||||
|
$body = preg_replace('/[^A-Za-z0-9+\/=]/', '', $bodySource);
|
||||||
|
$bodyLength = strlen($body);
|
||||||
|
|
||||||
|
if ($bodyLength > 100) {
|
||||||
|
$formattedPublicKey = "-----BEGIN {$pemType}-----\n"
|
||||||
|
. chunk_split($body, 64, "\n")
|
||||||
|
. "-----END {$pemType}-----\n";
|
||||||
|
}
|
||||||
} elseif (!str_contains($formattedPublicKey, '-----BEGIN')) {
|
} elseif (!str_contains($formattedPublicKey, '-----BEGIN')) {
|
||||||
$body = preg_replace('/[^A-Za-z0-9+\/=]/', '', $formattedPublicKey);
|
$body = preg_replace('/[^A-Za-z0-9+\/=]/', '', $formattedPublicKey);
|
||||||
$bodyLength = strlen($body);
|
$bodyLength = strlen($body);
|
||||||
|
|||||||
Reference in New Issue
Block a user