Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
import org.apache.logging.log4j.core.net.ssl.SslConfiguration;
import org.apache.logging.log4j.core.net.ssl.SslConfigurationFactory;
import org.apache.logging.log4j.core.util.AuthorizationProvider;
import org.apache.logging.log4j.core.util.internal.SystemUtils;
import org.apache.logging.log4j.util.PropertiesUtil;
import org.apache.logging.log4j.util.Strings;

Expand All @@ -51,7 +52,24 @@ public class UrlConnectionFactory {
private static final String HTTP = "http";
private static final String HTTPS = "https";
private static final String JAR = "jar";
private static final String DEFAULT_ALLOWED_PROTOCOLS = "https, file, jar";
/**
* Default list of protocols that are allowed to be used for configuration files and other trusted resources.
* <p>
* By default, we trust the following protocols:
* <dl>
* <dt>file</dt>
* <dd>Local files</dd>
* <dt>https</dt>
* <dd>Resources retrieved through TLS to guarantee their integrity</dd>
* <dt>jar</dt>
* <dd>Resources retrieved from JAR files</dd>
* <dt>resource</dt>
* <dd>Resources embedded in a GraalVM native image</dd>
* </dl>
*/
private static final String DEFAULT_ALLOWED_PROTOCOLS =
SystemUtils.isGraalVm() ? "file, https, jar, resource" : "file, https, jar";

private static final String NO_PROTOCOLS = "_none";
public static final String ALLOWED_PROTOCOLS = "log4j2.Configuration.allowedProtocols";

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,5 +36,21 @@ public static boolean isOsAndroid() {
return getJavaVendor().contains("Android");
}

/**
* Checks if the current runtime is GraalVM.
* <p>
* See <a href="https://www.graalvm.org/sdk/javadoc/org/graalvm/nativeimage/ImageInfo.html#PROPERTY_IMAGE_CODE_KEY">ImageInfo.PROPERTY_IMAGE_CODE_KEY</a>.
* </p>
* @return true if the current runtime is GraalVM, false otherwise.
*/
public static boolean isGraalVm() {
try {
return System.getProperty("org.graalvm.nativeimage.imagecode") != null;
} catch (final SecurityException e) {
LOGGER.debug("Unable to determine if the current runtime is GraalVM.", e);
return false;
}
}

private SystemUtils() {}
}
12 changes: 12 additions & 0 deletions src/changelog/.2.x.x/3790_allow-resource-protocol.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<?xml version="1.0" encoding="UTF-8"?>
<entry xmlns="https://logging.apache.org/xml/ns"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="
https://logging.apache.org/xml/ns
https://logging.apache.org/xml/ns/log4j-changelog-0.xsd"
type="fixed">
<issue id="3790" link="https://github.com/apache/logging-log4j2/issues/3790"/>
<description format="asciidoc">
Allow `resource:` protocol for configuration files by default, if the current runtime is GraalVM.
</description>
</entry>
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,17 @@

[cols="1h,5"]
|===
| Env. variable | `LOG4J_CONFIGURATION_ALLOWED_PROTOCOLS`
| Type | Comma-separated list of https://docs.oracle.com/javase/{java-target-version}/docs/api/java/net/URL.html[`URL`] protocols
| Default value | `file, https, jar`
| Env. variable
| `LOG4J_CONFIGURATION_ALLOWED_PROTOCOLS`

| Type
| Comma-separated list of https://docs.oracle.com/javase/{java-target-version}/docs/api/java/net/URL.html[`URL`] protocols

| Default value
|
`file, https, jar` (JVM)

`file, https, jar, resource` (GraalVM)
|===

A comma separated list of https://docs.oracle.com/javase/{java-target-version}/docs/api/java/net/URL.html[`URL`] protocols that may be used to load any kind of configuration source.
Expand Down