Skip to content

Commit fa9b48c

Browse files
truncate long issuers in log messages
1 parent 301f6a0 commit fa9b48c

File tree

2 files changed

+36
-2
lines changed

2 files changed

+36
-2
lines changed

x-pack/plugin/security/src/main/java/org/elasticsearch/xpack/security/authc/saml/SamlObjectHandler.java

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -267,8 +267,16 @@ private ElasticsearchSecurityException samlSignatureException(Issuer issuer, Lis
267267
return samlSignatureException(issuer, credentials, signature, null);
268268
}
269269

270-
private String describeIssuer(@Nullable Issuer issuer) {
271-
return issuer != null ? Strings.format(" The issuer included in the SAML message was [%s]", issuer.getValue()) : "";
270+
// package private for testing
271+
String describeIssuer(@Nullable Issuer issuer) {
272+
if (issuer == null) {
273+
return "";
274+
}
275+
final String msg = " The issuer included in the SAML message was [%s]";
276+
if (issuer.getValue().length() > 64) {
277+
return Strings.format(msg + "...", Strings.cleanTruncate(issuer.getValue(), 64));
278+
}
279+
return Strings.format(msg, issuer.getValue());
272280
}
273281

274282
private static String describeCredentials(List<Credential> credentials) {

x-pack/plugin/security/src/test/java/org/elasticsearch/xpack/security/authc/saml/SamlAuthenticatorTests.java

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,8 @@
3939
import org.opensaml.saml.saml2.core.SubjectConfirmation;
4040
import org.opensaml.saml.saml2.core.SubjectConfirmationData;
4141
import org.opensaml.saml.saml2.core.impl.AuthnStatementBuilder;
42+
import org.opensaml.saml.saml2.core.impl.IssuerBuilder;
43+
import org.opensaml.saml.saml2.core.impl.IssuerImpl;
4244
import org.opensaml.saml.saml2.encryption.Encrypter;
4345
import org.opensaml.security.credential.BasicCredential;
4446
import org.opensaml.security.credential.Credential;
@@ -83,7 +85,9 @@
8385
import static org.hamcrest.Matchers.contains;
8486
import static org.hamcrest.Matchers.containsInAnyOrder;
8587
import static org.hamcrest.Matchers.containsString;
88+
import static org.hamcrest.Matchers.endsWith;
8689
import static org.hamcrest.Matchers.equalTo;
90+
import static org.hamcrest.Matchers.hasLength;
8791
import static org.hamcrest.Matchers.instanceOf;
8892
import static org.hamcrest.Matchers.is;
8993
import static org.hamcrest.Matchers.iterableWithSize;
@@ -1370,6 +1374,28 @@ public void testFailureWhenIdPCredentialsAreNull() throws Exception {
13701374
}
13711375
}
13721376

1377+
public void testDescribeNullIssuer() {
1378+
assertThat(authenticator.describeIssuer(null), equalTo(""));
1379+
}
1380+
1381+
public void testDescribeIssuer() {
1382+
final Issuer issuer = new IssuerBuilder().buildObject();
1383+
issuer.setValue("https://idp.saml.elastic.test/");
1384+
assertThat(
1385+
authenticator.describeIssuer(issuer),
1386+
equalTo(" The issuer included in the SAML message was [https://idp.saml.elastic.test/]")
1387+
);
1388+
}
1389+
1390+
public void testDescribeVeryLongIssuer() {
1391+
final Issuer issuer = new IssuerBuilder().buildObject();
1392+
issuer.setValue("https://idp.saml.elastic.test/" + "a".repeat(128));
1393+
1394+
final String description = authenticator.describeIssuer(issuer);
1395+
assertThat(description, hasLength(114));
1396+
assertThat(description, endsWith("..."));
1397+
}
1398+
13731399
private interface CryptoTransform {
13741400
String transform(String xml, Tuple<X509Certificate, PrivateKey> keyPair) throws Exception;
13751401
}

0 commit comments

Comments
 (0)