6801071: Remote sites can compromise user privacy and possibly hijack web sessions

Reviewed-by: jccollet, hawtin
This commit is contained in:
Chris Hegarty 2009-05-12 16:32:34 +01:00
parent 813ad65e9a
commit ce7e28f3e6
6 changed files with 78 additions and 13 deletions

View file

@ -24,6 +24,7 @@
# #
FILES_java = \ FILES_java = \
sun/net/ApplicationProxy.java \
sun/net/InetAddressCachePolicy.java \ sun/net/InetAddressCachePolicy.java \
sun/net/URLCanonicalizer.java \ sun/net/URLCanonicalizer.java \
sun/net/NetworkClient.java \ sun/net/NetworkClient.java \

View file

@ -118,7 +118,7 @@ class Socket implements java.io.Closeable {
if (proxy == null) { if (proxy == null) {
throw new IllegalArgumentException("Invalid Proxy"); throw new IllegalArgumentException("Invalid Proxy");
} }
Proxy p = proxy == Proxy.NO_PROXY ? Proxy.NO_PROXY : new Proxy(proxy.type(), proxy.address()); Proxy p = proxy == Proxy.NO_PROXY ? Proxy.NO_PROXY : sun.net.ApplicationProxy.create(proxy);
if (p.type() == Proxy.Type.SOCKS) { if (p.type() == Proxy.Type.SOCKS) {
SecurityManager security = System.getSecurityManager(); SecurityManager security = System.getSecurityManager();
InetSocketAddress epoint = (InetSocketAddress) p.address(); InetSocketAddress epoint = (InetSocketAddress) p.address();

View file

@ -47,6 +47,9 @@ class SocksSocketImpl extends PlainSocketImpl implements SocksConsts {
private Socket cmdsock = null; private Socket cmdsock = null;
private InputStream cmdIn = null; private InputStream cmdIn = null;
private OutputStream cmdOut = null; private OutputStream cmdOut = null;
/* true if the Proxy has been set programatically */
private boolean applicationSetProxy; /* false */
SocksSocketImpl() { SocksSocketImpl() {
// Nothing needed // Nothing needed
@ -64,6 +67,7 @@ class SocksSocketImpl extends PlainSocketImpl implements SocksConsts {
// Use getHostString() to avoid reverse lookups // Use getHostString() to avoid reverse lookups
server = ad.getHostString(); server = ad.getHostString();
port = ad.getPort(); port = ad.getPort();
applicationSetProxy = true;
} }
} }
@ -165,8 +169,7 @@ class SocksSocketImpl extends PlainSocketImpl implements SocksConsts {
throw (IOException) pae.getException(); throw (IOException) pae.getException();
} }
} else { } else {
userName = java.security.AccessController.doPrivileged( userName = getUserName();
new sun.security.action.GetPropertyAction("user.name"));
} }
} }
if (userName == null) if (userName == null)
@ -267,8 +270,7 @@ class SocksSocketImpl extends PlainSocketImpl implements SocksConsts {
out.write((endpoint.getPort() >> 8) & 0xff); out.write((endpoint.getPort() >> 8) & 0xff);
out.write((endpoint.getPort() >> 0) & 0xff); out.write((endpoint.getPort() >> 0) & 0xff);
out.write(endpoint.getAddress().getAddress()); out.write(endpoint.getAddress().getAddress());
String userName = java.security.AccessController.doPrivileged( String userName = getUserName();
new sun.security.action.GetPropertyAction("user.name"));
try { try {
out.write(userName.getBytes("ISO-8859-1")); out.write(userName.getBytes("ISO-8859-1"));
} catch (java.io.UnsupportedEncodingException uee) { } catch (java.io.UnsupportedEncodingException uee) {
@ -588,8 +590,7 @@ class SocksSocketImpl extends PlainSocketImpl implements SocksConsts {
out.write((super.getLocalPort() >> 8) & 0xff); out.write((super.getLocalPort() >> 8) & 0xff);
out.write((super.getLocalPort() >> 0) & 0xff); out.write((super.getLocalPort() >> 0) & 0xff);
out.write(addr1); out.write(addr1);
String userName = java.security.AccessController.doPrivileged( String userName = getUserName();
new sun.security.action.GetPropertyAction("user.name"));
try { try {
out.write(userName.getBytes("ISO-8859-1")); out.write(userName.getBytes("ISO-8859-1"));
} catch (java.io.UnsupportedEncodingException uee) { } catch (java.io.UnsupportedEncodingException uee) {
@ -1052,4 +1053,16 @@ class SocksSocketImpl extends PlainSocketImpl implements SocksConsts {
super.close(); super.close();
} }
private String getUserName() {
String userName = "";
if (applicationSetProxy) {
try {
userName = System.getProperty("user.name");
} catch (SecurityException se) { /* swallow Exception */ }
} else {
userName = java.security.AccessController.doPrivileged(
new sun.security.action.GetPropertyAction("user.name"));
}
return userName;
}
} }

View file

@ -1005,7 +1005,7 @@ public final class URL implements java.io.Serializable {
} }
// Create a copy of Proxy as a security measure // Create a copy of Proxy as a security measure
Proxy p = proxy == Proxy.NO_PROXY ? Proxy.NO_PROXY : new Proxy(proxy.type(), proxy.address()); Proxy p = proxy == Proxy.NO_PROXY ? Proxy.NO_PROXY : sun.net.ApplicationProxy.create(proxy);
SecurityManager sm = System.getSecurityManager(); SecurityManager sm = System.getSecurityManager();
if (p.type() != Proxy.Type.DIRECT && sm != null) { if (p.type() != Proxy.Type.DIRECT && sm != null) {
InetSocketAddress epoint = (InetSocketAddress) p.address(); InetSocketAddress epoint = (InetSocketAddress) p.address();

View file

@ -0,0 +1,43 @@
/*
* Copyright 2009 Sun Microsystems, Inc. All Rights Reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Sun designates this
* particular file as subject to the "Classpath" exception as provided
* by Sun in the LICENSE file that accompanied this code.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
* CA 95054 USA or visit www.sun.com if you need additional information or
* have any questions.
*/
package sun.net;
import java.net.Proxy;
import java.net.SocketAddress;
/**
* Proxy wrapper class so that we can determine application set
* proxies by type.
*/
public final class ApplicationProxy extends Proxy {
private ApplicationProxy(Proxy proxy) {
super(proxy.type(), proxy.address());
}
public static ApplicationProxy create(Proxy proxy) {
return new ApplicationProxy(proxy);
}
}

View file

@ -575,12 +575,20 @@ public class HttpURLConnection extends java.net.HttpURLConnection {
responses = new MessageHeader(); responses = new MessageHeader();
this.handler = handler; this.handler = handler;
instProxy = p; instProxy = p;
cookieHandler = java.security.AccessController.doPrivileged( if (instProxy instanceof sun.net.ApplicationProxy) {
new java.security.PrivilegedAction<CookieHandler>() { /* Application set Proxies should not have access to cookies
* in a secure environment unless explicitly allowed. */
try {
cookieHandler = CookieHandler.getDefault();
} catch (SecurityException se) { /* swallow exception */ }
} else {
cookieHandler = java.security.AccessController.doPrivileged(
new java.security.PrivilegedAction<CookieHandler>() {
public CookieHandler run() { public CookieHandler run() {
return CookieHandler.getDefault(); return CookieHandler.getDefault();
} }
}); });
}
cacheHandler = java.security.AccessController.doPrivileged( cacheHandler = java.security.AccessController.doPrivileged(
new java.security.PrivilegedAction<ResponseCache>() { new java.security.PrivilegedAction<ResponseCache>() {
public ResponseCache run() { public ResponseCache run() {