Skip to content

Commit c0fcaaa

Browse files
committed
Remove most alerts
Removes all the security alerts, except PATH_TRAVERSAL_IN/OUT and URLCONNECTION_SSRF_FD.
1 parent 8996e9f commit c0fcaaa

File tree

17 files changed

+84
-14
lines changed

17 files changed

+84
-14
lines changed

log4j-core-test/src/test/java/org/apache/logging/log4j/core/appender/rolling/RolloverFilePatternTest.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -30,30 +30,30 @@ public class RolloverFilePatternTest {
3030
@Test
3131
public void testFilePatternWithoutPadding() throws Exception {
3232
final Matcher matcher = AbstractRolloverStrategy.PATTERN_COUNTER.matcher("target/logs/test-%i.log.gz");
33-
assertTrue(matcher.matches());
33+
assertTrue(matcher.find());
3434
assertNull(matcher.group("ZEROPAD"));
3535
assertNull(matcher.group("PADDING"));
3636
}
3737

3838
@Test
3939
public void testFilePatternWithSpacePadding() throws Exception {
4040
final Matcher matcher = AbstractRolloverStrategy.PATTERN_COUNTER.matcher("target/logs/test-%3i.log.gz");
41-
assertTrue(matcher.matches());
41+
assertTrue(matcher.find());
4242
assertNull(matcher.group("ZEROPAD"));
4343
assertEquals("3", matcher.group("PADDING"));
4444
}
4545

4646
@Test
4747
public void testFilePatternWithZeroPadding() throws Exception {
4848
final Matcher matcher = AbstractRolloverStrategy.PATTERN_COUNTER.matcher("target/logs/test-%03i.log.gz");
49-
assertTrue(matcher.matches());
49+
assertTrue(matcher.find());
5050
assertEquals("0", matcher.group("ZEROPAD"));
5151
assertEquals("3", matcher.group("PADDING"));
5252
}
5353

5454
@Test
5555
public void testFilePatternUnmatched() throws Exception {
5656
final Matcher matcher = AbstractRolloverStrategy.PATTERN_COUNTER.matcher("target/logs/test-%n.log.gz");
57-
assertFalse(matcher.matches());
57+
assertFalse(matcher.find());
5858
}
5959
}

log4j-core/src/main/java/org/apache/logging/log4j/core/appender/db/jdbc/JdbcDatabaseManager.java

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@
3838
import java.util.Objects;
3939
import java.util.concurrent.CountDownLatch;
4040

41+
import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
4142
import org.apache.logging.log4j.core.Layout;
4243
import org.apache.logging.log4j.core.LogEvent;
4344
import org.apache.logging.log4j.core.StringLayout;
@@ -589,6 +590,10 @@ private boolean commitAndCloseAll() {
589590
return true;
590591
}
591592

593+
@SuppressFBWarnings(
594+
value = "SQL_INJECTION_JDBC",
595+
justification = "The SQL statement is generated based on the configuration file."
596+
)
592597
private void connectAndPrepare() throws SQLException {
593598
logger().debug("Acquiring JDBC connection from {}", this.getConnectionSource());
594599
this.connection = getConnectionSource().getConnection();
@@ -654,6 +659,10 @@ public String getTableName() {
654659
return factoryData.tableName;
655660
}
656661

662+
@SuppressFBWarnings(
663+
value = "SQL_INJECTION_JDBC",
664+
justification = "The SQL statement is generated based on the configuration file."
665+
)
657666
private void initColumnMetaData() throws SQLException {
658667
// Could use:
659668
// this.connection.getMetaData().getColumns(catalog, schemaPattern, tableNamePattern, columnNamePattern);

log4j-core/src/main/java/org/apache/logging/log4j/core/appender/rolling/AbstractRolloverStrategy.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ public abstract class AbstractRolloverStrategy implements RolloverStrategy {
4848
*/
4949
protected static final Logger LOGGER = StatusLogger.getLogger();
5050

51-
public static final Pattern PATTERN_COUNTER= Pattern.compile(".*%((?<ZEROPAD>0)?(?<PADDING>\\d+))?i.*");
51+
public static final Pattern PATTERN_COUNTER = Pattern.compile(".*%(?<ZEROPAD>0)?(?<PADDING>\\d+)?i.*");
5252

5353
protected final StrSubstitutor strSubstitutor;
5454

@@ -121,7 +121,7 @@ protected SortedMap<Integer, Path> getEligibleFiles(final String currentFile, fi
121121
} else {
122122
parent.mkdirs();
123123
}
124-
if (!PATTERN_COUNTER.matcher(logfilePattern).matches()) {
124+
if (!PATTERN_COUNTER.matcher(logfilePattern).find()) {
125125
return eligibleFiles;
126126
}
127127
final Path dir = parent.toPath();

log4j-core/src/main/java/org/apache/logging/log4j/core/appender/rolling/TimeBasedTriggeringPolicy.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
import java.util.concurrent.ThreadLocalRandom;
2020
import java.util.concurrent.TimeUnit;
2121

22+
import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
2223
import org.apache.logging.log4j.core.Core;
2324
import org.apache.logging.log4j.core.LogEvent;
2425
import org.apache.logging.log4j.core.config.plugins.Plugin;
@@ -106,6 +107,7 @@ public long getNextRolloverMillis() {
106107
* @param aManager The RollingFileManager.
107108
*/
108109
@Override
110+
@SuppressFBWarnings("PREDICTABLE_RANDOM")
109111
public void initialize(final RollingFileManager aManager) {
110112
this.manager = aManager;
111113
long current = aManager.getFileTime();
@@ -127,6 +129,7 @@ public void initialize(final RollingFileManager aManager) {
127129
* @return true if a rollover should occur.
128130
*/
129131
@Override
132+
@SuppressFBWarnings("PREDICTABLE_RANDOM")
130133
public boolean isTriggeringEvent(final LogEvent event) {
131134
final long nowMillis = event.getTimeMillis();
132135
if (nowMillis >= nextRolloverMillis) {

log4j-core/src/main/java/org/apache/logging/log4j/core/appender/rolling/action/PosixViewAttributeAction.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
import java.util.List;
3030
import java.util.Set;
3131

32+
import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
3233
import org.apache.logging.log4j.core.Core;
3334
import org.apache.logging.log4j.core.config.Configuration;
3435
import org.apache.logging.log4j.core.config.plugins.Plugin;
@@ -114,6 +115,10 @@ public static class Builder implements org.apache.logging.log4j.core.util.Builde
114115
private String fileGroup;
115116

116117
@Override
118+
@SuppressFBWarnings(
119+
value = "OVERLY_PERMISSIVE_FILE_PERMISSION",
120+
justification = "File permissions are specified in a configuration file."
121+
)
117122
public PosixViewAttributeAction build() {
118123
if (Strings.isEmpty(basePath)) {
119124
LOGGER.error("Posix file attribute view action not valid because base path is empty.");

log4j-core/src/main/java/org/apache/logging/log4j/core/config/builder/impl/DefaultConfigurationBuilder.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@
3939
import javax.xml.transform.stream.StreamResult;
4040
import javax.xml.transform.stream.StreamSource;
4141

42+
import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
4243
import org.apache.logging.log4j.Level;
4344
import org.apache.logging.log4j.core.Filter;
4445
import org.apache.logging.log4j.core.LoggerContext;
@@ -91,6 +92,10 @@ public class DefaultConfigurationBuilder<T extends BuiltConfiguration> implement
9192
private LoggerContext loggerContext;
9293
private String name;
9394

95+
@SuppressFBWarnings(
96+
value = {"XXE_DTD_TRANSFORM_FACTORY", "XXE_XSLT_TRANSFORM_FACTORY"},
97+
justification = "This method only uses internally generated data."
98+
)
9499
public static void formatXml(final Source source, final Result result)
95100
throws TransformerConfigurationException, TransformerFactoryConfigurationError, TransformerException {
96101
final Transformer transformer = TransformerFactory.newInstance().newTransformer();

log4j-core/src/main/java/org/apache/logging/log4j/core/config/xml/XmlConfiguration.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@
3434
import javax.xml.validation.SchemaFactory;
3535
import javax.xml.validation.Validator;
3636

37+
import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
3738
import org.apache.logging.log4j.core.LoggerContext;
3839
import org.apache.logging.log4j.core.config.AbstractConfiguration;
3940
import org.apache.logging.log4j.core.config.Configuration;
@@ -74,6 +75,10 @@ public class XmlConfiguration extends AbstractConfiguration implements Reconfigu
7475
private boolean strict;
7576
private String schemaResource;
7677

78+
@SuppressFBWarnings(
79+
value = "XXE_DOCUMENT",
80+
justification = "The `newDocumentBuilder` method disables DTD processing."
81+
)
7782
public XmlConfiguration(final LoggerContext loggerContext, final ConfigurationSource configSource) {
7883
super(loggerContext, configSource);
7984
final File configFile = configSource.getFile();

log4j-core/src/main/java/org/apache/logging/log4j/core/jmx/LoggerContextAdmin.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@
4141
import javax.management.NotificationBroadcasterSupport;
4242
import javax.management.ObjectName;
4343

44+
import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
4445
import org.apache.logging.log4j.core.LoggerContext;
4546
import org.apache.logging.log4j.core.config.Configuration;
4647
import org.apache.logging.log4j.core.config.ConfigurationFactory;
@@ -152,6 +153,10 @@ public String getConfigText() throws IOException {
152153
}
153154

154155
@Override
156+
@SuppressFBWarnings(
157+
value = "INFORMATION_EXPOSURE_THROUGH_AN_ERROR_MESSAGE",
158+
justification = "JMX should be considered a trusted channel."
159+
)
155160
public String getConfigText(final String charsetName) throws IOException {
156161
try {
157162
final ConfigurationSource source = loggerContext.getConfiguration().getConfigurationSource();

log4j-core/src/main/java/org/apache/logging/log4j/core/layout/GelfLayout.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
import java.util.zip.DeflaterOutputStream;
3131
import java.util.zip.GZIPOutputStream;
3232

33+
import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
3334
import org.apache.logging.log4j.Level;
3435
import org.apache.logging.log4j.core.Layout;
3536
import org.apache.logging.log4j.core.LogEvent;
@@ -747,6 +748,10 @@ private int formatLevel(final Level level) {
747748
/**
748749
* Non-private to make it accessible from unit test.
749750
*/
751+
@SuppressFBWarnings(
752+
value = "INFORMATION_EXPOSURE_THROUGH_AN_ERROR_MESSAGE",
753+
justification = "Log4j prints stacktraces only to logs, which should be private."
754+
)
750755
static CharSequence formatThrowable(final Throwable throwable) {
751756
// stack traces are big enough to provide a reasonably large initial capacity here
752757
final StringWriter sw = new StringWriter(2048);

log4j-core/src/main/java/org/apache/logging/log4j/core/layout/HtmlLayout.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
import java.nio.charset.StandardCharsets;
2828
import java.util.ArrayList;
2929

30+
import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
3031
import org.apache.logging.log4j.Level;
3132
import org.apache.logging.log4j.core.Layout;
3233
import org.apache.logging.log4j.core.LogEvent;
@@ -238,6 +239,10 @@ public String getContentType() {
238239
return contentType;
239240
}
240241

242+
@SuppressFBWarnings(
243+
value = "INFORMATION_EXPOSURE_THROUGH_AN_ERROR_MESSAGE",
244+
justification = "Log4j prints stacktraces only to logs, which should be private."
245+
)
241246
private void appendThrowableAsHtml(final Throwable throwable, final StringBuilder sbuf) {
242247
final StringWriter sw = new StringWriter();
243248
final PrintWriter pw = new PrintWriter(sw);

0 commit comments

Comments
 (0)