blob: f7e7e0bfa0f264bd8d21b61c65118c31c298b703 [file] [log] [blame]
<html><head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Aliased Files and Symbolic links</title><link rel="stylesheet" type="text/css" href="css/docbook.css"><meta name="generator" content="DocBook XSL Stylesheets V1.79.1"><meta name="keywords" content="jetty, servlet, servlet-api, cometd, http, websocket, eclipse, maven, java, server, software"><link rel="home" href="index.html" title="Jetty"><link rel="up" href="configuring-security.html" title="Chapter&nbsp;7.&nbsp;Configuring Security"><link rel="prev" href="configuring-form-size.html" title="Limiting Form Content"><link rel="next" href="configuring-security-secure-passwords.html" title="Secure Password Obfuscation"><link xmlns:jfetch="java:org.eclipse.jetty.xslt.tools.JavaSourceFetchExtension" xmlns:fetch="java:org.eclipse.jetty.xslt.tools.SourceFetchExtension" xmlns:d="http://docbook.org/ns/docbook" xmlns:l="http://docbook.sourceforge.net/xmlns/l10n/1.0" xmlns:xslthl="http://xslthl.sf.net" xmlns:gcse="http://www.google.com" xmlns:date="http://exslt.org/dates-and-times" rel="shortcut icon" href="images/favicon.ico"><link rel="stylesheet" href="css/highlighter/foundation.css"><script src="js/highlight.pack.js"></script><script>
hljs.initHighlightingOnLoad();
</script><link type="text/css" rel="stylesheet" href="css/font-awesome/font-awesome.min.css"></head><body bgcolor="white" text="black" link="#0000FF" vlink="#840084" alink="#0000FF"><table xmlns:jfetch="java:org.eclipse.jetty.xslt.tools.JavaSourceFetchExtension" xmlns:fetch="java:org.eclipse.jetty.xslt.tools.SourceFetchExtension" xmlns:d="http://docbook.org/ns/docbook" xmlns:l="http://docbook.sourceforge.net/xmlns/l10n/1.0" xmlns:xslthl="http://xslthl.sf.net" xmlns:gcse="http://www.google.com" xmlns:date="http://exslt.org/dates-and-times"><tr><td style="width: 25%"><a href="http://www.eclipse.org/jetty"><img src="images/jetty-header-logo.png" alt="Jetty Logo"></a><br><span style="font-size: small">
Version: 9.4.28-SNAPSHOT</span></td><td style="width: 50%"></td></tr></table><div xmlns:jfetch="java:org.eclipse.jetty.xslt.tools.JavaSourceFetchExtension" xmlns:fetch="java:org.eclipse.jetty.xslt.tools.SourceFetchExtension" xmlns:d="http://docbook.org/ns/docbook" xmlns:l="http://docbook.sourceforge.net/xmlns/l10n/1.0" xmlns:xslthl="http://xslthl.sf.net" xmlns:gcse="http://www.google.com" xmlns:date="http://exslt.org/dates-and-times" class="navheader"><table width="100%" summary="Navigation header"><tr><th colspan="3" align="center">Aliased Files and Symbolic links</th></tr><tr><td width="20%" align="left"><a accesskey="p" href="configuring-form-size.html"><i class="fa fa-chevron-left" aria-hidden="true"></i> Previous</a>&nbsp;</td><th width="60%" align="center">Chapter&nbsp;7.&nbsp;Configuring Security<br><a accesskey="p" href="index.html"><i class="fa fa-home" aria-hidden="true"></i> Home</a></th><td width="20%" align="right">&nbsp;<a accesskey="n" href="configuring-security-secure-passwords.html">Next <i class="fa fa-chevron-right" aria-hidden="true"></i></a></td></tr></table><hr></div><div xmlns:jfetch="java:org.eclipse.jetty.xslt.tools.JavaSourceFetchExtension" xmlns:fetch="java:org.eclipse.jetty.xslt.tools.SourceFetchExtension" xmlns:d="http://docbook.org/ns/docbook" xmlns:l="http://docbook.sourceforge.net/xmlns/l10n/1.0" xmlns:xslthl="http://xslthl.sf.net" xmlns:gcse="http://www.google.com" xmlns:date="http://exslt.org/dates-and-times" class="jetty-callout"><h5 class="callout"><a href="http://www.webtide.com/">Contact the core Jetty developers at
<span class="website">www.webtide.com</span></a></h5><p>
private support for your internal/customer projects ... custom extensions and distributions ... versioned snapshots for indefinite support ...
scalability guidance for your apps and Ajax/Comet projects ... development services for sponsored feature development
</p></div><div class="section"><div class="titlepage"><div><div><h2 class="title" style="clear: both"><a name="serving-aliased-files"></a>Aliased Files and Symbolic links</h2></div></div></div><div class="toc"><dl class="toc"><dt><span class="section"><a href="serving-aliased-files.html#_good_security_practise">Good Security Practise</a></span></dt><dt><span class="section"><a href="serving-aliased-files.html#file-alias-detection">Alias detection</a></span></dt><dt><span class="section"><a href="serving-aliased-files.html#file-alias-serving">Serving Aliases and Symbolic Links</a></span></dt></dl></div><p>Web applications will often serve static content from the file system provided by the operating system running underneath the JVM.
However, because file systems often implement multiple aliased names for the same file, then security constraints and other servlet URI space mappings may inadvertently be bypassed by aliases.</p><p>A key example of this is case insensitivity and 8.3 filenames implemented by the Windows file system.
If a file within a web application called <code class="literal">/mysecretfile.txt</code> is protected by a security constraint on the URI <code class="literal">/mysecretfile.txt</code>, then a request to <code class="literal">/MySecretFile.TXT</code> will not match the URI constraint because URIs are case sensitive, but the Windows file system will report that a file does exist at that name and it will be served despite the security constraint.
Less well known than case insensitivity is that Windows files systems also support <a class="link" href="http://en.wikipedia.org/wiki/8.3_filename" target="_top">8.3 filenames</a> for compatibility with legacy programs.
Thus a request to a URI like <code class="literal">/MYSECR~1.TXT</code> will again not match the security constraint, but will be reported as an existing file by the file system and served.</p><p>There are many examples of aliases, not just on Windows:</p><div class="itemizedlist"><ul class="itemizedlist" style="list-style-type: disc; "><li class="listitem">NTFS Alternate stream names like <code class="literal">c:\test\file.txt::$DATA:name</code></li><li class="listitem">OpenVMS support file versionig so that <code class="literal">/mysecret.txt;N</code> refers to version N of <code class="literal">/mysecret.txt</code> and is essentially an alias.</li><li class="listitem">The clearcase software configuration management system provides a file system where <code class="literal">@@</code> in a file name is an alias to a specific version.</li><li class="listitem">The Unix files system supports <code class="literal">/./foo.txt</code> as and alias for <code class="literal">/foo.txt</code></li><li class="listitem">Many JVM implementations incorrectly assume the null character is a string terminator, so that a file name resulting from <code class="literal">/foobar.txt%00</code> is an alias for <code class="literal">/foobar.txt</code></li><li class="listitem">Unix symbolic links and hard links are a form of aliases that allow the same file or directory to have multiple names.</li></ul></div><p>In addition, it is not just URI security constraints that can be bypassed. For example the mapping of the URI pattern <code class="literal">*.jsp</code> to the JSP
Servlet may be bypassed by an a request to an alias like <code class="literal">/foobar.jsp%00</code>, thus rather than execute the JSP, the source code of the JSP is returned by the file system.</p><div class="section"><div class="titlepage"><div><div><h3 class="title"><a name="_good_security_practise"></a>Good Security Practise</h3></div></div></div><p>Part of the problem with aliases is that the standard web application security model is to allow all requests except the ones that are specifically denied by security constraints.
A best practice for security is to deny all requests and to permit only those that are specifically identified as allowable.
While it is possible to design web application security constraints in this style, it can be difficult in all circumstances and it is not the default. T
hus it is important for Jetty to be able to detect and deny requests to aliased static content.</p></div><div class="section"><div class="titlepage"><div><div><h3 class="title"><a name="file-alias-detection"></a>Alias detection</h3></div></div></div><p>It is impossible for Jetty to know of all the aliases that may be implemented by the file system running beneath it, thus it does not attempt to make any specific checks for any know aliases.
Instead Jetty detects aliases by using the canonical path of a file.
If a file resource handled by jetty has a canonical name that differs from the name used to request the resource, then Jetty determines that the resource is an aliased request and it will not be returned by the <code class="literal">ServletContext.getResource(String)</code> method (or similar) and thus will not be served as static content nor used as the basis of a JSP.</p><p>This if Jetty is running on a Windows operating system, then a file called <code class="literal">/MySecret.TXT</code> will have a canonical name that exactly matches that case.
So while a request to <code class="literal">/mysecret.txt</code> or <code class="literal">/MYSECR~1.TXT</code> will result in a File Resource that matches the file, the different canonical name will indicate that those requests are aliases and they will not be served as static content and instead a 404 response returned.</p><p>Unfortunately this approach denies all aliases, including symbolic links, which can be useful in assembling complex web applications.</p></div><div class="section"><div class="titlepage"><div><div><h3 class="title"><a name="file-alias-serving"></a>Serving Aliases and Symbolic Links</h3></div></div></div><p>Not all aliases are bad nor should be seen as attempts to subvert security constraints.
Specifically, symbolic links can be very useful when assembling complex web applications.
As such, Jetty contexts support an extensible <code class="literal">AliasCheck</code> mechanism to allow aliases resources to be inspected and conditionally served.
In this way, "good" aliases can be detected and served.
Jetty provides several utility implementations of the <code class="literal">AliasCheck</code> interface as nested classes with <code class="literal">ContextHandler</code>:</p><div class="variablelist"><dl class="variablelist"><dt><span class="term">ApproveAliases</span></dt><dd>Approve all aliases (<span class="strong"><strong>Use with caution!</strong></span>).</dd><dt><span class="term">AllowSymLinkAliasChecker</span></dt><dd>Approve Aliases using the java-7 <code class="literal">Files.readSymbolicLink(path)</code> and <code class="literal">Path.toRealPath(...)</code> APIs to check that aliases are valid symbolic links.</dd></dl></div><div class="blockquote"><blockquote class="blockquote"><div xmlns:jfetch="java:org.eclipse.jetty.xslt.tools.JavaSourceFetchExtension" xmlns:fetch="java:org.eclipse.jetty.xslt.tools.SourceFetchExtension" xmlns:d="http://docbook.org/ns/docbook" xmlns:l="http://docbook.sourceforge.net/xmlns/l10n/1.0" xmlns:xslthl="http://xslthl.sf.net" xmlns:gcse="http://www.google.com" xmlns:date="http://exslt.org/dates-and-times" class="note" style="margin-left: 0.5in; margin-right: 0.5in;"><h3 class="title"><i class="fa fa-asterisk" aria-hidden="true"></i> Note</h3><p>By default, Jetty serves aliased files for implementations running on UNIX as Contexts are created with both the <a class="link" href="http://www.eclipse.org/jetty/javadoc/9.4.28-SNAPSHOT/org/eclipse/jetty/server/handler/AllowSymLinkAliasChecker.html" target="_top"><code class="literal">AllowSymLinkAliasChecker</code></a> and <a class="link" href="http://www.eclipse.org/jetty/javadoc/9.4.28-SNAPSHOT/org/eclipse/jetty/server/handler/ContextHandler.ApproveNonExistentDirectoryAliases.html" target="_top"><code class="literal">ApproveNonExistentDirectoryAliases</code></a> alias checkers.</p></div></blockquote></div><p>An application is free to implement its own Alias checking.
Alias Checkers can be installed in a context via the following XML used in a context deployer file or <code class="literal">WEB-INF/jetty-web.xml</code>:</p><pre xmlns:jfetch="java:org.eclipse.jetty.xslt.tools.JavaSourceFetchExtension" xmlns:fetch="java:org.eclipse.jetty.xslt.tools.SourceFetchExtension" xmlns:d="http://docbook.org/ns/docbook" xmlns:l="http://docbook.sourceforge.net/xmlns/l10n/1.0" xmlns:xslthl="http://xslthl.sf.net" xmlns:gcse="http://www.google.com" xmlns:date="http://exslt.org/dates-and-times"><code> &lt;!-- Allow symbolic links --&gt;
&lt;Call name="addAliasCheck"&gt;
&lt;Arg&gt;&lt;New class="org.eclipse.jetty.server.handler.AllowSymLinkAliasChecker"/&gt;&lt;/Arg&gt;
&lt;/Call&gt;</code></pre></div></div><script type="text/javascript">
SyntaxHighlighter.all()
</script><div class="navfooter"><hr><table width="100%" summary="Navigation footer"><tr><td width="40%" align="left"><a accesskey="p" href="configuring-form-size.html"><i class="fa fa-chevron-left" aria-hidden="true"></i> Previous</a>&nbsp;</td><td width="20%" align="center"><a accesskey="u" href="configuring-security.html"><i class="fa fa-chevron-up" aria-hidden="true"></i> Top</a></td><td width="40%" align="right">&nbsp;<a accesskey="n" href="configuring-security-secure-passwords.html">Next <i class="fa fa-chevron-right" aria-hidden="true"></i></a></td></tr><tr><td width="40%" align="left" valign="top">Limiting Form Content&nbsp;</td><td width="20%" align="center"><a accesskey="h" href="index.html"><i class="fa fa-home" aria-hidden="true"></i> Home</a></td><td width="40%" align="right" valign="top">&nbsp;Secure Password Obfuscation</td></tr></table></div><p xmlns:jfetch="java:org.eclipse.jetty.xslt.tools.JavaSourceFetchExtension" xmlns:fetch="java:org.eclipse.jetty.xslt.tools.SourceFetchExtension" xmlns:d="http://docbook.org/ns/docbook" xmlns:l="http://docbook.sourceforge.net/xmlns/l10n/1.0" xmlns:xslthl="http://xslthl.sf.net" xmlns:gcse="http://www.google.com" xmlns:date="http://exslt.org/dates-and-times"><div class="jetty-callout">
See an error or something missing?
<span class="callout"><a href="http://github.com/eclipse/jetty.project">Contribute to this documentation at
<span class="website"><i class="fa fa-github" aria-hidden="true"></i> Github!</span></a></span><span style="float: right"><i>(Generated: 2020-03-10)</i></span></div></p></body></html>