Skip to content

Commit

Permalink
fixup! Bug 23247: Communicating security expectations for .onion
Browse files Browse the repository at this point in the history
  • Loading branch information
acatarineu committed Oct 3, 2019
1 parent f970a6e commit d32c2e6
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 18 deletions.
4 changes: 4 additions & 0 deletions browser/base/content/browser-siteIdentity.js
Expand Up @@ -612,6 +612,10 @@ var gIdentityHandler = {
* built-in (returns false) or imported (returns true).
*/
_hasCustomRoot() {
if (!this._secInfo) {
return false;
}

let issuerCert = null;
// Walk the whole chain to get the last cert.
// eslint-disable-next-line no-empty
Expand Down
4 changes: 3 additions & 1 deletion docshell/base/nsDocShell.cpp
Expand Up @@ -63,6 +63,7 @@
#include "mozilla/dom/ChildSHistory.h"
#include "mozilla/dom/nsCSPContext.h"
#include "mozilla/dom/LoadURIOptionsBinding.h"
#include "mozilla/dom/nsMixedContentBlocker.h"

#include "mozilla/net/ReferrerPolicy.h"
#include "mozilla/net/UrlClassifierFeatureFactory.h"
Expand Down Expand Up @@ -5583,7 +5584,8 @@ nsDocShell::GetAllowMixedContentAndConnectionData(
// aRootHasSecureConnection should be false.
nsCOMPtr<nsIURI> rootUri = rootPrincipal->GetURI();
if (nsContentUtils::IsSystemPrincipal(rootPrincipal) || !rootUri ||
!SchemeIsHTTPS(rootUri)) {
(!SchemeIsHTTPS(rootUri) &&
!nsMixedContentBlocker::IsPotentiallyTrustworthyOnion(rootUri))) {
*aRootHasSecureConnection = false;
}

Expand Down
46 changes: 29 additions & 17 deletions security/manager/ssl/nsSecureBrowserUIImpl.cpp
Expand Up @@ -9,6 +9,7 @@
#include "mozilla/Logging.h"
#include "mozilla/Unused.h"
#include "mozilla/dom/Document.h"
#include "mozilla/dom/nsMixedContentBlocker.h"
#include "nsContentUtils.h"
#include "nsIChannel.h"
#include "nsDocShell.h"
Expand Down Expand Up @@ -246,8 +247,8 @@ static nsresult URICanBeConsideredSecure(
return rv;
}

nsAutoCString host;
bool isOnion = NS_SUCCEEDED(innermostURI->GetHost(host)) && StringEndsWith(host, NS_LITERAL_CSTRING(".onion"));
bool isOnion =
nsMixedContentBlocker::IsPotentiallyTrustworthyOnion(innermostURI);

canBeConsideredSecure = isHttps || isOnion;

Expand Down Expand Up @@ -314,24 +315,35 @@ nsresult nsSecureBrowserUIImpl::UpdateStateAndSecurityInfo(nsIChannel* channel,
if (NS_FAILED(rv)) {
return rv;
}
// If the security state is STATE_IS_INSECURE, the TLS handshake never
// completed. Don't set any further state.
if (mState == STATE_IS_INSECURE) {
return NS_OK;
// Skip setting some state if mState == STATE_IS_INSECURE (TLS handshake
// never completed). But do not return in that case, since a
// STATE_IS_INSECURE can still be changed later to STATE_IS_SECURE if it's
// routed over tor (.onion).
if (mState != STATE_IS_INSECURE) {
mTopLevelSecurityInfo = securityInfo;
MOZ_LOG(gSecureBrowserUILog, LogLevel::Debug,
(" set mTopLevelSecurityInfo"));
bool isEV;
rv = mTopLevelSecurityInfo->GetIsExtendedValidation(&isEV);
if (NS_FAILED(rv)) {
return rv;
}
if (isEV) {
MOZ_LOG(gSecureBrowserUILog, LogLevel::Debug, (" is EV"));
mState |= STATE_IDENTITY_EV_TOPLEVEL;
}
}
}

mTopLevelSecurityInfo = securityInfo;
MOZ_LOG(gSecureBrowserUILog, LogLevel::Debug,
(" set mTopLevelSecurityInfo"));
bool isEV;
rv = mTopLevelSecurityInfo->GetIsExtendedValidation(&isEV);
if (NS_FAILED(rv)) {
return rv;
}
if (isEV) {
MOZ_LOG(gSecureBrowserUILog, LogLevel::Debug, (" is EV"));
mState |= STATE_IDENTITY_EV_TOPLEVEL;
// any protocol routed over tor is secure
if ((mState & STATE_IS_SECURE) == 0) {
if (nsMixedContentBlocker::IsPotentiallyTrustworthyOnion(uri)) {
MOZ_LOG(gSecureBrowserUILog, LogLevel::Debug, (" URI is onion"));
mState = STATE_IS_SECURE;
}
}

if (mState != STATE_IS_INSECURE) {
// Proactively check for mixed content in case GetState() is never called
// (this can happen when loading from the BF cache).
CheckForMixedContent();
Expand Down

0 comments on commit d32c2e6

Please sign in to comment.