Bug 1244474 - cut off path from URLs passed to PAC scripts, r=mcmanus
--- a/modules/libpref/init/all.js
+++ b/modules/libpref/init/all.js
@@ -1951,16 +1951,18 @@ pref("network.cookie.cookieBehavior",
#endif
pref("network.cookie.thirdparty.sessionOnly", false);
pref("network.cookie.lifetimePolicy", 0); // 0-accept, 1-dontUse 2-acceptForSession, 3-acceptForNDays
pref("network.cookie.prefsMigrated", false);
pref("network.cookie.lifetime.days", 90); // Ignored unless network.cookie.lifetimePolicy is 3.
// The PAC file to load. Ignored unless network.proxy.type is 2.
pref("network.proxy.autoconfig_url", "");
+// Strip off paths when sending URLs to PAC scripts
+pref("network.proxy.autoconfig_url.include_path", false);
// If we cannot load the PAC file, then try again (doubling from interval_min
// until we reach interval_max or the PAC file is successfully loaded).
pref("network.proxy.autoconfig_retry_interval_min", 5); // 5 seconds
pref("network.proxy.autoconfig_retry_interval_max", 300); // 5 minutes
// Use the HSTS preload list by default
pref("network.stricttransportsecurity.preloadlist", true);
--- a/netwerk/base/ProxyAutoConfig.cpp
+++ b/netwerk/base/ProxyAutoConfig.cpp
@@ -6,16 +6,17 @@
#include "ProxyAutoConfig.h"
#include "nsICancelable.h"
#include "nsIDNSListener.h"
#include "nsIDNSRecord.h"
#include "nsIDNSService.h"
#include "nsThreadUtils.h"
#include "nsIConsoleService.h"
+#include "nsIURLParser.h"
#include "nsJSUtils.h"
#include "jsfriendapi.h"
#include "prnetdb.h"
#include "nsITimer.h"
#include "mozilla/net/DNS.h"
#include "nsServiceManagerUtils.h"
#include "nsNetCID.h"
@@ -730,25 +731,27 @@ const JSClass JSRuntimeWrapper::sGlobalC
void
ProxyAutoConfig::SetThreadLocalIndex(uint32_t index)
{
sRunningIndex = index;
}
nsresult
ProxyAutoConfig::Init(const nsCString &aPACURI,
- const nsCString &aPACScript)
+ const nsCString &aPACScript,
+ bool aIncludePath)
{
mPACURI = aPACURI;
mPACScript = sPacUtils;
mPACScript.Append(aPACScript);
if (!GetRunning())
return SetupJS();
+ mIncludePath = aIncludePath;
mJSNeedsSetup = true;
return NS_OK;
}
nsresult
ProxyAutoConfig::SetupJS()
{
mJSNeedsSetup = false;
@@ -836,17 +839,39 @@ ProxyAutoConfig::GetProxyForURI(const ns
// while the event loop is spinning on a DNS function. Don't early return.
SetRunning(this);
mRunningHost = aTestHost;
mRunningAppId = aAppId;
mRunningAppOrigin = aAppOrigin;
mRunningIsInIsolatedMozBrowser = aIsInIsolatedMozBrowser;
nsresult rv = NS_ERROR_FAILURE;
- JS::RootedString uriString(cx, JS_NewStringCopyZ(cx, aTestURI.get()));
+ uint32_t schemePos;
+ int32_t schemeLen;
+ uint32_t authorityPos;
+ int32_t authorityLen;
+ uint32_t pathPos;
+ int32_t pathLen;
+
+ nsCString clensedURI = aTestURI;
+
+ if (!mIncludePath) {
+ nsCOMPtr<nsIURLParser> urlParser =
+ do_GetService(NS_STDURLPARSER_CONTRACTID, &rv);
+ rv = urlParser->ParseURL(aTestURI.get(), aTestURI.Length(),
+ &schemePos, &schemeLen,
+ &authorityPos, &authorityLen,
+ &pathPos, &pathLen);
+ if (NS_SUCCEEDED(rv)) {
+ // cut off the path
+ aTestURI.Left(clensedURI, aTestURI.Length() - pathLen);
+ }
+ }
+
+ JS::RootedString uriString(cx, JS_NewStringCopyZ(cx, clensedURI.get()));
JS::RootedString hostString(cx, JS_NewStringCopyZ(cx, aTestHost.get()));
if (uriString && hostString) {
JS::AutoValueArray<2> args(cx);
args[0].setString(uriString);
args[1].setString(hostString);
JS::Rooted<JS::Value> rval(cx);
--- a/netwerk/base/ProxyAutoConfig.h
+++ b/netwerk/base/ProxyAutoConfig.h
@@ -25,17 +25,18 @@ union NetAddr;
// thread and running nested event loops. GetProxyForURI is not re-entrant.
class ProxyAutoConfig {
public:
ProxyAutoConfig();
~ProxyAutoConfig();
nsresult Init(const nsCString &aPACURI,
- const nsCString &aPACScript);
+ const nsCString &aPACScript,
+ bool aIncludePath);
void SetThreadLocalIndex(uint32_t index);
void Shutdown();
void GC();
bool MyIPAddress(const JS::CallArgs &aArgs);
bool MyAppId(const JS::CallArgs &aArgs);
bool MyAppOrigin(const JS::CallArgs &aArgs);
bool IsInIsolatedMozBrowser(const JS::CallArgs &aArgs);
bool ResolveAddress(const nsCString &aHostName,
@@ -103,16 +104,17 @@ private:
bool MyIPAddressTryHost(const nsCString &hostName, unsigned int timeout,
const JS::CallArgs &aArgs, bool* aResult);
JSRuntimeWrapper *mJSRuntime;
bool mJSNeedsSetup;
bool mShutdown;
nsCString mPACScript;
nsCString mPACURI;
+ bool mIncludePath;
nsCString mRunningHost;
uint32_t mRunningAppId;
nsString mRunningAppOrigin;
bool mRunningIsInIsolatedMozBrowser;
nsCOMPtr<nsITimer> mTimer;
};
} // namespace net
--- a/netwerk/base/nsPACMan.cpp
+++ b/netwerk/base/nsPACMan.cpp
@@ -12,16 +12,17 @@
#include "nsIPromptFactory.h"
#include "nsIHttpChannel.h"
#include "nsIPrefService.h"
#include "nsIPrefBranch.h"
#include "nsNetUtil.h"
#include "nsIAsyncVerifyRedirectCallback.h"
#include "nsISystemProxySettings.h"
#include "nsContentUtils.h"
+#include "mozilla/Preferences.h"
#ifdef MOZ_NUWA_PROCESS
#include "ipc/Nuwa.h"
#endif
//-----------------------------------------------------------------------------
namespace mozilla {
namespace net {
@@ -205,17 +206,18 @@ public:
mCancel = false;
return NS_OK;
}
if (mSetupPAC) {
mSetupPAC = false;
mPACMan->mPAC.Init(mSetupPACURI,
- mSetupPACData);
+ mSetupPACData,
+ mPACMan->mIncludePath);
RefPtr<PACLoadComplete> runnable = new PACLoadComplete(mPACMan);
NS_DispatchToMainThread(runnable);
return NS_OK;
}
mPACMan->ProcessPendingQ();
return NS_OK;
@@ -297,28 +299,32 @@ PendingPACQuery::Run()
return NS_OK;
}
//-----------------------------------------------------------------------------
static bool sThreadLocalSetup = false;
static uint32_t sThreadLocalIndex = 0xdeadbeef; // out of range
+static const char *kPACIncludePath =
+ "network.proxy.autoconfig_url.include_path";
+
nsPACMan::nsPACMan()
: mLoadPending(false)
, mShutdown(false)
, mLoadFailureCount(0)
, mInProgress(false)
{
MOZ_ASSERT(NS_IsMainThread(), "pacman must be created on main thread");
if (!sThreadLocalSetup){
sThreadLocalSetup = true;
PR_NewThreadPrivateIndex(&sThreadLocalIndex, nullptr);
}
mPAC.SetThreadLocalIndex(sThreadLocalIndex);
+ mIncludePath = Preferences::GetBool(kPACIncludePath, false);
}
nsPACMan::~nsPACMan()
{
if (mPACThread) {
if (NS_IsMainThread()) {
mPACThread->Shutdown();
}
--- a/netwerk/base/nsPACMan.h
+++ b/netwerk/base/nsPACMan.h
@@ -237,16 +237,17 @@ private:
nsCOMPtr<nsIStreamLoader> mLoader;
bool mLoadPending;
Atomic<bool, Relaxed> mShutdown;
TimeStamp mScheduledReload;
uint32_t mLoadFailureCount;
bool mInProgress;
+ bool mIncludePath;
};
extern LazyLogModule gProxyLog;
} // namespace net
} // namespace mozilla
#endif // nsPACMan_h__