1 /* 2 * Copyright (c) 1997, 2020, Oracle and/or its affiliates. All rights reserved. 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4 * 5 * This code is free software; you can redistribute it and/or modify it 6 * under the terms of the GNU General Public License version 2 only, as 7 * published by the Free Software Foundation. Oracle designates this 8 * particular file as subject to the "Classpath" exception as provided 9 * by Oracle in the LICENSE file that accompanied this code. 10 * 11 * This code is distributed in the hope that it will be useful, but WITHOUT 12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 14 * version 2 for more details (a copy is included in the LICENSE file that 15 * accompanied this code). 16 * 17 * You should have received a copy of the GNU General Public License version 18 * 2 along with this work; if not, write to the Free Software Foundation, 19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 20 * 21 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 22 * or visit www.oracle.com if you need additional information or have any 23 * questions. 24 */ 25 26 package java.net; 27 28 import java.security.*; 29 import java.util.Enumeration; 30 import java.util.Hashtable; 31 import java.util.StringTokenizer; 32 33 /** 34 * This class is for various network permissions. 35 * A NetPermission contains a name (also referred to as a "target name") but 36 * no actions list; you either have the named permission 37 * or you don't. 38 * <P> 39 * The target name is the name of the network permission (see below). The naming 40 * convention follows the hierarchical property naming convention. 41 * Also, an asterisk 42 * may appear at the end of the name, following a ".", or by itself, to 43 * signify a wildcard match. For example: "foo.*" and "*" signify a wildcard 44 * match, while "*foo" and "a*b" do not. 45 * <P> 46 * The following table lists the standard NetPermission target names, 47 * and for each provides a description of what the permission allows 48 * and a discussion of the risks of granting code the permission. 49 * 50 * <table class="striped"> 51 * <caption style="display:none">Permission target name, what the permission allows, and associated risks</caption> 52 * <thead> 53 * <tr> 54 * <th scope="col">Permission Target Name</th> 55 * <th scope="col">What the Permission Allows</th> 56 * <th scope="col">Risks of Allowing this Permission</th> 57 * </tr> 58 * </thead> 59 * <tbody> 60 * <tr> 61 * <th scope="row">allowHttpTrace</th> 62 * <td>The ability to use the HTTP TRACE method in HttpURLConnection.</td> 63 * <td>Malicious code using HTTP TRACE could get access to security sensitive 64 * information in the HTTP headers (such as cookies) that it might not 65 * otherwise have access to.</td> 66 * </tr> 67 * 68 * <tr> 69 * <th scope="row">accessUnixDomainSocket</th> 70 * <td>The ability to accept, bind, connect or get the local address 71 * of a <i>Unix Domain</i> socket. 72 * </td> 73 * <td>Malicious code could connect to local processes using Unix domain sockets 74 * or impersonate local processes, by binding to the same pathnames (assuming they 75 * have the required Operating System permissions.</td> 76 * </tr> 77 * 78 * <tr> 79 * <th scope="row">getCookieHandler</th> 80 * <td>The ability to get the cookie handler that processes highly 81 * security sensitive cookie information for an Http session.</td> 82 * <td>Malicious code can get a cookie handler to obtain access to 83 * highly security sensitive cookie information. Some web servers 84 * use cookies to save user private information such as access 85 * control information, or to track user browsing habit.</td> 86 * </tr> 87 * 88 * <tr> 89 * <th scope="row">getNetworkInformation</th> 90 * <td>The ability to retrieve all information about local network interfaces.</td> 91 * <td>Malicious code can read information about network hardware such as 92 * MAC addresses, which could be used to construct local IPv6 addresses.</td> 93 * </tr> 94 * 95 * <tr> 96 * <th scope="row">getProxySelector</th> 97 * <td>The ability to get the proxy selector used to make decisions 98 * on which proxies to use when making network connections.</td> 99 * <td>Malicious code can get a ProxySelector to discover proxy 100 * hosts and ports on internal networks, which could then become 101 * targets for attack.</td> 102 * </tr> 103 * 104 * <tr> 105 * <th scope="row">getResponseCache</th> 106 * <td>The ability to get the response cache that provides 107 * access to a local response cache.</td> 108 * <td>Malicious code getting access to the local response cache 109 * could access security sensitive information.</td> 110 * </tr> 111 * 112 * <tr> 113 * <th scope="row">requestPasswordAuthentication</th> 114 * <td>The ability 115 * to ask the authenticator registered with the system for 116 * a password</td> 117 * <td>Malicious code may steal this password.</td> 118 * </tr> 119 * 120 * <tr> 121 * <th scope="row">setCookieHandler</th> 122 * <td>The ability to set the cookie handler that processes highly 123 * security sensitive cookie information for an Http session.</td> 124 * <td>Malicious code can set a cookie handler to obtain access to 125 * highly security sensitive cookie information. Some web servers 126 * use cookies to save user private information such as access 127 * control information, or to track user browsing habit.</td> 128 * </tr> 129 * 130 * <tr> 131 * <th scope="row">setDefaultAuthenticator</th> 132 * <td>The ability to set the 133 * way authentication information is retrieved when 134 * a proxy or HTTP server asks for authentication</td> 135 * <td>Malicious 136 * code can set an authenticator that monitors and steals user 137 * authentication input as it retrieves the input from the user.</td> 138 * </tr> 139 * 140 * <tr> 141 * <th scope="row">setProxySelector</th> 142 * <td>The ability to set the proxy selector used to make decisions 143 * on which proxies to use when making network connections.</td> 144 * <td>Malicious code can set a ProxySelector that directs network 145 * traffic to an arbitrary network host.</td> 146 * </tr> 147 * 148 * <tr> 149 * <th scope="row">setResponseCache</th> 150 * <td>The ability to set the response cache that provides access to 151 * a local response cache.</td> 152 * <td>Malicious code getting access to the local response cache 153 * could access security sensitive information, or create false 154 * entries in the response cache.</td> 155 * </tr> 156 * 157 * <tr> 158 * <th scope="row">setSocketImpl</th> 159 * <td>The ability to create a sub-class of Socket or ServerSocket with a 160 * user specified SocketImpl.</td> 161 * <td>Malicious user-defined SocketImpls can change the behavior of 162 * Socket and ServerSocket in surprising ways, by virtue of their 163 * ability to access the protected fields of SocketImpl.</td> 164 * </tr> 165 * 166 * <tr> 167 * <th scope="row">specifyStreamHandler</th> 168 * <td>The ability 169 * to specify a stream handler when constructing a URL</td> 170 * <td>Malicious code may create a URL with resources that it would 171 * normally not have access to (like file:/foo/fum/), specifying a 172 * stream handler that gets the actual bytes from someplace it does 173 * have access to. Thus it might be able to trick the system into 174 * creating a ProtectionDomain/CodeSource for a class even though 175 * that class really didn't come from that location.</td> 176 * </tr> 177 * </tbody> 178 * </table> 179 * 180 * @implNote 181 * Implementations may define additional target names, but should use naming 182 * conventions such as reverse domain name notation to avoid name clashes. 183 * 184 * @see java.security.BasicPermission 185 * @see java.security.Permission 186 * @see java.security.Permissions 187 * @see java.security.PermissionCollection 188 * @see java.lang.SecurityManager 189 * 190 * 191 * @author Marianne Mueller 192 * @author Roland Schemers 193 * @since 1.2 194 */ 195 196 public final class NetPermission extends BasicPermission { 197 @java.io.Serial 198 private static final long serialVersionUID = -8343910153355041693L; 199 200 /** 201 * Creates a new NetPermission with the specified name. 202 * The name is the symbolic name of the NetPermission, such as 203 * "setDefaultAuthenticator", etc. An asterisk 204 * may appear at the end of the name, following a ".", or by itself, to 205 * signify a wildcard match. 206 * 207 * @param name the name of the NetPermission. 208 * 209 * @throws NullPointerException if {@code name} is {@code null}. 210 * @throws IllegalArgumentException if {@code name} is empty. 211 */ 212 213 public NetPermission(String name) 214 { 215 super(name); 216 } 217 218 /** 219 * Creates a new NetPermission object with the specified name. 220 * The name is the symbolic name of the NetPermission, and the 221 * actions String is currently unused and should be null. 222 * 223 * @param name the name of the NetPermission. 224 * @param actions should be null. 225 * 226 * @throws NullPointerException if {@code name} is {@code null}. 227 * @throws IllegalArgumentException if {@code name} is empty. 228 */ 229 230 public NetPermission(String name, String actions) 231 { 232 super(name, actions); 233 } 234 }