Skip to content

Commit dcc1417

Browse files
committed
Update PEM reader regex to avoid exponential backtracking
CodeQL flagged this as a vulnerability.
1 parent 15ede0f commit dcc1417

1 file changed

Lines changed: 7 additions & 6 deletions

File tree

src/main/java/com/rabbitmq/client/PemReader.java

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -50,20 +50,21 @@
5050
* The following modifications have been made to the original source code:
5151
* <ul>
5252
* <li>removed methods around loading trustStores.</li>
53+
* <li>updated the regular expressions to avoid exponential backtracking.</li>
5354
* </ul>
5455
*/
5556
public final class PemReader {
5657

5758
private static final Pattern CERT_PATTERN = Pattern.compile(
58-
"-+BEGIN\\s+.*CERTIFICATE[^-]*-+(?:\\s|\\r|\\n)+" // Header
59-
+ "([a-z0-9+/=\\r\\n]+)" // Base64 text
60-
+ "-+END\\s+.*CERTIFICATE[^-]*-+", // Footer
59+
"-+BEGIN\\s+.*CERTIFICATE[^-]*-+\\s*" // Header
60+
+ "([a-z0-9+/=\\r\\n]+)" // Base64 text
61+
+ "-+END\\s+.*CERTIFICATE[^-]*-+", // Footer
6162
CASE_INSENSITIVE);
6263

6364
private static final Pattern PRIVATE_KEY_PATTERN = Pattern.compile(
64-
"-+BEGIN\\s+.*PRIVATE\\s+KEY[^-]*-+(?:\\s|\\r|\\n)+" // Header
65-
+ "([a-z0-9+/=\\r\\n]+)" // Base64 text
66-
+ "-+END\\s+.*PRIVATE\\s+KEY[^-]*-+", // Footer
65+
"-+BEGIN\\s+.*PRIVATE\\s+KEY[^-]*-+\\s*" // Header
66+
+ "([a-z0-9+/=\\r\\n]+)" // Base64 text
67+
+ "-+END\\s+.*PRIVATE\\s+KEY[^-]*-+", // Footer
6768
CASE_INSENSITIVE);
6869

6970
private PemReader() {

0 commit comments

Comments
 (0)