Skip to content

Commit 7f004ac

Browse files
committed
Fix BZ 64871. Log if file access is blocked due to symlinks
https://bz.apache.org/bugzilla/show_bug.cgi?id=64871
1 parent 7f68b14 commit 7f004ac

3 files changed

Lines changed: 24 additions & 1 deletion

File tree

‎java/org/apache/catalina/webresources/AbstractFileResourceSet.java‎

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,11 +22,15 @@
2222
import java.net.URL;
2323

2424
import org.apache.catalina.LifecycleException;
25+
import org.apache.juli.logging.Log;
26+
import org.apache.juli.logging.LogFactory;
2527
import org.apache.tomcat.util.compat.JrePlatform;
2628
import org.apache.tomcat.util.http.RequestUtil;
2729

2830
public abstract class AbstractFileResourceSet extends AbstractResourceSet {
2931

32+
private static final Log log = LogFactory.getLog(AbstractFileResourceSet.class);
33+
3034
protected static final String[] EMPTY_STRING_ARRAY = new String[0];
3135

3236
private File fileBase;
@@ -128,6 +132,19 @@ protected final File file(String name, boolean mustExist) {
128132
canPath = normalize(canPath);
129133
}
130134
if (!canPath.equals(absPath)) {
135+
if (!canPath.equalsIgnoreCase(absPath)) {
136+
// Typically means symlinks are in use but being ignored. Given
137+
// the symlink was likely created for a reason, log a warning
138+
// that it was ignored.
139+
String msg = sm.getString("abstractFileResourceSet.canonicalfileCheckFailed",
140+
getRoot().getContext().getName(), absPath, canPath);
141+
// Log issues with configuration files at a higher level
142+
if(absPath.startsWith("/META-INF/") || absPath.startsWith("/WEB-INF/")) {
143+
log.error(msg);
144+
} else {
145+
log.warn(msg);
146+
}
147+
}
131148
return null;
132149
}
133150

@@ -144,7 +161,7 @@ private boolean isInvalidWindowsFilename(String name) {
144161
// expression irrespective of input length.
145162
for (int i = 0; i < len; i++) {
146163
char c = name.charAt(i);
147-
if (c == '\"' || c == '<' || c == '>') {
164+
if (c == '\"' || c == '<' || c == '>' || c == ':') {
148165
// These characters are disallowed in Windows file names and
149166
// there are known problems for file names with these characters
150167
// when using File#getCanonicalPath().

‎java/org/apache/catalina/webresources/LocalStrings.properties‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@
1515

1616
abstractArchiveResourceSet.setReadOnlyFalse=Archive based WebResourceSets such as those based on JARs are hard-coded to be read-only and may not be configured to be read-write
1717

18+
abstractFileResourceSet.canonicalfileCheckFailed=Resource for web application [{0}] at path [{1}] was not loaded as the canonical path [{2}] did not match. Use of symlinks is one possible cause.
19+
1820
abstractResource.getContentFail=Unable to return [{0}] as a byte array
1921
abstractResource.getContentTooLarge=Unable to return [{0}] as a byte array since the resource is [{1}] bytes in size which is larger than the maximum size of a byte array
2022

‎webapps/docs/changelog.xml‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,10 @@
9292
classloader as the thread context classloader, just like for the JAAS
9393
realm. (remm)
9494
</fix>
95+
<add>
96+
<bug>64871</bug>: Log a warning if Tomcat blocks access to a file
97+
because it uses symlinks. (markt)
98+
</add>
9599
</changelog>
96100
</subsection>
97101
<subsection name="Coyote">

0 commit comments

Comments
 (0)