Skip to content

Commit

Permalink
Bug 1914286 - Remove NS_RelaxStrictFileOriginPolicy. r=smaug,necko-re…
Browse files Browse the repository at this point in the history
…viewers,kershaw

Differential Revision: https://phabricator.services.mozilla.com/D219921
  • Loading branch information
vyv03354 committed Aug 23, 2024
1 parent 493131b commit 7a6cd72
Show file tree
Hide file tree
Showing 8 changed files with 1 addition and 100 deletions.
12 changes: 0 additions & 12 deletions caps/BasePrincipal.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -793,18 +793,6 @@ BasePrincipal::IsL10nAllowed(nsIURI* aURI, bool* aRes) {
return NS_OK;
}

NS_IMETHODIMP
BasePrincipal::AllowsRelaxStrictFileOriginPolicy(nsIURI* aURI, bool* aRes) {
*aRes = false;
nsCOMPtr<nsIURI> prinURI;
nsresult rv = GetURI(getter_AddRefs(prinURI));
if (NS_FAILED(rv) || !prinURI) {
return NS_OK;
}
*aRes = NS_RelaxStrictFileOriginPolicy(aURI, prinURI);
return NS_OK;
}

NS_IMETHODIMP
BasePrincipal::GetPrefLightCacheKey(nsIURI* aURI, bool aWithCredentials,
const OriginAttributes& aOriginAttributes,
Expand Down
2 changes: 0 additions & 2 deletions caps/BasePrincipal.h
Original file line number Diff line number Diff line change
Expand Up @@ -182,8 +182,6 @@ class BasePrincipal : public nsJSPrincipals {
bool* aOutAllowed) override;
NS_IMETHOD GetAsciiHost(nsACString& aAsciiHost) override;
NS_IMETHOD GetLocalStorageQuotaKey(nsACString& aRes) override;
NS_IMETHOD AllowsRelaxStrictFileOriginPolicy(nsIURI* aURI,
bool* aRes) override;
NS_IMETHOD CreateReferrerInfo(mozilla::dom::ReferrerPolicy aReferrerPolicy,
nsIReferrerInfo** _retval) override;
NS_IMETHOD GetIsScriptAllowedByPolicy(
Expand Down
8 changes: 0 additions & 8 deletions caps/ContentPrincipal.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -305,14 +305,6 @@ bool ContentPrincipal::MayLoadInternal(nsIURI* aURI) {
return true;
}

// If strict file origin policy is in effect, local files will always fail
// SecurityCompareURIs unless they are identical. Explicitly check file origin
// policy, in that case.
if (nsScriptSecurityManager::GetStrictFileOriginPolicy() &&
NS_URIIsLocalFile(aURI) && NS_RelaxStrictFileOriginPolicy(aURI, mURI)) {
return true;
}

return false;
}

Expand Down
8 changes: 0 additions & 8 deletions caps/nsIPrincipal.idl
Original file line number Diff line number Diff line change
Expand Up @@ -419,14 +419,6 @@ interface nsIPrincipal : nsISupports
[infallible]
boolean isSameOrigin(in nsIURI otherURI);

/*
* Checks if the Principal is allowed to load the Provided file:// URI
* using NS_RelaxStrictFileOriginPolicy
*
* May be called from any thread.
*/
boolean allowsRelaxStrictFileOriginPolicy(in nsIURI aURI);


/*
* Generates a Cache-Key for the Cors-Preflight Cache
Expand Down
14 changes: 0 additions & 14 deletions dom/workers/WorkerLoadInfo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -333,20 +333,6 @@ bool WorkerLoadInfo::PrincipalURIMatchesScriptURL() {
return true;
}

// If strict file origin policy is in effect, local files will always fail
// IsSameOrigin unless they are identical. Explicitly check file origin
// policy, in that case.

bool allowsRelaxedOriginPolicy = false;
rv = mPrincipal->AllowsRelaxStrictFileOriginPolicy(
mBaseURI, &allowsRelaxedOriginPolicy);

if (nsScriptSecurityManager::GetStrictFileOriginPolicy() &&
NS_URIIsLocalFile(mBaseURI) &&
(NS_SUCCEEDED(rv) && allowsRelaxedOriginPolicy)) {
return true;
}

return false;
}
#endif // MOZ_DIAGNOSTIC_ASSERT_ENABLED
Expand Down
47 changes: 1 addition & 46 deletions netwerk/base/nsNetUtil.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2450,8 +2450,7 @@ bool NS_SecurityCompareURIs(nsIURI* aSourceURI, nsIURI* aTargetURI,
return false;
}

// For file scheme, reject unless the files are identical. See
// NS_RelaxStrictFileOriginPolicy for enforcing file same-origin checking
// For file scheme, reject unless the files are identical.
if (targetScheme.EqualsLiteral("file")) {
// in traditional unsafe behavior all files are the same origin
if (!aStrictFileOriginPolicy) return true;
Expand Down Expand Up @@ -2520,50 +2519,6 @@ bool NS_URIIsLocalFile(nsIURI* aURI) {
isFile;
}

bool NS_RelaxStrictFileOriginPolicy(nsIURI* aTargetURI, nsIURI* aSourceURI,
bool aAllowDirectoryTarget /* = false */) {
if (!NS_URIIsLocalFile(aTargetURI)) {
// This is probably not what the caller intended
MOZ_ASSERT_UNREACHABLE(
"NS_RelaxStrictFileOriginPolicy called with non-file URI");
return false;
}

if (!NS_URIIsLocalFile(aSourceURI)) {
// If the source is not also a file: uri then forget it
// (don't want resource: principals in a file: doc)
//
// note: we're not de-nesting jar: uris here, we want to
// keep archive content bottled up in its own little island
return false;
}

//
// pull out the internal files
//
nsCOMPtr<nsIFileURL> targetFileURL(do_QueryInterface(aTargetURI));
nsCOMPtr<nsIFileURL> sourceFileURL(do_QueryInterface(aSourceURI));
nsCOMPtr<nsIFile> targetFile;
nsCOMPtr<nsIFile> sourceFile;
bool targetIsDir;

// Make sure targetFile is not a directory (bug 209234)
// and that it exists w/out unescaping (bug 395343)
if (!sourceFileURL || !targetFileURL ||
NS_FAILED(targetFileURL->GetFile(getter_AddRefs(targetFile))) ||
NS_FAILED(sourceFileURL->GetFile(getter_AddRefs(sourceFile))) ||
!targetFile || !sourceFile || NS_FAILED(targetFile->Normalize()) ||
#ifndef MOZ_WIDGET_ANDROID
NS_FAILED(sourceFile->Normalize()) ||
#endif
(!aAllowDirectoryTarget &&
(NS_FAILED(targetFile->IsDirectory(&targetIsDir)) || targetIsDir))) {
return false;
}

return false;
}

bool NS_IsInternalSameURIRedirect(nsIChannel* aOldChannel,
nsIChannel* aNewChannel, uint32_t aFlags) {
if (!(aFlags & nsIChannelEventSink::REDIRECT_INTERNAL)) {
Expand Down
9 changes: 0 additions & 9 deletions netwerk/base/nsNetUtil.h
Original file line number Diff line number Diff line change
Expand Up @@ -878,15 +878,6 @@ bool NS_SecurityCompareURIs(nsIURI* aSourceURI, nsIURI* aTargetURI,

bool NS_URIIsLocalFile(nsIURI* aURI);

// When strict file origin policy is enabled, SecurityCompareURIs will fail for
// file URIs that do not point to the same local file. This call provides an
// alternate file-specific origin check that allows target files that are
// contained in the same directory as the source.
//
// https://developer.mozilla.org/en-US/docs/Same-origin_policy_for_file:_URIs
bool NS_RelaxStrictFileOriginPolicy(nsIURI* aTargetURI, nsIURI* aSourceURI,
bool aAllowDirectoryTarget = false);

bool NS_IsInternalSameURIRedirect(nsIChannel* aOldChannel,
nsIChannel* aNewChannel, uint32_t aFlags);

Expand Down
1 change: 0 additions & 1 deletion tools/@types/lib.gecko.xpcom.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1297,7 +1297,6 @@ interface nsIPrincipal extends nsISupports {
isURIInList(list: string): boolean;
isContentAccessibleAboutURI(): boolean;
isSameOrigin(otherURI: nsIURI): boolean;
allowsRelaxStrictFileOriginPolicy(aURI: nsIURI): boolean;
hasFirstpartyStorageAccess(aWindow: mozIDOMWindow, rejectedReason: OutParam<u32>): boolean;
readonly localStorageQuotaKey: string;
readonly isOriginPotentiallyTrustworthy: boolean;
Expand Down

0 comments on commit 7a6cd72

Please sign in to comment.