Skip to content

Commit 464ccfa

Browse files
committed
Bug 1968644 - Part 4: Populate triggeringFirstPartyClassificationFlags and triggeringThirdPartyClassificationFlags for loads. r=smaug,necko-reviewers
Differential Revision: https://phabricator.services.mozilla.com/D252445
1 parent 7625948 commit 464ccfa

File tree

10 files changed

+106
-0
lines changed

10 files changed

+106
-0
lines changed

docshell/base/nsDocShell.cpp

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,7 @@
107107
#include "nsICaptivePortalService.h"
108108
#include "nsIChannel.h"
109109
#include "nsIChannelEventSink.h"
110+
#include "nsIClassifiedChannel.h"
110111
#include "nsIClassOfService.h"
111112
#include "nsIConsoleReportCollector.h"
112113
#include "nsIContent.h"
@@ -4133,6 +4134,8 @@ nsresult nsDocShell::ReloadDocument(nsDocShell* aDocShell, Document* aDocument,
41334134
uint32_t triggeringSandboxFlags = aDocument->GetSandboxFlags();
41344135
uint64_t triggeringWindowId = aDocument->InnerWindowID();
41354136
bool triggeringStorageAccess = aDocument->UsingStorageAccess();
4137+
net::ClassificationFlags triggeringClassificationFlags =
4138+
aDocument->GetScriptTrackingFlags();
41364139

41374140
nsAutoString contentTypeHint;
41384141
aDocument->GetContentType(contentTypeHint);
@@ -4181,6 +4184,7 @@ nsresult nsDocShell::ReloadDocument(nsDocShell* aDocShell, Document* aDocument,
41814184
loadState->SetTriggeringSandboxFlags(triggeringSandboxFlags);
41824185
loadState->SetTriggeringWindowId(triggeringWindowId);
41834186
loadState->SetTriggeringStorageAccess(triggeringStorageAccess);
4187+
loadState->SetTriggeringClassificationFlags(triggeringClassificationFlags);
41844188
loadState->SetPrincipalToInherit(triggeringPrincipal);
41854189
loadState->SetCsp(csp);
41864190
loadState->SetInternalLoadFlags(flags);
@@ -5163,6 +5167,7 @@ nsDocShell::ForceRefreshURI(nsIURI* aURI, nsIPrincipal* aPrincipal,
51635167
loadState->SetTriggeringSandboxFlags(doc->GetSandboxFlags());
51645168
loadState->SetTriggeringWindowId(doc->InnerWindowID());
51655169
loadState->SetTriggeringStorageAccess(doc->UsingStorageAccess());
5170+
loadState->SetTriggeringClassificationFlags(doc->GetScriptTrackingFlags());
51665171

51675172
loadState->SetPrincipalIsExplicit(true);
51685173

@@ -6770,6 +6775,19 @@ nsresult nsDocShell::CreateAboutBlankDocumentViewer(
67706775
// after being set here.
67716776
blankDoc->SetSandboxFlags(sandboxFlags);
67726777

6778+
// We inherit the classification flags from the parent document if the
6779+
// principal matches.
6780+
nsCOMPtr<nsIDocShellTreeItem> parentItem;
6781+
GetInProcessSameTypeParent(getter_AddRefs(parentItem));
6782+
if (parentItem) {
6783+
RefPtr<Document> parentDocument = parentItem->GetDocument();
6784+
if (parentDocument && principal &&
6785+
principal->Equals(parentDocument->NodePrincipal())) {
6786+
blankDoc->SetClassificationFlags(
6787+
parentDocument->GetClassificationFlags());
6788+
}
6789+
}
6790+
67736791
// create a content viewer for us and the new document
67746792
docFactory->CreateInstanceForDocument(
67756793
NS_ISUPPORTS_CAST(nsIDocShell*, this), blankDoc, "view",
@@ -7971,6 +7989,19 @@ nsresult nsDocShell::CreateDocumentViewer(const nsACString& aContentType,
79717989
nullptr, nullptr, nullptr, true, false);
79727990
}
79737991

7992+
// We inherit the classification flags from the parent document if the
7993+
// document is about:blank and the principal matches.
7994+
nsCOMPtr<nsIDocShellTreeItem> parentItem;
7995+
GetInProcessSameTypeParent(getter_AddRefs(parentItem));
7996+
if (parentItem && finalURI && NS_IsAboutBlank(finalURI)) {
7997+
RefPtr<Document> doc = viewer->GetDocument();
7998+
RefPtr<Document> parentDocument = parentItem->GetDocument();
7999+
if (parentDocument && doc &&
8000+
doc->NodePrincipal()->Equals(parentDocument->NodePrincipal())) {
8001+
doc->SetClassificationFlags(parentDocument->GetClassificationFlags());
8002+
}
8003+
}
8004+
79748005
// let's try resetting the load group if we need to...
79758006
nsCOMPtr<nsILoadGroup> currentLoadGroup;
79768007
NS_ENSURE_SUCCESS(
@@ -8573,6 +8604,8 @@ nsresult nsDocShell::PerformRetargeting(nsDocShellLoadState* aLoadState) {
85738604
loadState->SetTriggeringWindowId(aLoadState->TriggeringWindowId());
85748605
loadState->SetTriggeringStorageAccess(
85758606
aLoadState->TriggeringStorageAccess());
8607+
loadState->SetTriggeringClassificationFlags(
8608+
aLoadState->TriggeringClassificationFlags());
85768609
loadState->SetCsp(aLoadState->Csp());
85778610
loadState->SetInheritPrincipal(aLoadState->HasInternalLoadFlags(
85788611
INTERNAL_LOAD_FLAGS_INHERIT_PRINCIPAL));
@@ -10775,6 +10808,9 @@ nsresult nsDocShell::DoURILoad(nsDocShellLoadState* aLoadState,
1077510808
loadInfo->SetTriggeringWindowId(aLoadState->TriggeringWindowId());
1077610809
loadInfo->SetTriggeringStorageAccess(aLoadState->TriggeringStorageAccess());
1077710810
loadInfo->SetTriggeringSandboxFlags(aLoadState->TriggeringSandboxFlags());
10811+
net::ClassificationFlags flags = aLoadState->TriggeringClassificationFlags();
10812+
loadInfo->SetTriggeringFirstPartyClassificationFlags(flags.firstPartyFlags);
10813+
loadInfo->SetTriggeringThirdPartyClassificationFlags(flags.thirdPartyFlags);
1077810814
loadInfo->SetIsMetaRefresh(aLoadState->IsMetaRefresh());
1077910815

1078010816
uint32_t cacheKey = 0;
@@ -13239,6 +13275,8 @@ nsresult nsDocShell::OnLinkClick(
1323913275
ownerDoc->ConsumeTextDirectiveUserActivation() ||
1324013276
hasValidUserGestureActivation);
1324113277
loadState->SetUserNavigationInvolvement(aUserInvolvement);
13278+
loadState->SetTriggeringClassificationFlags(
13279+
ownerDoc->GetScriptTrackingFlags());
1324213280

1324313281
nsCOMPtr<nsIRunnable> ev = new OnLinkClickEvent(
1324413282
this, aContent, loadState, noOpenerImplied, aTriggeringPrincipal);

docshell/base/nsDocShellLoadState.cpp

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,7 @@ nsDocShellLoadState::nsDocShellLoadState(
9393
mTriggeringSandboxFlags = aLoadState.TriggeringSandboxFlags();
9494
mTriggeringWindowId = aLoadState.TriggeringWindowId();
9595
mTriggeringStorageAccess = aLoadState.TriggeringStorageAccess();
96+
mTriggeringClassificationFlags = aLoadState.TriggeringClassificationFlags();
9697
mTriggeringRemoteType = aLoadState.TriggeringRemoteType();
9798
mSchemelessInput = aLoadState.SchemelessInput();
9899
mHttpsUpgradeTelemetry = aLoadState.HttpsUpgradeTelemetry();
@@ -161,6 +162,7 @@ nsDocShellLoadState::nsDocShellLoadState(const nsDocShellLoadState& aOther)
161162
mTriggeringSandboxFlags(aOther.mTriggeringSandboxFlags),
162163
mTriggeringWindowId(aOther.mTriggeringWindowId),
163164
mTriggeringStorageAccess(aOther.mTriggeringStorageAccess),
165+
mTriggeringClassificationFlags(aOther.mTriggeringClassificationFlags),
164166
mCsp(aOther.mCsp),
165167
mKeepResultPrincipalURIIfSet(aOther.mKeepResultPrincipalURIIfSet),
166168
mLoadReplace(aOther.mLoadReplace),
@@ -222,6 +224,7 @@ nsDocShellLoadState::nsDocShellLoadState(nsIURI* aURI, uint64_t aLoadIdentifier)
222224
mTriggeringSandboxFlags(0),
223225
mTriggeringWindowId(0),
224226
mTriggeringStorageAccess(false),
227+
mTriggeringClassificationFlags({0, 0}),
225228
mKeepResultPrincipalURIIfSet(false),
226229
mLoadReplace(false),
227230
mInheritPrincipal(false),
@@ -480,6 +483,9 @@ nsresult nsDocShellLoadState::CreateFromLoadURIOptions(
480483
loadState->SetTriggeringWindowId(aLoadURIOptions.mTriggeringWindowId);
481484
loadState->SetTriggeringStorageAccess(
482485
aLoadURIOptions.mTriggeringStorageAccess);
486+
// The load is assumed to be first-party, so the triggering classification
487+
// should be both zero.
488+
loadState->SetTriggeringClassificationFlags({0, 0});
483489
loadState->SetPostDataStream(postData);
484490
loadState->SetHeadersStream(aLoadURIOptions.mHeaders);
485491
loadState->SetBaseURI(aLoadURIOptions.mBaseURI);
@@ -619,6 +625,16 @@ bool nsDocShellLoadState::TriggeringStorageAccess() const {
619625
return mTriggeringStorageAccess;
620626
}
621627

628+
mozilla::net::ClassificationFlags
629+
nsDocShellLoadState::TriggeringClassificationFlags() const {
630+
return mTriggeringClassificationFlags;
631+
}
632+
633+
void nsDocShellLoadState::SetTriggeringClassificationFlags(
634+
mozilla::net::ClassificationFlags aFlags) {
635+
mTriggeringClassificationFlags = aFlags;
636+
}
637+
622638
bool nsDocShellLoadState::InheritPrincipal() const { return mInheritPrincipal; }
623639

624640
void nsDocShellLoadState::SetInheritPrincipal(bool aInheritPrincipal) {
@@ -1364,6 +1380,7 @@ DocShellLoadStateInit nsDocShellLoadState::Serialize(
13641380
loadState.TriggeringSandboxFlags() = mTriggeringSandboxFlags;
13651381
loadState.TriggeringWindowId() = mTriggeringWindowId;
13661382
loadState.TriggeringStorageAccess() = mTriggeringStorageAccess;
1383+
loadState.TriggeringClassificationFlags() = mTriggeringClassificationFlags;
13671384
loadState.TriggeringRemoteType() = mTriggeringRemoteType;
13681385
loadState.SchemelessInput() = mSchemelessInput;
13691386
loadState.HttpsUpgradeTelemetry() = mHttpsUpgradeTelemetry;

docshell/base/nsDocShellLoadState.h

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
#include "mozilla/dom/SessionHistoryEntry.h"
1313
#include "mozilla/dom/UserNavigationInvolvement.h"
1414

15+
#include "nsIClassifiedChannel.h"
1516
#include "nsILoadInfo.h"
1617

1718
// Helper Classes
@@ -127,6 +128,10 @@ class nsDocShellLoadState final {
127128

128129
void SetTriggeringStorageAccess(bool aTriggeringStorageAccess);
129130

131+
mozilla::net::ClassificationFlags TriggeringClassificationFlags() const;
132+
void SetTriggeringClassificationFlags(
133+
mozilla::net::ClassificationFlags aFlags);
134+
130135
nsIContentSecurityPolicy* Csp() const;
131136

132137
void SetCsp(nsIContentSecurityPolicy* aCsp);
@@ -484,6 +489,10 @@ class nsDocShellLoadState final {
484489
uint64_t mTriggeringWindowId;
485490
bool mTriggeringStorageAccess;
486491

492+
// The classification flags of the context responsible for causing
493+
// the load to start.
494+
mozilla::net::ClassificationFlags mTriggeringClassificationFlags;
495+
487496
// The CSP of the load, that is, the CSP of the entity responsible for causing
488497
// the load to occur. Most likely this is the CSP of the document that started
489498
// the load. In case the entity starting the load did not use a CSP, then mCsp

dom/base/Document.cpp

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -343,6 +343,7 @@
343343
#include "nsICSSLoaderObserver.h"
344344
#include "nsICategoryManager.h"
345345
#include "nsICertOverrideService.h"
346+
#include "nsIClassifiedChannel.h"
346347
#include "nsIContent.h"
347348
#include "nsIContentInlines.h"
348349
#include "nsIContentPolicy.h"
@@ -1507,6 +1508,7 @@ Document::Document(const char* aContentType)
15071508
mThrowOnDynamicMarkupInsertionCounter(0),
15081509
mIgnoreOpensDuringUnloadCounter(0),
15091510
mSavedResolution(1.0f),
1511+
mClassificationFlags({0, 0}),
15101512
mGeneration(0),
15111513
mCachedTabSizeGeneration(0),
15121514
mNextFormNumber(0),
@@ -3630,6 +3632,15 @@ nsresult Document::StartDocumentLoad(const char* aCommand, nsIChannel* aChannel,
36303632
WarnIfSandboxIneffective(docShell, mSandboxFlags, GetChannel());
36313633
}
36323634

3635+
nsCOMPtr<nsIClassifiedChannel> classifiedChannel =
3636+
do_QueryInterface(aChannel);
3637+
3638+
if (classifiedChannel) {
3639+
mClassificationFlags = {
3640+
classifiedChannel->GetFirstPartyClassificationFlags(),
3641+
classifiedChannel->GetThirdPartyClassificationFlags()};
3642+
}
3643+
36333644
// Set the opener policy for the top level content document.
36343645
nsCOMPtr<nsIHttpChannelInternal> httpChan = do_QueryInterface(mChannel);
36353646
nsILoadInfo::CrossOriginOpenerPolicy policy =

dom/base/Document.h

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3900,6 +3900,13 @@ class Document : public nsINode,
39003900
// classification flags of the document.
39013901
net::ClassificationFlags GetScriptTrackingFlags() const;
39023902

3903+
net::ClassificationFlags GetClassificationFlags() {
3904+
return mClassificationFlags;
3905+
}
3906+
void SetClassificationFlags(net::ClassificationFlags aFlags) {
3907+
mClassificationFlags = aFlags;
3908+
}
3909+
39033910
// ResizeObserver usage.
39043911
void AddResizeObserver(ResizeObserver& aObserver) {
39053912
MOZ_ASSERT(!mResizeObservers.Contains(&aObserver));
@@ -5539,6 +5546,8 @@ class Document : public nsINode,
55395546

55405547
bool mHasStoragePermission;
55415548

5549+
net::ClassificationFlags mClassificationFlags;
5550+
55425551
// Document generation. Gets incremented everytime it changes.
55435552
int32_t mGeneration;
55445553

dom/base/LocationBase.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
#include "mozilla/dom/LocationBase.h"
88
#include "nsIScriptSecurityManager.h"
99
#include "nsIScriptContext.h"
10+
#include "nsIClassifiedChannel.h"
1011
#include "nsDocShellLoadState.h"
1112
#include "nsIWebNavigation.h"
1213
#include "nsNetUtil.h"
@@ -113,6 +114,7 @@ already_AddRefed<nsDocShellLoadState> LocationBase::CheckURL(
113114
loadState->HasValidUserGestureActivation());
114115
loadState->SetTriggeringWindowId(doc->InnerWindowID());
115116
loadState->SetTriggeringStorageAccess(doc->UsingStorageAccess());
117+
loadState->SetTriggeringClassificationFlags(doc->GetScriptTrackingFlags());
116118

117119
return loadState.forget();
118120
}

dom/base/nsFrameLoader.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -715,6 +715,8 @@ nsresult nsFrameLoader::ReallyStartLoadingInternal() {
715715
if (ownerDoc) {
716716
loadState->SetTriggeringStorageAccess(ownerDoc->UsingStorageAccess());
717717
loadState->SetTriggeringWindowId(ownerDoc->InnerWindowID());
718+
loadState->SetTriggeringClassificationFlags(
719+
ownerDoc->GetScriptTrackingFlags());
718720
}
719721

720722
// If we're loading the default about:blank document in a <browser> element,

dom/ipc/DOMTypes.ipdlh

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ include "mozilla/dom/notification/IPCUtils.h";
1717
include "mozilla/ipc/URIUtils.h";
1818
include "mozilla/layers/LayersMessageUtils.h";
1919
include "mozilla/net/NeckoMessageUtils.h";
20+
include "mozilla/URLClassifierIPCUtils.h";
2021

2122
include IPCBlob;
2223
include IPCStream;
@@ -60,6 +61,7 @@ using mozilla::TimeStamp from "mozilla/TimeStamp.h";
6061
[MoveOnly] using class mozilla::ipc::BigBuffer from "mozilla/ipc/BigBuffer.h";
6162
using mozilla::dom::NotificationDirection from "mozilla/dom/NotificationBinding.h";
6263
using mozilla::dom::UserNavigationInvolvement from "mozilla/dom/UserNavigationInvolvement.h";
64+
using mozilla::net::ClassificationFlags from "nsIClassifiedChannel.h";
6365

6466
namespace mozilla {
6567
namespace dom {
@@ -204,6 +206,7 @@ struct DocShellLoadStateInit
204206
uint32_t TriggeringSandboxFlags;
205207
uint64_t TriggeringWindowId;
206208
bool TriggeringStorageAccess;
209+
ClassificationFlags TriggeringClassificationFlags;
207210
int32_t? CancelContentJSEpoch;
208211

209212
bool ResultPrincipalURIIsSome;

netwerk/ipc/DocumentLoadListener.cpp

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@
4949
#include "nsExternalHelperAppService.h"
5050
#include "nsHttpChannel.h"
5151
#include "nsIBrowser.h"
52+
#include "nsIClassifiedChannel.h"
5253
#include "nsIHttpChannelInternal.h"
5354
#include "nsIStreamConverterService.h"
5455
#include "nsIViewSourceChannel.h"
@@ -173,6 +174,12 @@ static auto CreateDocumentLoadInfo(CanonicalBrowsingContext* aBrowsingContext,
173174
loadInfo->SetTriggeringSandboxFlags(aLoadState->TriggeringSandboxFlags());
174175
loadInfo->SetTriggeringWindowId(aLoadState->TriggeringWindowId());
175176
loadInfo->SetTriggeringStorageAccess(aLoadState->TriggeringStorageAccess());
177+
ClassificationFlags classificationFlags =
178+
aLoadState->TriggeringClassificationFlags();
179+
loadInfo->SetTriggeringFirstPartyClassificationFlags(
180+
classificationFlags.firstPartyFlags);
181+
loadInfo->SetTriggeringThirdPartyClassificationFlags(
182+
classificationFlags.thirdPartyFlags);
176183
loadInfo->SetHasValidUserGestureActivation(
177184
aLoadState->HasValidUserGestureActivation());
178185
loadInfo->SetTextDirectiveUserActivation(
@@ -206,6 +213,12 @@ static auto CreateObjectLoadInfo(nsDocShellLoadState* aLoadState,
206213
loadInfo->SetTriggeringSandboxFlags(aLoadState->TriggeringSandboxFlags());
207214
loadInfo->SetTriggeringWindowId(aLoadState->TriggeringWindowId());
208215
loadInfo->SetTriggeringStorageAccess(aLoadState->TriggeringStorageAccess());
216+
net::ClassificationFlags classificationFlags =
217+
aLoadState->TriggeringClassificationFlags();
218+
loadInfo->SetTriggeringFirstPartyClassificationFlags(
219+
classificationFlags.firstPartyFlags);
220+
loadInfo->SetTriggeringThirdPartyClassificationFlags(
221+
classificationFlags.thirdPartyFlags);
209222
loadInfo->SetIsMetaRefresh(aLoadState->IsMetaRefresh());
210223

211224
return loadInfo.forget();

toolkit/components/windowwatcher/nsWindowWatcher.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2088,6 +2088,8 @@ already_AddRefed<nsDocShellLoadState> nsWindowWatcher::CreateLoadState(
20882088
loadState->SetTextDirectiveUserActivation(
20892089
parentDoc->ConsumeTextDirectiveUserActivation() ||
20902090
loadState->HasValidUserGestureActivation());
2091+
loadState->SetTriggeringClassificationFlags(
2092+
parentDoc->GetScriptTrackingFlags());
20912093
}
20922094
}
20932095

0 commit comments

Comments
 (0)