Bug 1921226 - Change expiration time for HTTPS upgrade exceptions r=maltejur

Differential Revision: https://phabricator.services.mozilla.com/D226274
This commit is contained in:
Simon Friedberger
2024-10-23 13:59:43 +00:00
parent 5e374731ed
commit d978475c0c
8 changed files with 23 additions and 20 deletions

View File

@@ -156,7 +156,7 @@ HTTPSOnlyUpgradeSpeculativeConnection = Upgrading insecure speculative TCP conne
HTTPSFirstSchemeless = Upgrading URL loaded in the address bar without explicit protocol scheme to use HTTPS.
# LOCALIZATION NOTE: %S is the hostname for which a exception will be added;
HTTPSFirstAddingSessionException = Website does not appear to support HTTPS. Further attempts to load “http://%S” securely will be skipped temporarily.
HTTPSFirstAddingException = Adding exception to temporarily prevent further attempts to automatically load “http://%S” securely.
# LOCALIZATION NOTE: %S is the URL of the blocked request;
IframeSandboxBlockedDownload = Download of “%S” was blocked because the triggering iframe has the sandbox flag set.

View File

@@ -557,7 +557,7 @@ nsHTTPSOnlyUtils::PotentiallyDowngradeHttpsFirstRequest(
if (mozilla::StaticPrefs::
dom_security_https_first_add_exception_on_failiure()) {
AddHTTPSFirstExceptionForSession(uri, loadInfo);
AddHTTPSFirstException(uri, loadInfo);
}
return newURI.forget();
@@ -689,9 +689,7 @@ bool nsHTTPSOnlyUtils::TestIfPrincipalIsExempt(nsIPrincipal* aPrincipal,
return perm == nsIHttpsOnlyModePermission::LOAD_INSECURE_ALLOW ||
perm == nsIHttpsOnlyModePermission::LOAD_INSECURE_ALLOW_SESSION ||
(aCheckForHTTPSFirst &&
(perm == nsIHttpsOnlyModePermission::HTTPSFIRST_LOAD_INSECURE_ALLOW ||
perm == nsIHttpsOnlyModePermission::
HTTPSFIRST_LOAD_INSECURE_ALLOW_SESSION));
perm == nsIHttpsOnlyModePermission::HTTPSFIRST_LOAD_INSECURE_ALLOW);
}
/* static */
@@ -957,7 +955,7 @@ bool nsHTTPSOnlyUtils::IsHttpDowngrade(nsIURI* aFromURI, nsIURI* aToURI) {
}
/* static */
nsresult nsHTTPSOnlyUtils::AddHTTPSFirstExceptionForSession(
nsresult nsHTTPSOnlyUtils::AddHTTPSFirstException(
nsCOMPtr<nsIURI> aURI, nsILoadInfo* const aLoadInfo) {
// We need to reconstruct a principal instead of taking one from the loadinfo,
// as the permission needs a http scheme, while the passed URL or principals
@@ -978,14 +976,16 @@ nsresult nsHTTPSOnlyUtils::AddHTTPSFirstExceptionForSession(
nsCString host;
aURI->GetHost(host);
LogLocalizedString("HTTPSFirstAddingSessionException",
{NS_ConvertUTF8toUTF16(host)}, nsIScriptError::warningFlag,
aLoadInfo, aURI, true);
LogLocalizedString("HTTPSFirstAddingException", {NS_ConvertUTF8toUTF16(host)},
nsIScriptError::warningFlag, aLoadInfo, aURI, true);
uint32_t lifetime =
mozilla::StaticPrefs::dom_security_https_first_exception_lifetime();
int64_t expirationTime = (PR_Now() / PR_USEC_PER_MSEC) + lifetime;
rv = permMgr->AddFromPrincipal(
principal, "https-only-load-insecure"_ns,
nsIHttpsOnlyModePermission::HTTPSFIRST_LOAD_INSECURE_ALLOW_SESSION,
nsIPermissionManager::EXPIRE_SESSION, 0);
nsIHttpsOnlyModePermission::HTTPSFIRST_LOAD_INSECURE_ALLOW,
nsIPermissionManager::EXPIRE_TIME, expirationTime);
NS_ENSURE_SUCCESS(rv, rv);
return NS_OK;

View File

@@ -176,8 +176,8 @@ class nsHTTPSOnlyUtils {
* @param aLoadInfo The loadinfo of the request triggering this exception to
* be added (needs to match aURI)
*/
static nsresult AddHTTPSFirstExceptionForSession(
nsCOMPtr<nsIURI> aURI, nsILoadInfo* const aLoadInfo);
static nsresult AddHTTPSFirstException(nsCOMPtr<nsIURI> aURI,
nsILoadInfo* const aLoadInfo);
/**
* Determines which HTTPS-Only status flags should get propagated to

View File

@@ -26,10 +26,9 @@ interface nsIHttpsOnlyModePermission : nsISupports
const uint32_t LOAD_INSECURE_ALLOW_SESSION = 9;
/**
* While LOAD_INSECURE_ALLOW and LOAD_INSECURE_ALLOW_SESSION apply to both
* HTTPS-Only and HTTPS-First, the following two values work analogous, but
* only apply to HTTPS-First. Permissions with these values set will not be
* displayed in the UI.
* HTTPS-Only and HTTPS-First, the following only applies to HTTPS-First.
* It is only used for exceptions which are set automatically and should
* therefore not apply to HTTPS-Only.
*/
const uint32_t HTTPSFIRST_LOAD_INSECURE_ALLOW = 10;
const uint32_t HTTPSFIRST_LOAD_INSECURE_ALLOW_SESSION = 11;
};

View File

@@ -59,7 +59,7 @@
await SpecialPowers.testPermission(
"https-only-load-insecure",
SpecialPowers.Ci.nsIHttpsOnlyModePermission
.HTTPSFIRST_LOAD_INSECURE_ALLOW_SESSION,
.HTTPSFIRST_LOAD_INSECURE_ALLOW,
URL_A
),
"A temporary HTTPS-First exception should have been added for the site"

View File

@@ -4018,6 +4018,11 @@
value: true
mirror: always
- name: dom.security.https_first_exception_lifetime
type: uint32_t
value: 7*24*60*60*1000 # 7 days in milliseconds
mirror: always
- name: dom.security.unexpected_system_load_telemetry_enabled
type: bool
value: true

View File

@@ -6185,7 +6185,7 @@ nsresult HttpBaseChannel::CheckRedirectLimit(nsIURI* aNewURI,
mURI, aNewURI, mLoadInfo,
{nsHTTPSOnlyUtils::UpgradeDowngradeEndlessLoopOptions::
EnforceForHTTPSFirstMode})) {
nsHTTPSOnlyUtils::AddHTTPSFirstExceptionForSession(mURI, mLoadInfo);
nsHTTPSOnlyUtils::AddHTTPSFirstException(mURI, mLoadInfo);
}
return NS_OK;

View File

@@ -3842,7 +3842,6 @@ interface nsIHttpsOnlyModePermission extends nsISupports {
readonly LOAD_INSECURE_BLOCK: 2;
readonly LOAD_INSECURE_ALLOW_SESSION: 9;
readonly HTTPSFIRST_LOAD_INSECURE_ALLOW: 10;
readonly HTTPSFIRST_LOAD_INSECURE_ALLOW_SESSION: 11;
}
// https://searchfox.org/mozilla-central/source/dom/serializers/nsIDocumentEncoder.idl