diff --git a/CHANGELOG.md b/CHANGELOG.md index cc226822..272c9362 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -13,6 +13,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ### Fixed - Fix configuration for delegated authentication with OIDC [#222] +- Prevent logging of invalid login credentials [#233] ## [v7.0.8-3] - 2024-10-11 ### Changed diff --git a/app/etc/cas/config/log4j2.xml b/app/etc/cas/config/log4j2.xml index 9ed0543a..4073754c 100644 --- a/app/etc/cas/config/log4j2.xml +++ b/app/etc/cas/config/log4j2.xml @@ -67,6 +67,10 @@ + + + + @@ -104,6 +108,9 @@ + + + diff --git a/app/src/main/java/de/triology/cas/logging/MisspelledPasswordRewritePolicy.java b/app/src/main/java/de/triology/cas/logging/MisspelledPasswordRewritePolicy.java new file mode 100644 index 00000000..f10cbf9a --- /dev/null +++ b/app/src/main/java/de/triology/cas/logging/MisspelledPasswordRewritePolicy.java @@ -0,0 +1,42 @@ +package de.triology.cas.logging; + +import org.apache.logging.log4j.core.config.plugins.Plugin; +import org.apache.logging.log4j.core.config.plugins.PluginFactory; + +@Plugin( + name = "MisspelledPasswordRewritePolicy", + category = "Core", + elementType = "rewritePolicy", + printObject = true +) +/* + * Password rewriter for class org.apereo.cas.web.flow.DefaultDelegatedClientIdentityProviderConfigurationProducer. + */ +public final class MisspelledPasswordRewritePolicy extends AbstractCASPasswordRewritePolicy { + private static final String PARAMETER_PASSWORD_TEXT = "password="; + + @PluginFactory + public static MisspelledPasswordRewritePolicy createPolicy() { + return new MisspelledPasswordRewritePolicy(); + } + + private MisspelledPasswordRewritePolicy() { + // + } + + @Override + protected String getPasswordFlag() { + return PARAMETER_PASSWORD_TEXT; + } + + @Override + protected String replacePasswordValue(String originMessage) { + String truncatedMessage = null; + + if (originMessage != null) { + truncatedMessage = originMessage.replaceAll("password=\\[.*\\],\\s*exec", "password=[******], exec"); + } + + return truncatedMessage; + } +} \ No newline at end of file diff --git a/resources/etc/cas/config/log4j2.xml.tpl b/resources/etc/cas/config/log4j2.xml.tpl index be69d14e..feaac3fa 100644 --- a/resources/etc/cas/config/log4j2.xml.tpl +++ b/resources/etc/cas/config/log4j2.xml.tpl @@ -67,6 +67,10 @@ + + + + @@ -104,6 +108,9 @@ + + +