зеркало из https://github.com/mozilla/gecko-dev.git
Bug 1815738 - record type of 401 request.r=necko-reviewers,pbz,valentin
Differential Revision: https://phabricator.services.mozilla.com/D169894
This commit is contained in:
Родитель
b3e99300e3
Коммит
28b4f88f22
|
@ -1,9 +1,18 @@
|
|||
[DEFAULT]
|
||||
support-files = head.js
|
||||
[browser_abort_when_in_modal_state.js]
|
||||
[browser_auth_spoofing_protection.js]
|
||||
support-files =
|
||||
redirect-crossDomain.html
|
||||
redirect-sameDomain.html
|
||||
auth-route.sjs
|
||||
[browser_auth_spoofing_telemetry.js]
|
||||
support-files =
|
||||
redirect-crossDomain.html
|
||||
redirect-sameDomain.html
|
||||
cross-domain-iframe.html
|
||||
same-domain-iframe.html
|
||||
auth-route.sjs
|
||||
[browser_auth_spoofing_url_copy.js]
|
||||
support-files =
|
||||
redirect-crossDomain.html
|
||||
|
|
|
@ -0,0 +1,81 @@
|
|||
/* Any copyright is dedicated to the Public Domain.
|
||||
* http://creativecommons.org/publicdomain/zero/1.0/ */
|
||||
|
||||
"use strict";
|
||||
|
||||
let TEST_PATH = getRootDirectory(gTestPath).replace(
|
||||
"chrome://mochitests/content",
|
||||
"https://example.com"
|
||||
);
|
||||
|
||||
let TEST_PATH_AUTH = getRootDirectory(gTestPath).replace(
|
||||
"chrome://mochitests/content",
|
||||
"https://example.org"
|
||||
);
|
||||
|
||||
const CROSS_DOMAIN_URL = TEST_PATH + "redirect-crossDomain.html";
|
||||
|
||||
const SAME_DOMAIN_URL = TEST_PATH + "redirect-sameDomain.html";
|
||||
|
||||
const CROSS_DOMAIN_SUB_URL = TEST_PATH + "cross-domain-iframe.html";
|
||||
|
||||
const SAME_DOMAIN_SUB_URL = TEST_PATH + "same-domain-iframe.html";
|
||||
|
||||
const AUTH_URL = TEST_PATH_AUTH + "auth-route.sjs";
|
||||
|
||||
const TOP_LEVEL_SAME_DOMAIN = 0;
|
||||
const TOP_LEVEL_CROSS_DOMAIN = 1;
|
||||
const SAME_DOMAIN_SUBRESOURCE = 2;
|
||||
const CROSS_DOMAIN_SUBRESOURCE = 3;
|
||||
|
||||
/**
|
||||
* Opens a new tab with the given url, this will trigger an auth prompt for type
|
||||
* cross or same domain, top level or subresouce, depending on the url.
|
||||
* It checks whether the right index of the histogram "HTTP_AUTH_DIALOG_STATS_3"
|
||||
* was increases, according to the type
|
||||
* @param {String} urlToLoad - url to be loaded.
|
||||
* @param {Integer} index - index at which we check the count of the histogram.
|
||||
*/
|
||||
async function loadAndHandlePrompt(urlToLoad, index) {
|
||||
let histogram = TelemetryTestUtils.getAndClearHistogram(
|
||||
"HTTP_AUTH_RESOURCE_TYPE"
|
||||
);
|
||||
let dialogShown = waitForDialog(index, histogram);
|
||||
await BrowserTestUtils.withNewTab(urlToLoad, async function() {
|
||||
await dialogShown;
|
||||
});
|
||||
await new Promise(resolve => {
|
||||
Services.clearData.deleteData(
|
||||
Ci.nsIClearDataService.CLEAR_AUTH_CACHE,
|
||||
resolve
|
||||
);
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests that top level cross domain 401s are properly recorded by telemetry
|
||||
*/
|
||||
add_task(async function testCrossDomainTopLevel() {
|
||||
await loadAndHandlePrompt(CROSS_DOMAIN_URL, TOP_LEVEL_CROSS_DOMAIN);
|
||||
});
|
||||
|
||||
/**
|
||||
Tests that top level same domain 401s are properly recorded by telemetry
|
||||
*/
|
||||
add_task(async function testSameDomainTopLevel() {
|
||||
await loadAndHandlePrompt(SAME_DOMAIN_URL, TOP_LEVEL_SAME_DOMAIN);
|
||||
});
|
||||
|
||||
/**
|
||||
Tests that cross domain 401s from sub resouces are properly recorded by telemetry
|
||||
*/
|
||||
add_task(async function testCrossDomainSubresource() {
|
||||
await loadAndHandlePrompt(CROSS_DOMAIN_SUB_URL, CROSS_DOMAIN_SUBRESOURCE);
|
||||
});
|
||||
|
||||
/**
|
||||
Tests that same domain 401s from sub resouces are properly recorded by telemetry
|
||||
*/
|
||||
add_task(async function testSameDomainSubresource() {
|
||||
await loadAndHandlePrompt(SAME_DOMAIN_SUB_URL, SAME_DOMAIN_SUBRESOURCE);
|
||||
});
|
|
@ -0,0 +1,10 @@
|
|||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<title>example.com</title>
|
||||
</head>
|
||||
<body>
|
||||
<iframe src="https://example.org/browser/browser/base/content/test/tabPrompts/auth-route.sjs" title="Cross domain iframe!"></iframe>
|
||||
</body>
|
||||
</html>
|
|
@ -0,0 +1,26 @@
|
|||
/* Any copyright is dedicated to the Public Domain.
|
||||
* http://creativecommons.org/publicdomain/zero/1.0/ */
|
||||
|
||||
"use strict";
|
||||
|
||||
const { TelemetryTestUtils } = ChromeUtils.importESModule(
|
||||
"resource://testing-common/TelemetryTestUtils.sys.mjs"
|
||||
);
|
||||
|
||||
// Waits for an auth dialog to appear and closes it.
|
||||
// Also checks an index of a given histopgram
|
||||
async function waitForDialog(index, histogram) {
|
||||
await TestUtils.topicObserved("common-dialog-loaded");
|
||||
let dialog = gBrowser.getTabDialogBox(gBrowser.selectedBrowser)
|
||||
._tabDialogManager._topDialog;
|
||||
let dialogDocument = dialog._frame.contentDocument;
|
||||
let onDialogClosed = BrowserTestUtils.waitForEvent(
|
||||
window,
|
||||
"DOMModalDialogClosed"
|
||||
);
|
||||
TelemetryTestUtils.assertHistogram(histogram, index, 1);
|
||||
// it does not matter if the dialog is canceled or accepted for our telemety so we just always cancel
|
||||
dialogDocument.getElementById("commonDialog").cancelDialog();
|
||||
|
||||
await onDialogClosed;
|
||||
}
|
|
@ -0,0 +1,10 @@
|
|||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<title>example.com</title>
|
||||
</head>
|
||||
<body>
|
||||
<iframe src="https://test1.example.com/browser/browser/base/content/test/tabPrompts/auth-route.sjs" title="Same domain iframe!"></iframe>
|
||||
</body>
|
||||
</html>
|
|
@ -41,6 +41,7 @@
|
|||
#include "mozilla/StaticPrefs_network.h"
|
||||
#include "mozilla/StaticPrefs_prompts.h"
|
||||
#include "mozilla/Telemetry.h"
|
||||
#include "mozilla/dom/WindowGlobalParent.h"
|
||||
#include "nsIProxiedChannel.h"
|
||||
#include "nsIProxyInfo.h"
|
||||
|
||||
|
@ -1059,16 +1060,37 @@ bool nsHttpChannelAuthProvider::BlockPrompt(bool proxyAuth) {
|
|||
bool topDoc = true;
|
||||
bool xhr = false;
|
||||
bool nonWebContent = false;
|
||||
bool isCrossDomain = false;
|
||||
|
||||
if (loadInfo->GetExternalContentPolicyType() !=
|
||||
ExtContentPolicy::TYPE_DOCUMENT) {
|
||||
topDoc = false;
|
||||
}
|
||||
|
||||
if (!topDoc) {
|
||||
if (topDoc) {
|
||||
// To check if the navigation is cross domain, we need to find out where
|
||||
// we're navigating away from
|
||||
RefPtr<dom::BrowsingContext> browsingContext;
|
||||
nsresult rv =
|
||||
loadInfo->GetTargetBrowsingContext(getter_AddRefs(browsingContext));
|
||||
if (NS_SUCCEEDED(rv)) {
|
||||
if (RefPtr<dom::WindowGlobalParent> windowGlobalParent =
|
||||
browsingContext->Canonical()->GetCurrentWindowGlobal()) {
|
||||
if (nsCOMPtr<nsIPrincipal> documentPrincipal =
|
||||
windowGlobalParent->DocumentPrincipal()) {
|
||||
rv = documentPrincipal->IsThirdPartyURI(mURI, &isCrossDomain);
|
||||
if (NS_FAILED(rv)) {
|
||||
isCrossDomain = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
} else {
|
||||
nsCOMPtr<nsIPrincipal> triggeringPrinc = loadInfo->TriggeringPrincipal();
|
||||
if (triggeringPrinc->IsSystemPrincipal()) {
|
||||
nonWebContent = true;
|
||||
} else {
|
||||
triggeringPrinc->IsThirdPartyURI(mURI, &isCrossDomain);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1089,6 +1111,24 @@ bool nsHttpChannelAuthProvider::BlockPrompt(bool proxyAuth) {
|
|||
}
|
||||
}
|
||||
|
||||
if (topDoc) {
|
||||
if (isCrossDomain) {
|
||||
Telemetry::AccumulateCategorical(
|
||||
Telemetry::LABELS_HTTP_AUTH_RESOURCE_TYPE::topLevelCrossDomain);
|
||||
} else {
|
||||
Telemetry::AccumulateCategorical(
|
||||
Telemetry::LABELS_HTTP_AUTH_RESOURCE_TYPE::topLevelSameDomain);
|
||||
}
|
||||
} else {
|
||||
if (isCrossDomain) {
|
||||
Telemetry::AccumulateCategorical(
|
||||
Telemetry::LABELS_HTTP_AUTH_RESOURCE_TYPE::subCrossDomain);
|
||||
} else {
|
||||
Telemetry::AccumulateCategorical(
|
||||
Telemetry::LABELS_HTTP_AUTH_RESOURCE_TYPE::subSameDomain);
|
||||
}
|
||||
}
|
||||
|
||||
if (Telemetry::CanRecordPrereleaseData()) {
|
||||
if (topDoc) {
|
||||
Telemetry::Accumulate(Telemetry::HTTP_AUTH_DIALOG_STATS_3,
|
||||
|
|
|
@ -3187,6 +3187,17 @@
|
|||
"n_values": 64,
|
||||
"description": "Stats about what kind of resource requested http authentication. (29=top-level doc, 30=same origin subresources, 31=same origin xhr, 32=non-web-content, (nsIContentPolicy type)=cross-origin subresources per nsIContentPolicy type)"
|
||||
},
|
||||
"HTTP_AUTH_RESOURCE_TYPE": {
|
||||
"record_in_processes": ["main"],
|
||||
"products": ["firefox"],
|
||||
"expires_in_version": "116",
|
||||
"alert_emails": ["pbz@mozilla.com", "hpeuckmann@mozilla.com"],
|
||||
"bug_numbers": [1815738],
|
||||
"kind": "categorical",
|
||||
"releaseChannelCollection": "opt-out",
|
||||
"description": "Records same/cross domain http authentication requests from top level navigations and subresource requests.",
|
||||
"labels": ["topLevelSameDomain", "topLevelCrossDomain", "subSameDomain", "subCrossDomain"]
|
||||
},
|
||||
"HTTP_AUTH_TYPE_STATS": {
|
||||
"record_in_processes": ["main", "content"],
|
||||
"products": ["firefox", "fennec"],
|
||||
|
|
Загрузка…
Ссылка в новой задаче