Path: blob/master/src/java.base/share/classes/java/net/NetPermission.java
41152 views
/*1* Copyright (c) 1997, 2020, Oracle and/or its affiliates. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation. Oracle designates this7* particular file as subject to the "Classpath" exception as provided8* by Oracle in the LICENSE file that accompanied this code.9*10* This code is distributed in the hope that it will be useful, but WITHOUT11* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or12* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License13* version 2 for more details (a copy is included in the LICENSE file that14* accompanied this code).15*16* You should have received a copy of the GNU General Public License version17* 2 along with this work; if not, write to the Free Software Foundation,18* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.19*20* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA21* or visit www.oracle.com if you need additional information or have any22* questions.23*/2425package java.net;2627import java.security.*;28import java.util.Enumeration;29import java.util.Hashtable;30import java.util.StringTokenizer;3132/**33* This class is for various network permissions.34* A NetPermission contains a name (also referred to as a "target name") but35* no actions list; you either have the named permission36* or you don't.37* <P>38* The target name is the name of the network permission (see below). The naming39* convention follows the hierarchical property naming convention.40* Also, an asterisk41* may appear at the end of the name, following a ".", or by itself, to42* signify a wildcard match. For example: "foo.*" and "*" signify a wildcard43* match, while "*foo" and "a*b" do not.44* <P>45* The following table lists the standard NetPermission target names,46* and for each provides a description of what the permission allows47* and a discussion of the risks of granting code the permission.48*49* <table class="striped">50* <caption style="display:none">Permission target name, what the permission allows, and associated risks</caption>51* <thead>52* <tr>53* <th scope="col">Permission Target Name</th>54* <th scope="col">What the Permission Allows</th>55* <th scope="col">Risks of Allowing this Permission</th>56* </tr>57* </thead>58* <tbody>59* <tr>60* <th scope="row">allowHttpTrace</th>61* <td>The ability to use the HTTP TRACE method in HttpURLConnection.</td>62* <td>Malicious code using HTTP TRACE could get access to security sensitive63* information in the HTTP headers (such as cookies) that it might not64* otherwise have access to.</td>65* </tr>66*67* <tr>68* <th scope="row">accessUnixDomainSocket</th>69* <td>The ability to accept, bind, connect or get the local address70* of a <i>Unix Domain</i> socket.71* </td>72* <td>Malicious code could connect to local processes using Unix domain sockets73* or impersonate local processes, by binding to the same pathnames (assuming they74* have the required Operating System permissions.</td>75* </tr>76*77* <tr>78* <th scope="row">getCookieHandler</th>79* <td>The ability to get the cookie handler that processes highly80* security sensitive cookie information for an Http session.</td>81* <td>Malicious code can get a cookie handler to obtain access to82* highly security sensitive cookie information. Some web servers83* use cookies to save user private information such as access84* control information, or to track user browsing habit.</td>85* </tr>86*87* <tr>88* <th scope="row">getNetworkInformation</th>89* <td>The ability to retrieve all information about local network interfaces.</td>90* <td>Malicious code can read information about network hardware such as91* MAC addresses, which could be used to construct local IPv6 addresses.</td>92* </tr>93*94* <tr>95* <th scope="row">getProxySelector</th>96* <td>The ability to get the proxy selector used to make decisions97* on which proxies to use when making network connections.</td>98* <td>Malicious code can get a ProxySelector to discover proxy99* hosts and ports on internal networks, which could then become100* targets for attack.</td>101* </tr>102*103* <tr>104* <th scope="row">getResponseCache</th>105* <td>The ability to get the response cache that provides106* access to a local response cache.</td>107* <td>Malicious code getting access to the local response cache108* could access security sensitive information.</td>109* </tr>110*111* <tr>112* <th scope="row">requestPasswordAuthentication</th>113* <td>The ability114* to ask the authenticator registered with the system for115* a password</td>116* <td>Malicious code may steal this password.</td>117* </tr>118*119* <tr>120* <th scope="row">setCookieHandler</th>121* <td>The ability to set the cookie handler that processes highly122* security sensitive cookie information for an Http session.</td>123* <td>Malicious code can set a cookie handler to obtain access to124* highly security sensitive cookie information. Some web servers125* use cookies to save user private information such as access126* control information, or to track user browsing habit.</td>127* </tr>128*129* <tr>130* <th scope="row">setDefaultAuthenticator</th>131* <td>The ability to set the132* way authentication information is retrieved when133* a proxy or HTTP server asks for authentication</td>134* <td>Malicious135* code can set an authenticator that monitors and steals user136* authentication input as it retrieves the input from the user.</td>137* </tr>138*139* <tr>140* <th scope="row">setProxySelector</th>141* <td>The ability to set the proxy selector used to make decisions142* on which proxies to use when making network connections.</td>143* <td>Malicious code can set a ProxySelector that directs network144* traffic to an arbitrary network host.</td>145* </tr>146*147* <tr>148* <th scope="row">setResponseCache</th>149* <td>The ability to set the response cache that provides access to150* a local response cache.</td>151* <td>Malicious code getting access to the local response cache152* could access security sensitive information, or create false153* entries in the response cache.</td>154* </tr>155*156* <tr>157* <th scope="row">setSocketImpl</th>158* <td>The ability to create a sub-class of Socket or ServerSocket with a159* user specified SocketImpl.</td>160* <td>Malicious user-defined SocketImpls can change the behavior of161* Socket and ServerSocket in surprising ways, by virtue of their162* ability to access the protected fields of SocketImpl.</td>163* </tr>164*165* <tr>166* <th scope="row">specifyStreamHandler</th>167* <td>The ability168* to specify a stream handler when constructing a URL</td>169* <td>Malicious code may create a URL with resources that it would170* normally not have access to (like file:/foo/fum/), specifying a171* stream handler that gets the actual bytes from someplace it does172* have access to. Thus it might be able to trick the system into173* creating a ProtectionDomain/CodeSource for a class even though174* that class really didn't come from that location.</td>175* </tr>176* </tbody>177* </table>178*179* @implNote180* Implementations may define additional target names, but should use naming181* conventions such as reverse domain name notation to avoid name clashes.182*183* @see java.security.BasicPermission184* @see java.security.Permission185* @see java.security.Permissions186* @see java.security.PermissionCollection187* @see java.lang.SecurityManager188*189*190* @author Marianne Mueller191* @author Roland Schemers192* @since 1.2193*/194195public final class NetPermission extends BasicPermission {196@java.io.Serial197private static final long serialVersionUID = -8343910153355041693L;198199/**200* Creates a new NetPermission with the specified name.201* The name is the symbolic name of the NetPermission, such as202* "setDefaultAuthenticator", etc. An asterisk203* may appear at the end of the name, following a ".", or by itself, to204* signify a wildcard match.205*206* @param name the name of the NetPermission.207*208* @throws NullPointerException if {@code name} is {@code null}.209* @throws IllegalArgumentException if {@code name} is empty.210*/211212public NetPermission(String name)213{214super(name);215}216217/**218* Creates a new NetPermission object with the specified name.219* The name is the symbolic name of the NetPermission, and the220* actions String is currently unused and should be null.221*222* @param name the name of the NetPermission.223* @param actions should be null.224*225* @throws NullPointerException if {@code name} is {@code null}.226* @throws IllegalArgumentException if {@code name} is empty.227*/228229public NetPermission(String name, String actions)230{231super(name, actions);232}233}234235236