From 5748c75132fccb88cde7837bbf9fb0eccd8194cd Mon Sep 17 00:00:00 2001 From: NapalmSauce <35426980+NapalmSauce@users.noreply.github.com> Date: Thu, 11 Jun 2020 20:30:45 -0400 Subject: [PATCH] Issue #607: new, separate blocklist in caps/ for scripts that can crash the browser, but have no obvious workaround (#609) --- caps/nsScriptSecurityManager.cpp | 37 ++++++++++++++++++++++++++++++++ caps/nsScriptSecurityManager.h | 2 ++ 2 files changed, 39 insertions(+) diff --git a/caps/nsScriptSecurityManager.cpp b/caps/nsScriptSecurityManager.cpp index 44ab87758..8beb23e44 100644 --- a/caps/nsScriptSecurityManager.cpp +++ b/caps/nsScriptSecurityManager.cpp @@ -688,6 +688,34 @@ nsScriptSecurityManager::CheckLoadURIWithPrincipal(nsIPrincipal* aPrincipal, return NS_ERROR_DOM_BAD_URI; } + // See TenFourFox issue 607 + // determine if this is a script we want to block + // Scripts that somehow hit hard limits should go in here + if (!mIsTenFourFoxTroublesomeJsAllowed && + (targetScheme.EqualsLiteral("http") || targetScheme.EqualsLiteral("https"))) { + nsAutoCString hostname; + if (MOZ_LIKELY(NS_SUCCEEDED(targetBaseURI->GetHost(hostname)))) { + ToLowerCase(hostname); +#define BLOC(q) hostname.EqualsLiteral(q) + if (0 || + +#ifdef __ppc__ + BLOC("static.twitchcdn.net") || +#endif // __ppc__ + + 0) { +#undef BLOC + +#ifndef DEBUG + if (mIsTenFourFoxTroublesomeJsLoggingEnabled) +#endif + fprintf(stderr, "Warning: TenFourFox blocking problematic script from %s.\n", + hostname.get()); + return NS_ERROR_DOM_BAD_URI; + } + } + } + // TenFourFox issue 469 // determine if this is a script we want to block if (mIsTenFourFoxAdBlockEnabled && @@ -1790,6 +1818,7 @@ static const char* kObservedPrefs[] = { sFileOriginPolicyPrefName, "capability.policy.", "tenfourfox.adblock.", + "tenfourfox.troublesome-js.", nullptr }; @@ -1810,6 +1839,8 @@ nsScriptSecurityManager::nsScriptSecurityManager(void) , mIsJavaScriptEnabled(false) , mIsTenFourFoxAdBlockEnabled(false) , mIsTenFourFoxAdBlockLoggingEnabled(false) + , mIsTenFourFoxTroublesomeJsAllowed(false) + , mIsTenFourFoxTroublesomeJsLoggingEnabled(false) { static_assert(sizeof(intptr_t) == sizeof(void*), "intptr_t and void* have different lengths on this platform. " @@ -1950,6 +1981,12 @@ nsScriptSecurityManager::ScriptSecurityPrefChanged() Preferences::GetBool("tenfourfox.adblock.enabled", mIsTenFourFoxAdBlockEnabled); mIsTenFourFoxAdBlockLoggingEnabled = Preferences::GetBool("tenfourfox.adblock.logging.enabled", mIsTenFourFoxAdBlockLoggingEnabled); + mIsTenFourFoxTroublesomeJsAllowed = + Preferences::GetBool("tenfourfox.troublesome-js.allow", + mIsTenFourFoxTroublesomeJsAllowed); + mIsTenFourFoxTroublesomeJsLoggingEnabled = + Preferences::GetBool("tenfourfox.troublesome-js.logging.enabled", + mIsTenFourFoxTroublesomeJsLoggingEnabled); // // Rebuild the set of principals for which we allow file:// URI loads. This diff --git a/caps/nsScriptSecurityManager.h b/caps/nsScriptSecurityManager.h index 41b68e137..7b0960a14 100644 --- a/caps/nsScriptSecurityManager.h +++ b/caps/nsScriptSecurityManager.h @@ -125,6 +125,8 @@ private: bool mIsJavaScriptEnabled; bool mIsTenFourFoxAdBlockEnabled; bool mIsTenFourFoxAdBlockLoggingEnabled; + bool mIsTenFourFoxTroublesomeJsAllowed; + bool mIsTenFourFoxTroublesomeJsLoggingEnabled; nsTArray> mFileURIWhitelist; // This machinery controls new-style domain policies. The old-style