h4xr opened a new issue, #4181:
URL: https://github.com/apache/logging-log4j2/issues/4181
## Description
Currently `RoutingAppender` based on its configuration can materialize an
unbounded number of routes. This coupled with a user controlled or high
cardinality key can result in File descriptor exhaustion.
Example configuration which can be problematic:
```xml
<?xml version="1.0" encoding="UTF-8"?>
<Configuration status="WARN">
<Appenders>
<Routing name="Routing">
<Routes pattern="${ctx:userId}">
<Route>
<File name="File-${ctx:userId}"
fileName="logs/user-${ctx:userId}.log">
<PatternLayout pattern="%d %p %c{1.} [%t] %m%n"/>
</File>
</Route>
</Routes>
<IdlePurgePolicy timeToLive="10" cleanupIntervalMillis="1000"/>
</Routing>
<Console name="Console" target="SYSTEM_OUT">
<PatternLayout pattern="%d{HH:mm:ss.SSS} [%t] %-5level
%logger{36} - %msg%n"/>
</Console>
</Appenders>
<Loggers>
<Root level="info">
<AppenderRef ref="Routing"/>
<AppenderRef ref="Console"/>
</Root>
</Loggers>
</Configuration>
```
## Configuration
**Version:** 2.26.3
**Operating system:** Mac OS 15
**JDK:** openjdk64-25.0.3
## Logs
N/A
## Reproduction
log4j config:
```xml
<?xml version="1.0" encoding="UTF-8"?>
<Configuration status="WARN">
<Appenders>
<Routing name="Routing">
<Routes pattern="${ctx:userId}">
<Route>
<File name="File-${ctx:userId}"
fileName="logs/user-${ctx:userId}.log">
<PatternLayout pattern="%d %p %c{1.} [%t] %m%n"/>
</File>
</Route>
</Routes>
<IdlePurgePolicy timeToLive="10" cleanupIntervalMillis="1000"/>
</Routing>
<Console name="Console" target="SYSTEM_OUT">
<PatternLayout pattern="%d{HH:mm:ss.SSS} [%t] %-5level
%logger{36} - %msg%n"/>
</Console>
</Appenders>
<Loggers>
<Root level="info">
<AppenderRef ref="Routing"/>
<AppenderRef ref="Console"/>
</Root>
</Loggers>
</Configuration>
```
Java Code to Trigger the bug:
```java
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.apache.logging.log4j.ThreadContext;
import java.util.UUID;
public class Harness {
private static final Logger logger = LogManager.getLogger(Harness.class);
public static void main(String[] args) {
System.out.println("Starting DoS harness...");
for (int i = 0; i < 1000000; i++) {
String userId = UUID.randomUUID().toString();
ThreadContext.put("userId", userId);
[logger.info](http://logger.info/)("Log message for user: " +
userId);
if (i % 10000 == 0) {
System.out.println("Logged " + i + " unique users...");
}
}
System.out.println("Finished logging.");
}
}
```
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]