Skip to content

Commit

Permalink
issue classilla#607: new, separate blocklist in caps/ for scripts tha…
Browse files Browse the repository at this point in the history
…t can crash the browser, but have no obvious workaround
  • Loading branch information
NapalmSauce committed Jun 10, 2020
1 parent 8304421 commit 69d50d7
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 0 deletions.
33 changes: 33 additions & 0 deletions caps/nsScriptSecurityManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -688,6 +688,30 @@ 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 ||
BLOC("static.twitchcdn.net") ||
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 &&
Expand Down Expand Up @@ -1790,6 +1814,7 @@ static const char* kObservedPrefs[] = {
sFileOriginPolicyPrefName,
"capability.policy.",
"tenfourfox.adblock.",
"tenfourfox.troublesome-js.",
nullptr
};

Expand All @@ -1810,6 +1835,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. "
Expand Down Expand Up @@ -1950,6 +1977,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
Expand Down
2 changes: 2 additions & 0 deletions caps/nsScriptSecurityManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,8 @@ class nsScriptSecurityManager final : public nsIScriptSecurityManager,
bool mIsJavaScriptEnabled;
bool mIsTenFourFoxAdBlockEnabled;
bool mIsTenFourFoxAdBlockLoggingEnabled;
bool mIsTenFourFoxTroublesomeJsAllowed;
bool mIsTenFourFoxTroublesomeJsLoggingEnabled;
nsTArray<nsCOMPtr<nsIURI>> mFileURIWhitelist;

// This machinery controls new-style domain policies. The old-style
Expand Down

0 comments on commit 69d50d7

Please sign in to comment.