570 lines
32 KiB
HTML
570 lines
32 KiB
HTML
<html><head><META http-equiv="Content-Type" content="text/html; charset=iso-8859-1"><title>Apache Tomcat 7 (7.0.108) - Security Manager HOW-TO</title><meta name="author" content="Glenn Nielsen"><meta name="author" content="Jean-Francois Arcand"><style type="text/css" media="print">
|
|
.noPrint {display: none;}
|
|
td#mainBody {width: 100%;}
|
|
</style><style type="text/css">
|
|
code {background-color:rgb(224,255,255);padding:0 0.1em;}
|
|
code.attributeName, code.propertyName {background-color:transparent;}
|
|
|
|
|
|
table {
|
|
border-collapse: collapse;
|
|
text-align: left;
|
|
}
|
|
table *:not(table) {
|
|
/* Prevent border-collapsing for table child elements like <div> */
|
|
border-collapse: separate;
|
|
}
|
|
|
|
th {
|
|
text-align: left;
|
|
}
|
|
|
|
|
|
div.codeBox pre code, code.attributeName, code.propertyName, code.noHighlight, .noHighlight code {
|
|
background-color: transparent;
|
|
}
|
|
div.codeBox {
|
|
overflow: auto;
|
|
margin: 1em 0;
|
|
}
|
|
div.codeBox pre {
|
|
margin: 0;
|
|
padding: 4px;
|
|
border: 1px solid #999;
|
|
border-radius: 5px;
|
|
background-color: #eff8ff;
|
|
display: table; /* To prevent <pre>s from taking the complete available width. */
|
|
/*
|
|
When it is officially supported, use the following CSS instead of display: table
|
|
to prevent big <pre>s from exceeding the browser window:
|
|
max-width: available;
|
|
width: min-content;
|
|
*/
|
|
}
|
|
|
|
div.codeBox pre.wrap {
|
|
white-space: pre-wrap;
|
|
}
|
|
|
|
|
|
table.defaultTable tr, table.detail-table tr {
|
|
border: 1px solid #CCC;
|
|
}
|
|
|
|
table.defaultTable tr:nth-child(even), table.detail-table tr:nth-child(even) {
|
|
background-color: #FAFBFF;
|
|
}
|
|
|
|
table.defaultTable tr:nth-child(odd), table.detail-table tr:nth-child(odd) {
|
|
background-color: #EEEFFF;
|
|
}
|
|
|
|
table.defaultTable th, table.detail-table th {
|
|
background-color: #88b;
|
|
color: #fff;
|
|
}
|
|
|
|
table.defaultTable th, table.defaultTable td, table.detail-table th, table.detail-table td {
|
|
padding: 5px 8px;
|
|
}
|
|
|
|
|
|
p.notice {
|
|
border: 1px solid rgb(255, 0, 0);
|
|
background-color: rgb(238, 238, 238);
|
|
color: rgb(0, 51, 102);
|
|
padding: 0.5em;
|
|
margin: 1em 2em 1em 1em;
|
|
}
|
|
</style></head><body bgcolor="#ffffff" text="#000000" link="#525D76" alink="#525D76" vlink="#525D76"><table border="0" width="100%" cellspacing="0"><!--PAGE HEADER--><tr><td><!--PROJECT LOGO--><a href="https://tomcat.apache.org/"><img src="./images/tomcat.gif" align="right" alt="
|
|
The Apache Tomcat Servlet/JSP Container
|
|
" border="0"></a></td><td><h1><font face="arial,helvetica,sanserif">Apache Tomcat 7</font></h1><font face="arial,helvetica,sanserif">Version 7.0.108, Jan 28 2021</font></td><td><!--APACHE LOGO--><a href="http://www.apache.org/"><img src="./images/asf-logo.svg" align="right" alt="Apache Logo" border="0" style="width: 266px;height: 83px;"></a></td></tr></table><table border="0" width="100%" cellspacing="4"><!--HEADER SEPARATOR--><tr><td colspan="2"><hr noshade size="1"></td></tr><tr><!--LEFT SIDE NAVIGATION--><td width="20%" valign="top" nowrap class="noPrint"><p><strong>Links</strong></p><ul><li><a href="index.html">Docs Home</a></li><li><a href="https://wiki.apache.org/tomcat/FAQ">FAQ</a></li><li><a href="#comments_section">User Comments</a></li></ul><p><strong>User Guide</strong></p><ul><li><a href="introduction.html">1) Introduction</a></li><li><a href="setup.html">2) Setup</a></li><li><a href="appdev/index.html">3) First webapp</a></li><li><a href="deployer-howto.html">4) Deployer</a></li><li><a href="manager-howto.html">5) Manager</a></li><li><a href="host-manager-howto.html">6) Host Manager</a></li><li><a href="realm-howto.html">7) Realms and AAA</a></li><li><a href="security-manager-howto.html">8) Security Manager</a></li><li><a href="jndi-resources-howto.html">9) JNDI Resources</a></li><li><a href="jndi-datasource-examples-howto.html">10) JDBC DataSources</a></li><li><a href="class-loader-howto.html">11) Classloading</a></li><li><a href="jasper-howto.html">12) JSPs</a></li><li><a href="ssl-howto.html">13) SSL/TLS</a></li><li><a href="ssi-howto.html">14) SSI</a></li><li><a href="cgi-howto.html">15) CGI</a></li><li><a href="proxy-howto.html">16) Proxy Support</a></li><li><a href="mbeans-descriptors-howto.html">17) MBeans Descriptors</a></li><li><a href="default-servlet.html">18) Default Servlet</a></li><li><a href="cluster-howto.html">19) Clustering</a></li><li><a href="balancer-howto.html">20) Load Balancer</a></li><li><a href="connectors.html">21) Connectors</a></li><li><a href="monitoring.html">22) Monitoring and Management</a></li><li><a href="logging.html">23) Logging</a></li><li><a href="apr.html">24) APR/Native</a></li><li><a href="virtual-hosting-howto.html">25) Virtual Hosting</a></li><li><a href="aio.html">26) Advanced IO</a></li><li><a href="extras.html">27) Additional Components</a></li><li><a href="maven-jars.html">28) Mavenized</a></li><li><a href="security-howto.html">29) Security Considerations</a></li><li><a href="windows-service-howto.html">30) Windows Service</a></li><li><a href="windows-auth-howto.html">31) Windows Authentication</a></li><li><a href="jdbc-pool.html">32) Tomcat's JDBC Pool</a></li><li><a href="web-socket-howto.html">33) WebSocket</a></li></ul><p><strong>Reference</strong></p><ul><li><a href="RELEASE-NOTES.txt">Release Notes</a></li><li><a href="config/index.html">Configuration</a></li><li><a href="api/index.html">Tomcat Javadocs</a></li><li><a href="servletapi/index.html">Servlet Javadocs</a></li><li><a href="jspapi/index.html">JSP 2.2 Javadocs</a></li><li><a href="elapi/index.html">EL 2.2 Javadocs</a></li><li><a href="websocketapi/index.html">WebSocket 1.1 Javadocs</a></li><li><a href="annotationapi/index.html">Common Annotations 1.1 Javadocs</a></li><li><a href="https://tomcat.apache.org/connectors-doc/">JK 1.2 Documentation</a></li></ul><p><strong>Apache Tomcat Development</strong></p><ul><li><a href="building.html">Building</a></li><li><a href="changelog.html">Changelog</a></li><li><a href="https://wiki.apache.org/tomcat/TomcatVersions">Status</a></li><li><a href="developers.html">Developers</a></li><li><a href="architecture/index.html">Architecture</a></li><li><a href="tribes/introduction.html">Tribes</a></li></ul></td><!--RIGHT SIDE MAIN BODY--><td width="80%" valign="top" align="left" id="mainBody"><h1>Security Manager HOW-TO</h1><table border="0" cellspacing="0" cellpadding="2"><tr><td bgcolor="#525D76"><font color="#ffffff" face="arial,helvetica.sanserif"><a name="Table of Contents"><!--()--></a><a name="Table_of_Contents"><strong>Table of Contents</strong></a></font></td></tr><tr><td><blockquote>
|
|
<ul><li><a href="#Background">Background</a></li><li><a href="#Permissions">Permissions</a><ol><li><a href="#Standard_Permissions">Standard Permissions</a></li><li><a href="#Tomcat_Custom_Permissions">Tomcat Custom Permissions</a></li></ol></li><li><a href="#Configuring_Tomcat_With_A_SecurityManager">Configuring Tomcat With A SecurityManager</a></li><li><a href="#Configuring_Package_Protection_in_Tomcat">Configuring Package Protection in Tomcat</a></li><li><a href="#Troubleshooting">Troubleshooting</a></li></ul>
|
|
</blockquote></td></tr></table><table border="0" cellspacing="0" cellpadding="2"><tr><td bgcolor="#525D76"><font color="#ffffff" face="arial,helvetica.sanserif"><a name="Background"><strong>Background</strong></a></font></td></tr><tr><td><blockquote>
|
|
|
|
<p>The Java <strong>SecurityManager</strong> is what allows a web browser
|
|
to run an applet in its own sandbox to prevent untrusted code from
|
|
accessing files on the local file system, connecting to a host other
|
|
than the one the applet was loaded from, and so on. In the same way
|
|
the SecurityManager protects you from an untrusted applet running in
|
|
your browser, use of a SecurityManager while running Tomcat can protect
|
|
your server from trojan servlets, JSPs, JSP beans, and tag libraries.
|
|
Or even inadvertent mistakes.</p>
|
|
|
|
<p>Imagine if someone who is authorized to publish JSPs on your site
|
|
inadvertently included the following in their JSP:</p>
|
|
<div class="codeBox"><pre><code>
|
|
<% System.exit(1); %>
|
|
</code></pre></div>
|
|
|
|
<p>Every time this JSP was executed by Tomcat, Tomcat would exit.
|
|
Using the Java SecurityManager is just one more line of defense a
|
|
system administrator can use to keep the server secure and reliable.</p>
|
|
|
|
<p><strong>WARNING</strong> - A security audit
|
|
have been conducted using the Tomcat codebase. Most of the critical
|
|
package have been protected and a new security package protection mechanism
|
|
has been implemented. Still, make sure that you are satisfied with your SecurityManager
|
|
configuration before allowing untrusted users to publish web applications,
|
|
JSPs, servlets, beans, or tag libraries. <strong>However, running with a
|
|
SecurityManager is definitely better than running without one.</strong></p>
|
|
|
|
</blockquote></td></tr></table><table border="0" cellspacing="0" cellpadding="2"><tr><td bgcolor="#525D76"><font color="#ffffff" face="arial,helvetica.sanserif"><a name="Permissions"><strong>Permissions</strong></a></font></td></tr><tr><td><blockquote>
|
|
|
|
<p>Permission classes are used to define what Permissions a class loaded
|
|
by Tomcat will have. There are a number of Permission classes that are
|
|
a standard part of the JDK, and you can create your own Permission class
|
|
for use in your own web applications. Both techniques are used in
|
|
Tomcat.</p>
|
|
|
|
|
|
<table border="0" cellspacing="0" cellpadding="2"><tr><td bgcolor="#828DA6"><font color="#ffffff" face="arial,helvetica.sanserif"><a name="Standard Permissions"><!--()--></a><a name="Standard_Permissions"><strong>Standard Permissions</strong></a></font></td></tr><tr><td><blockquote>
|
|
|
|
<p>This is just a short summary of the standard system SecurityManager
|
|
Permission classes applicable to Tomcat. See
|
|
<a href="http://docs.oracle.com/javase/7/docs/technotes/guides/security/">
|
|
http://docs.oracle.com/javase/7/docs/technotes/guides/security/</a>
|
|
for more information.</p>
|
|
|
|
<ul>
|
|
<li><strong>java.util.PropertyPermission</strong> - Controls read/write
|
|
access to JVM properties such as <code>java.home</code>.</li>
|
|
<li><strong>java.lang.RuntimePermission</strong> - Controls use of
|
|
some System/Runtime functions like <code>exit()</code> and
|
|
<code>exec()</code>. Also control the package access/definition.</li>
|
|
<li><strong>java.io.FilePermission</strong> - Controls read/write/execute
|
|
access to files and directories.</li>
|
|
<li><strong>java.net.SocketPermission</strong> - Controls use of
|
|
network sockets.</li>
|
|
<li><strong>java.net.NetPermission</strong> - Controls use of
|
|
multicast network connections.</li>
|
|
<li><strong>java.lang.reflect.ReflectPermission</strong> - Controls
|
|
use of reflection to do class introspection.</li>
|
|
<li><strong>java.security.SecurityPermission</strong> - Controls access
|
|
to Security methods.</li>
|
|
<li><strong>java.security.AllPermission</strong> - Allows access to all
|
|
permissions, just as if you were running Tomcat without a
|
|
SecurityManager.</li>
|
|
</ul>
|
|
|
|
</blockquote></td></tr></table>
|
|
|
|
|
|
<table border="0" cellspacing="0" cellpadding="2"><tr><td bgcolor="#828DA6"><font color="#ffffff" face="arial,helvetica.sanserif"><a name="Tomcat Custom Permissions"><!--()--></a><a name="Tomcat_Custom_Permissions"><strong>Tomcat Custom Permissions</strong></a></font></td></tr><tr><td><blockquote>
|
|
|
|
<p>Tomcat utilizes a custom permission class called
|
|
<strong>org.apache.naming.JndiPermission</strong>. This permission
|
|
controls read access to JNDI named file based resources. The permission
|
|
name is the JNDI name and there are no actions. A trailing "*" can be
|
|
used to do wild card matching for a JNDI named file resource when
|
|
granting permission. For example, you might include the following
|
|
in your policy file:</p>
|
|
<div class="codeBox"><pre><code>
|
|
permission org.apache.naming.JndiPermission "jndi://localhost/examples/*";
|
|
</code></pre></div>
|
|
|
|
<p>A Permission entry like this is generated dynamically for each web
|
|
application that is deployed, to allow it to read its own static resources
|
|
but disallow it from using file access to read any other files (unless
|
|
permissions for those files are explicitly granted).</p>
|
|
|
|
<p>Also, Tomcat always dynamically creates the following file permissions:</p>
|
|
<div class="codeBox"><pre><code>
|
|
permission java.io.FilePermission "** your application context**", "read";
|
|
|
|
permission java.io.FilePermission
|
|
"** application working directory**", "read,write";
|
|
permission java.io.FilePermission
|
|
"** application working directory**/-", "read,write,delete";
|
|
</code></pre></div>
|
|
<p>Where **your application context** equals the folder (or WAR file) under which
|
|
your application has been deployed and **application working directory** is the
|
|
temporary directory provided to your application as required by the
|
|
Servlet Specification.</p>
|
|
|
|
</blockquote></td></tr></table>
|
|
|
|
|
|
</blockquote></td></tr></table><table border="0" cellspacing="0" cellpadding="2"><tr><td bgcolor="#525D76"><font color="#ffffff" face="arial,helvetica.sanserif"><a name="Configuring Tomcat With A SecurityManager"><!--()--></a><a name="Configuring_Tomcat_With_A_SecurityManager"><strong>Configuring Tomcat With A SecurityManager</strong></a></font></td></tr><tr><td><blockquote>
|
|
|
|
<h3>Policy File Format</h3>
|
|
|
|
<p>The security policies implemented by the Java SecurityManager are
|
|
configured in the <code>$CATALINA_BASE/conf/catalina.policy</code> file.
|
|
This file completely replaces the <code>java.policy</code> file present
|
|
in your JDK system directories. The <code>catalina.policy</code> file
|
|
can be edited by hand, or you can use the
|
|
<a href="http://docs.oracle.com/javase/6/docs/technotes/guides/security/PolicyGuide.html">policytool</a>
|
|
application that comes with Java 1.2 or later.</p>
|
|
|
|
<p>Entries in the <code>catalina.policy</code> file use the standard
|
|
<code>java.policy</code> file format, as follows:</p>
|
|
<div class="codeBox"><pre><code>
|
|
// Example policy file entry
|
|
|
|
grant [signedBy <signer>,] [codeBase <code source>] {
|
|
permission <class> [<name> [, <action list>]];
|
|
};
|
|
</code></pre></div>
|
|
|
|
<p>The <strong>signedBy</strong> and <strong>codeBase</strong> entries are
|
|
optional when granting permissions. Comment lines begin with "//" and
|
|
end at the end of the current line. The <code>codeBase</code> is in the
|
|
form of a URL, and for a file URL can use the <code>${java.home}</code>
|
|
and <code>${catalina.home}</code> properties (which are expanded out to
|
|
the directory paths defined for them by the <code>JAVA_HOME</code>,
|
|
<code>CATALINA_HOME</code> and <code>CATALINA_BASE</code> environment
|
|
variables).</p>
|
|
|
|
<h3>The Default Policy File</h3>
|
|
|
|
<p>The default <code>$CATALINA_BASE/conf/catalina.policy</code> file
|
|
looks like this:</p>
|
|
|
|
|
|
<div class="codeBox"><pre><code>// Licensed to the Apache Software Foundation (ASF) under one or more
|
|
// contributor license agreements. See the NOTICE file distributed with
|
|
// this work for additional information regarding copyright ownership.
|
|
// The ASF licenses this file to You under the Apache License, Version 2.0
|
|
// (the "License"); you may not use this file except in compliance with
|
|
// the License. You may obtain a copy of the License at
|
|
//
|
|
// http://www.apache.org/licenses/LICENSE-2.0
|
|
//
|
|
// Unless required by applicable law or agreed to in writing, software
|
|
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
// See the License for the specific language governing permissions and
|
|
// limitations under the License.
|
|
|
|
// ============================================================================
|
|
// catalina.policy - Security Policy Permissions for Tomcat 7
|
|
//
|
|
// This file contains a default set of security policies to be enforced (by the
|
|
// JVM) when Catalina is executed with the "-security" option. In addition
|
|
// to the permissions granted here, the following additional permissions are
|
|
// granted to each web application:
|
|
//
|
|
// * Read access to the web application's document root directory
|
|
// * Read, write and delete access to the web application's working directory
|
|
// ============================================================================
|
|
|
|
|
|
// ========== SYSTEM CODE PERMISSIONS =========================================
|
|
|
|
|
|
// These permissions apply to javac
|
|
grant codeBase "file:${java.home}/lib/-" {
|
|
permission java.security.AllPermission;
|
|
};
|
|
|
|
// These permissions apply to all shared system extensions
|
|
grant codeBase "file:${java.home}/jre/lib/ext/-" {
|
|
permission java.security.AllPermission;
|
|
};
|
|
|
|
// These permissions apply to javac when ${java.home} points at $JAVA_HOME/jre
|
|
grant codeBase "file:${java.home}/../lib/-" {
|
|
permission java.security.AllPermission;
|
|
};
|
|
|
|
// These permissions apply to all shared system extensions when
|
|
// ${java.home} points at $JAVA_HOME/jre
|
|
grant codeBase "file:${java.home}/lib/ext/-" {
|
|
permission java.security.AllPermission;
|
|
};
|
|
|
|
|
|
// ========== CATALINA CODE PERMISSIONS =======================================
|
|
|
|
|
|
// These permissions apply to the daemon code
|
|
grant codeBase "file:${catalina.home}/bin/commons-daemon.jar" {
|
|
permission java.security.AllPermission;
|
|
};
|
|
|
|
// These permissions apply to the logging API
|
|
// Note: If tomcat-juli.jar is in ${catalina.base} and not in ${catalina.home},
|
|
// update this section accordingly.
|
|
// grant codeBase "file:${catalina.base}/bin/tomcat-juli.jar" {..}
|
|
grant codeBase "file:${catalina.home}/bin/tomcat-juli.jar" {
|
|
permission java.io.FilePermission
|
|
"${java.home}${file.separator}lib${file.separator}logging.properties", "read";
|
|
|
|
permission java.io.FilePermission
|
|
"${catalina.base}${file.separator}conf${file.separator}logging.properties", "read";
|
|
permission java.io.FilePermission
|
|
"${catalina.base}${file.separator}logs", "read, write";
|
|
permission java.io.FilePermission
|
|
"${catalina.base}${file.separator}logs${file.separator}*", "read, write, delete";
|
|
|
|
permission java.lang.RuntimePermission "shutdownHooks";
|
|
permission java.lang.RuntimePermission "getClassLoader";
|
|
permission java.lang.RuntimePermission "setContextClassLoader";
|
|
|
|
permission java.util.logging.LoggingPermission "control";
|
|
|
|
permission java.util.PropertyPermission "java.util.logging.config.class", "read";
|
|
permission java.util.PropertyPermission "java.util.logging.config.file", "read";
|
|
permission java.util.PropertyPermission "org.apache.juli.ClassLoaderLogManager.debug", "read";
|
|
permission java.util.PropertyPermission "catalina.base", "read";
|
|
|
|
// Note: To enable per context logging configuration, permit read access to
|
|
// the appropriate file. Be sure that the logging configuration is
|
|
// secure before enabling such access.
|
|
// E.g. for the examples web application (uncomment and unwrap
|
|
// the following to be on a single line):
|
|
// permission java.io.FilePermission "${catalina.base}${file.separator}
|
|
// webapps${file.separator}examples${file.separator}WEB-INF
|
|
// ${file.separator}classes${file.separator}logging.properties", "read";
|
|
};
|
|
|
|
// These permissions apply to the server startup code
|
|
grant codeBase "file:${catalina.home}/bin/bootstrap.jar" {
|
|
permission java.security.AllPermission;
|
|
};
|
|
|
|
// These permissions apply to the servlet API classes
|
|
// and those that are shared across all class loaders
|
|
// located in the "lib" directory
|
|
grant codeBase "file:${catalina.home}/lib/-" {
|
|
permission java.security.AllPermission;
|
|
};
|
|
|
|
|
|
// If using a per instance lib directory, i.e. ${catalina.base}/lib,
|
|
// then the following permission will need to be uncommented
|
|
// grant codeBase "file:${catalina.base}/lib/-" {
|
|
// permission java.security.AllPermission;
|
|
// };
|
|
|
|
|
|
// ========== WEB APPLICATION PERMISSIONS =====================================
|
|
|
|
|
|
// These permissions are granted by default to all web applications
|
|
// In addition, a web application will be given a read FilePermission
|
|
// and JndiPermission for all files and directories in its document root.
|
|
grant {
|
|
// Required for JNDI lookup of named JDBC DataSource's and
|
|
// javamail named MimePart DataSource used to send mail
|
|
permission java.util.PropertyPermission "java.home", "read";
|
|
permission java.util.PropertyPermission "java.naming.*", "read";
|
|
permission java.util.PropertyPermission "javax.sql.*", "read";
|
|
|
|
// OS Specific properties to allow read access
|
|
permission java.util.PropertyPermission "os.name", "read";
|
|
permission java.util.PropertyPermission "os.version", "read";
|
|
permission java.util.PropertyPermission "os.arch", "read";
|
|
permission java.util.PropertyPermission "file.separator", "read";
|
|
permission java.util.PropertyPermission "path.separator", "read";
|
|
permission java.util.PropertyPermission "line.separator", "read";
|
|
|
|
// JVM properties to allow read access
|
|
permission java.util.PropertyPermission "java.version", "read";
|
|
permission java.util.PropertyPermission "java.vendor", "read";
|
|
permission java.util.PropertyPermission "java.vendor.url", "read";
|
|
permission java.util.PropertyPermission "java.class.version", "read";
|
|
permission java.util.PropertyPermission "java.specification.version", "read";
|
|
permission java.util.PropertyPermission "java.specification.vendor", "read";
|
|
permission java.util.PropertyPermission "java.specification.name", "read";
|
|
|
|
permission java.util.PropertyPermission "java.vm.specification.version", "read";
|
|
permission java.util.PropertyPermission "java.vm.specification.vendor", "read";
|
|
permission java.util.PropertyPermission "java.vm.specification.name", "read";
|
|
permission java.util.PropertyPermission "java.vm.version", "read";
|
|
permission java.util.PropertyPermission "java.vm.vendor", "read";
|
|
permission java.util.PropertyPermission "java.vm.name", "read";
|
|
|
|
// Required for OpenJMX
|
|
permission java.lang.RuntimePermission "getAttribute";
|
|
|
|
// Allow read of JAXP compliant XML parser debug
|
|
permission java.util.PropertyPermission "jaxp.debug", "read";
|
|
|
|
// All JSPs need to be able to read this package
|
|
permission java.lang.RuntimePermission "accessClassInPackage.org.apache.tomcat";
|
|
|
|
// Precompiled JSPs need access to these packages.
|
|
permission java.lang.RuntimePermission "accessClassInPackage.org.apache.jasper.el";
|
|
permission java.lang.RuntimePermission "accessClassInPackage.org.apache.jasper.runtime";
|
|
permission java.lang.RuntimePermission
|
|
"accessClassInPackage.org.apache.jasper.runtime.*";
|
|
|
|
// Precompiled JSPs need access to these system properties.
|
|
|
|
// The following two permissions are no longer needed since Tomcat 7.0.88
|
|
// They are here for historic reasons. There is no harm in keeping them.
|
|
permission java.util.PropertyPermission
|
|
"org.apache.jasper.runtime.BodyContentImpl.LIMIT_BUFFER", "read";
|
|
permission java.util.PropertyPermission
|
|
"org.apache.el.parser.COERCE_TO_ZERO", "read";
|
|
|
|
// The cookie code needs these.
|
|
permission java.util.PropertyPermission
|
|
"org.apache.catalina.STRICT_SERVLET_COMPLIANCE", "read";
|
|
permission java.util.PropertyPermission
|
|
"org.apache.tomcat.util.http.ServerCookie.STRICT_NAMING", "read";
|
|
permission java.util.PropertyPermission
|
|
"org.apache.tomcat.util.http.ServerCookie.FWD_SLASH_IS_SEPARATOR", "read";
|
|
|
|
// Applications using Comet need to be able to access this package
|
|
permission java.lang.RuntimePermission "accessClassInPackage.org.apache.catalina.comet";
|
|
|
|
// Applications using the legacy WebSocket implementation need to be able to access this package
|
|
permission java.lang.RuntimePermission "accessClassInPackage.org.apache.catalina.websocket";
|
|
|
|
// Applications using the JSR-356 WebSocket implementation need to be able to access these packages
|
|
permission java.lang.RuntimePermission "accessClassInPackage.org.apache.tomcat.websocket";
|
|
permission java.lang.RuntimePermission "accessClassInPackage.org.apache.tomcat.websocket.server";
|
|
};
|
|
|
|
|
|
// The Manager application needs access to the following packages to support the
|
|
// session display functionality. It also requires the custom Tomcat
|
|
// DeployXmlPermission to enable the use of META-INF/context.xml
|
|
// These settings support the following configurations:
|
|
// - default CATALINA_HOME == CATALINA_BASE
|
|
// - CATALINA_HOME != CATALINA_BASE, per instance Manager in CATALINA_BASE
|
|
// - CATALINA_HOME != CATALINA_BASE, shared Manager in CATALINA_HOME
|
|
grant codeBase "file:${catalina.base}/webapps/manager/-" {
|
|
permission java.lang.RuntimePermission "accessClassInPackage.org.apache.catalina";
|
|
permission java.lang.RuntimePermission "accessClassInPackage.org.apache.catalina.ha.session";
|
|
permission java.lang.RuntimePermission "accessClassInPackage.org.apache.catalina.manager";
|
|
permission java.lang.RuntimePermission "accessClassInPackage.org.apache.catalina.manager.util";
|
|
permission java.lang.RuntimePermission "accessClassInPackage.org.apache.catalina.util";
|
|
permission org.apache.catalina.security.DeployXmlPermission "manager";
|
|
};
|
|
grant codeBase "file:${catalina.home}/webapps/manager/-" {
|
|
permission java.lang.RuntimePermission "accessClassInPackage.org.apache.catalina";
|
|
permission java.lang.RuntimePermission "accessClassInPackage.org.apache.catalina.ha.session";
|
|
permission java.lang.RuntimePermission "accessClassInPackage.org.apache.catalina.manager";
|
|
permission java.lang.RuntimePermission "accessClassInPackage.org.apache.catalina.manager.util";
|
|
permission java.lang.RuntimePermission "accessClassInPackage.org.apache.catalina.util";
|
|
permission org.apache.catalina.security.DeployXmlPermission "manager";
|
|
};
|
|
|
|
// The Host Manager application needs the custom Tomcat DeployXmlPermission to
|
|
// enable the use of META-INF/context.xml
|
|
// These settings support the following configurations:
|
|
// - default CATALINA_HOME == CATALINA_BASE
|
|
// - CATALINA_HOME != CATALINA_BASE, per instance Host Manager in CATALINA_BASE
|
|
// - CATALINA_HOME != CATALINA_BASE, shared Host Manager in CATALINA_HOME
|
|
grant codeBase "file:${catalina.base}/webapps/host-manager/-" {
|
|
permission org.apache.catalina.security.DeployXmlPermission "host-manager";
|
|
};
|
|
grant codeBase "file:${catalina.home}/webapps/host-manager/-" {
|
|
permission org.apache.catalina.security.DeployXmlPermission "host-manager";
|
|
};
|
|
|
|
|
|
// You can assign additional permissions to particular web applications by
|
|
// adding additional "grant" entries here, based on the code base for that
|
|
// application, /WEB-INF/classes/, or /WEB-INF/lib/ jar files.
|
|
//
|
|
// Different permissions can be granted to JSP pages, classes loaded from
|
|
// the /WEB-INF/classes/ directory, all jar files in the /WEB-INF/lib/
|
|
// directory, or even to individual jar files in the /WEB-INF/lib/ directory.
|
|
//
|
|
// For instance, assume that the standard "examples" application
|
|
// included a JDBC driver that needed to establish a network connection to the
|
|
// corresponding database and used the scrape taglib to get the weather from
|
|
// the NOAA web server. You might create a "grant" entries like this:
|
|
//
|
|
// The permissions granted to the context root directory apply to JSP pages.
|
|
// grant codeBase "file:${catalina.base}/webapps/examples/-" {
|
|
// permission java.net.SocketPermission "dbhost.mycompany.com:5432", "connect";
|
|
// permission java.net.SocketPermission "*.noaa.gov:80", "connect";
|
|
// };
|
|
//
|
|
// The permissions granted to the context WEB-INF/classes directory
|
|
// grant codeBase "file:${catalina.base}/webapps/examples/WEB-INF/classes/-" {
|
|
// };
|
|
//
|
|
// The permission granted to your JDBC driver
|
|
// grant codeBase "jar:file:${catalina.base}/webapps/examples/WEB-INF/lib/driver.jar!/-" {
|
|
// permission java.net.SocketPermission "dbhost.mycompany.com:5432", "connect";
|
|
// };
|
|
// The permission granted to the scrape taglib
|
|
// grant codeBase "jar:file:${catalina.base}/webapps/examples/WEB-INF/lib/scrape.jar!/-" {
|
|
// permission java.net.SocketPermission "*.noaa.gov:80", "connect";
|
|
// };
|
|
|
|
</code></pre></div>
|
|
|
|
<h3>Starting Tomcat With A SecurityManager</h3>
|
|
|
|
<p>Once you have configured the <code>catalina.policy</code> file for use
|
|
with a SecurityManager, Tomcat can be started with a SecurityManager in
|
|
place by using the "-security" option:</p>
|
|
<div class="codeBox"><pre><code>
|
|
$CATALINA_HOME/bin/catalina.sh start -security (Unix)
|
|
%CATALINA_HOME%\bin\catalina start -security (Windows)
|
|
</code></pre></div>
|
|
|
|
</blockquote></td></tr></table><table border="0" cellspacing="0" cellpadding="2"><tr><td bgcolor="#525D76"><font color="#ffffff" face="arial,helvetica.sanserif"><a name="Configuring Package Protection in Tomcat"><!--()--></a><a name="Configuring_Package_Protection_in_Tomcat"><strong>Configuring Package Protection in Tomcat</strong></a></font></td></tr><tr><td><blockquote>
|
|
<p>Starting with Tomcat 5, it is now possible to configure which Tomcat
|
|
internal package are protected against package definition and access. See
|
|
<a href="http://www.oracle.com/technetwork/java/seccodeguide-139067.html">
|
|
http://www.oracle.com/technetwork/java/seccodeguide-139067.html</a>
|
|
for more information.</p>
|
|
|
|
|
|
<p><strong>WARNING</strong>: Be aware that removing the default package protection
|
|
could possibly open a security hole</p>
|
|
|
|
<h3>The Default Properties File</h3>
|
|
|
|
<p>The default <code>$CATALINA_BASE/conf/catalina.properties</code> file
|
|
looks like this:</p>
|
|
<div class="codeBox"><pre><code>
|
|
#
|
|
# List of comma-separated packages that start with or equal this string
|
|
# will cause a security exception to be thrown when
|
|
# passed to checkPackageAccess unless the
|
|
# corresponding RuntimePermission ("accessClassInPackage."+package) has
|
|
# been granted.
|
|
package.access=sun.,org.apache.catalina.,org.apache.coyote.,org.apache.tomcat.,
|
|
org.apache.jasper.
|
|
#
|
|
# List of comma-separated packages that start with or equal this string
|
|
# will cause a security exception to be thrown when
|
|
# passed to checkPackageDefinition unless the
|
|
# corresponding RuntimePermission ("defineClassInPackage."+package) has
|
|
# been granted.
|
|
#
|
|
# by default, no packages are restricted for definition, and none of
|
|
# the class loaders supplied with the JDK call checkPackageDefinition.
|
|
#
|
|
package.definition=sun.,java.,org.apache.catalina.,org.apache.coyote.,
|
|
org.apache.tomcat.,org.apache.jasper.
|
|
</code></pre></div>
|
|
<p>Once you have configured the <code>catalina.properties</code> file for use
|
|
with a SecurityManager, remember to re-start Tomcat.</p>
|
|
</blockquote></td></tr></table><table border="0" cellspacing="0" cellpadding="2"><tr><td bgcolor="#525D76"><font color="#ffffff" face="arial,helvetica.sanserif"><a name="Troubleshooting"><strong>Troubleshooting</strong></a></font></td></tr><tr><td><blockquote>
|
|
|
|
<p>If your web application attempts to execute an operation that is
|
|
prohibited by lack of a required Permission, it will throw an
|
|
<code>AccessControLException</code> or a <code>SecurityException</code>
|
|
when the SecurityManager detects the violation. Debugging the permission
|
|
that is missing can be challenging, and one option is to turn on debug
|
|
output of all security decisions that are made during execution. This
|
|
is done by setting a system property before starting Tomcat. The easiest
|
|
way to do this is via the <code>CATALINA_OPTS</code> environment variable.
|
|
Execute this command:</p>
|
|
<div class="codeBox"><pre><code>
|
|
export CATALINA_OPTS=-Djava.security.debug=all (Unix)
|
|
set CATALINA_OPTS=-Djava.security.debug=all (Windows)
|
|
</code></pre></div>
|
|
|
|
<p>before starting Tomcat.</p>
|
|
|
|
<p><strong>WARNING</strong> - This will generate <em>many megabytes</em>
|
|
of output! However, it can help you track down problems by searching
|
|
for the word "FAILED" and determining which permission was being checked
|
|
for. See the Java security documentation for more options that you can
|
|
specify here as well.</p>
|
|
|
|
</blockquote></td></tr></table></td></tr><!--FOOTER SEPARATOR--><tr><td colspan="2"><hr noshade size="1"></td></tr><!--PAGE FOOTER--><tr><td colspan="2"><div align="center"><font color="#525D76" size="-1"><em>
|
|
Copyright © 1999-2021, Apache Software Foundation
|
|
</em></font></div></td></tr></table></body></html> |