Skip to content

Commit 084a636

Browse files
committed
fix: Add resource: protocol to allowed URL schemes by default
This update includes `resource:` in the list of allowed URL schemes for retrieving configuration files. See [`log4j2.configurationAllowedProtocols`](https://logging.apache.org/log4j/2.x/manual/systemproperties.html#log4j2.configurationAllowedProtocols) Currently, the `resource:` protocol is used exclusively by a `URLStreamHandler` that retrieves files from the embedded resources in a GraalVM native image. This makes it a secure and appropriate source for trusted configuration files. This change cannot be easily and reliably tested through a unit test. An integration test will be provided in apache/logging-log4j-samples#345 Closes #3790
1 parent 3b0c77d commit 084a636

File tree

2 files changed

+29
-1
lines changed

2 files changed

+29
-1
lines changed

log4j-core/src/main/java/org/apache/logging/log4j/core/net/UrlConnectionFactory.java

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,23 @@ public class UrlConnectionFactory {
5151
private static final String HTTP = "http";
5252
private static final String HTTPS = "https";
5353
private static final String JAR = "jar";
54-
private static final String DEFAULT_ALLOWED_PROTOCOLS = "https, file, jar";
54+
/**
55+
* Default list of protocols that are allowed to be used for configuration files and other trusted resources.
56+
* <p>
57+
* By default, we trust the following protocols:
58+
* <dl>
59+
* <dt>file</dt>
60+
* <dd>Local files</dd>
61+
* <dt>https</dt>
62+
* <dd>Resources retrieved through TLS to guarantee their integrity</dd>
63+
* <dt>jar</dt>
64+
* <dd>Resources retrieved from JAR files</dd>
65+
* <dt>resource</dt>
66+
* <dd>Resources embedded in a GraalVM native image</dd>
67+
* </dl>
68+
*/
69+
private static final String DEFAULT_ALLOWED_PROTOCOLS = "file, https, jar, resource";
70+
5571
private static final String NO_PROTOCOLS = "_none";
5672
public static final String ALLOWED_PROTOCOLS = "log4j2.Configuration.allowedProtocols";
5773

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<entry xmlns="https://logging.apache.org/xml/ns"
3+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
4+
xsi:schemaLocation="
5+
https://logging.apache.org/xml/ns
6+
https://logging.apache.org/xml/ns/log4j-changelog-0.xsd"
7+
type="fixed">
8+
<issue id="3790" link="https://github.com/apache/logging-log4j2/issues/3790"/>
9+
<description format="asciidoc">
10+
Allow `resource:` protocol for configuration files by default.
11+
</description>
12+
</entry>

0 commit comments

Comments
 (0)