Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Sanitise peer certificate values we log #623

Merged
merged 1 commit into from
Aug 29, 2019
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 10 additions & 2 deletions src/main/java/com/rabbitmq/client/impl/TlsUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -130,8 +130,8 @@ public static String peerCertificateInfo(Certificate certificate, String prefix)
try {
return String.format("%s subject: %s, subject alternative names: %s, " +
"issuer: %s, not valid after: %s, X.509 usage extensions: %s",
prefix, c.getSubjectDN().getName(), sans(c, ","), c.getIssuerDN().getName(),
c.getNotAfter(), extensions(c));
stripCRLF(prefix), stripCRLF(c.getSubjectDN().getName()), stripCRLF(sans(c, ",")), stripCRLF(c.getIssuerDN().getName()),
c.getNotAfter(), stripCRLF(extensions(c)));
} catch (Exception e) {
return "Error while retrieving " + prefix + " certificate information";
}
Expand Down Expand Up @@ -173,6 +173,14 @@ public static String extensionPrettyPrint(String oid, byte[] derOctetString, X50
}
}

/**
* Strips carriage return (CR) and line feed (LF) characters to mitigate CWE-117.
* @return sanitised string value
*/
public static String stripCRLF(String value) {
return value.replaceAll("\r", "").replaceAll("\n", "");
}

private static String extensions(X509Certificate certificate) {
List<String> extensions = new ArrayList<String>();
for (String oid : certificate.getCriticalExtensionOIDs()) {
Expand Down