Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Give URLKeepingBlobAlive a top-origin SecurityOriginData #9184

Conversation

sysrqb
Copy link
Contributor

@sysrqb sysrqb commented Jan 26, 2023

6f0e501

Give URLKeepingBlobAlive a top-origin SecurityOriginData
https://bugs.webkit.org/show_bug.cgi?id=251218
rdar://104704879

Reviewed by Chris Dumez.

In this patch we construct the URLKeepingBlobAlive with its associated
top-level SecurityOrigin(Data). This will be helpful in a future patch where we
partition the Blob registry using that top-level origin. URLKeepingBlobAlive
needs this information, in particular, because it is responsible for
automatically registering and unregistering its Blob URL handle - thus keeping
the blob alive as long as it exists, as the class name implies.

* Source/WebCore/Modules/fetch/FetchRequest.cpp:
(WebCore::FetchRequest::FetchRequest):
(WebCore::m_signal):
(WebCore::FetchRequest::initializeWith):
(WebCore::FetchRequest::create):
(WebCore::FetchRequest::clone):
(WebCore::FetchRequest::stop):
* Source/WebCore/Modules/fetch/FetchRequest.h:
(WebCore::FetchRequest::FetchRequest): Deleted.
* Source/WebCore/dom/Document.cpp:
(WebCore::Document::setURL):
* Source/WebCore/fileapi/Blob.cpp:
(WebCore::Blob::Blob):
(WebCore::Blob::handle const):
* Source/WebCore/fileapi/Blob.h:
* Source/WebCore/fileapi/URLKeepingBlobAlive.cpp:
(WebCore::URLKeepingBlobAlive::URLKeepingBlobAlive):
(WebCore::URLKeepingBlobAlive::clear):
(WebCore::URLKeepingBlobAlive::operator=):
(WebCore::URLKeepingBlobAlive::isolatedCopy const):
(WebCore::URLKeepingBlobAlive::isolatedCopy):
* Source/WebCore/fileapi/URLKeepingBlobAlive.h:
(WebCore::URLKeepingBlobAlive::URLKeepingBlobAlive): Deleted.
(WebCore::URLKeepingBlobAlive::operator=): Deleted.
* Source/WebCore/loader/NavigationScheduler.cpp:
* Source/WebCore/loader/PolicyChecker.cpp:
(WebCore::FrameLoader::PolicyChecker::extendBlobURLLifetimeIfNecessary const):
(WebCore::FrameLoader::PolicyChecker::checkNavigationPolicy):
(WebCore::FrameLoader::PolicyChecker::checkNewWindowPolicy):
* Source/WebCore/loader/PolicyChecker.h:
* Source/WebCore/workers/WorkerGlobalScope.cpp:
(WebCore::WorkerGlobalScope::importScripts):
* Source/WebCore/workers/shared/SharedWorker.cpp:
(WebCore::SharedWorker::SharedWorker):
(WebCore::SharedWorker::didFinishLoading):
* Source/WebCore/xml/XMLHttpRequest.cpp:
(WebCore::XMLHttpRequest::open):
(WebCore::XMLHttpRequest::createRequest):
(WebCore::XMLHttpRequest::clearRequest):
(WebCore::XMLHttpRequest::didFinishLoading):

Canonical link: https://commits.webkit.org/260266@main

54ff216

Misc iOS, tvOS & watchOS macOS Linux Windows
βœ… πŸ§ͺ style βœ… πŸ›  ios βœ… πŸ›  mac βœ… πŸ›  wpe βœ… πŸ›  wincairo
βœ… πŸ§ͺ bindings βœ… πŸ›  ios-sim βœ… πŸ›  mac-AS-debug βœ… πŸ›  gtk
βœ… πŸ§ͺ webkitperl βœ… πŸ§ͺ ios-wk2 βœ… πŸ§ͺ api-mac βœ… πŸ§ͺ gtk-wk2
βœ… πŸ§ͺ api-ios βœ… πŸ§ͺ mac-wk1 βœ… πŸ§ͺ api-gtk
βœ… πŸ›  tv βœ… πŸ§ͺ mac-wk2
βœ… πŸ›  tv-sim βœ… πŸ§ͺ mac-AS-debug-wk2
βœ… πŸ›  watch βœ… πŸ§ͺ mac-wk2-stress
βœ… πŸ›  watch-sim
βœ… πŸ›  πŸ§ͺ unsafe-merge

Copy link
Contributor

@cdumez cdumez left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am not opposed to adding a topOrigin to this class (since this class has Blob in its name). However, I have some other comments.

Source/WebCore/fileapi/Blob.cpp Show resolved Hide resolved
{
ASSERT(context);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think we should have the assertion, not sure what makes this a guarantee

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I didn't find any call sites where the ScriptExecutionContext should be null, so this was only a sanity check.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If call sites never passed null, we would take in a C++ reference, not a pointer. If something is a pointer in WebKit, always assume it can be null. If it really cannot, then update the parameter to be a c++ reference.

{
ASSERT(context);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think we should have the assertion, not sure what makes this a guarantee

@@ -3542,7 +3542,9 @@ void Document::setURL(const URL& url)

if (SecurityOrigin::shouldIgnoreHost(newURL))
newURL.setHostAndPort({ });
m_url = WTFMove(newURL);
// SecurityContext::securityOrigin may not be initialized at this time if setURL() is called in the constructor, therefore calling topOrigin() is not always safe.
auto topOrigin = isTopDocument() && !SecurityContext::securityOrigin() ? SecurityOriginData::fromURL(url) : this->topOrigin().data();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What if the URL is a blob URL? (which is the base we care about I believe).
I see 2 likely issues:

  1. SecurityOriginData::fromURL(url) likely won't be able to extra the origin from a blob URL
  2. Even if we addressed the first issue, how would it enforce partitioning?

Imagine this case:

  • Frame from origin B (under top level origin A) creates a Blob and gets a URL for it. Then it opens a new window and uses this blob URL as URL for the popup. What's supposed to happen? I imagine the blob should have the "A / B" partitioned origin. Seems like we shouldn't be able to load this Blob in a top level popup? If so, I worry that your code here is not going to achieve this (even if we fix issue 1). Am I missing something?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Right, I originally used SecurityOrigin::create(url) for this but I change it in this patch, and that is wrong - we do need SecurityOrigin's logic for handling blob URLs. But, as for (2), there are two options:

  1. the popup has "A / B" blob partitioning (therefore has access to the blob data)
  2. the popup has "B" blob partitioning (therefore doesn't have access to the blob data)

I was following (2) because creating a top-level navigation with subframe partitioning was conceptually confusing and required more invasive code changes. Following (1) will provide better web compat, but I don't know how common is that use case. If you think we should use (1), then this patch will need changes.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think 2 makes sense. The popup would have "B" origin and thus shouldn't be able to load the blob.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Okay, thanks. I also just remembered and realized you are missing some other context. In w3c/FileAPI#153 there is discussion about how to partition blobs, and the general agreement is that cross-origin top-level navigations to a Blob URL should enforce no-opener.

@sysrqb sysrqb force-pushed the eng/Give-URLKeepingBlobAlive-a-top-origin-SecurityOriginData branch from b51bd49 to 6d7ad48 Compare January 27, 2023 08:11
Copy link
Contributor

@cdumez cdumez left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

inline FetchRequest::FetchRequest(ScriptExecutionContext* context, std::optional<FetchBody>&& body, Ref<FetchHeaders>&& headers, ResourceRequest&& request, FetchOptions&& options, String&& referrer)
: FetchBodyOwner(context, WTFMove(body), WTFMove(headers))
, m_request(WTFMove(request))
, m_requestURL({ m_request.url(), context->topOrigin().data() })
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We shouldn't dereference context without a null check. If context really truly can't be null, then we should change the parameter type to be a ScriptExecutionContext&.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Changing the parameter type seemed safe here, so I went ahead and did that.

@sysrqb sysrqb force-pushed the eng/Give-URLKeepingBlobAlive-a-top-origin-SecurityOriginData branch from 6d7ad48 to 79f9ad0 Compare January 27, 2023 16:45
@webkit-ews-buildbot webkit-ews-buildbot added the merging-blocked Applied to prevent a change from being merged label Jan 27, 2023
@sysrqb
Copy link
Contributor Author

sysrqb commented Jan 27, 2023

This needs to wait until #9253, and I don't understand why this failed to compile on Linux because that happened before #9000 was reverted. I'll rebase this after #9253 is merged and let EWS run again.

@sysrqb sysrqb force-pushed the eng/Give-URLKeepingBlobAlive-a-top-origin-SecurityOriginData branch from 79f9ad0 to c6db0fa Compare February 9, 2023 00:23
@sysrqb sysrqb requested a review from a team as a code owner February 9, 2023 00:23
@sysrqb sysrqb force-pushed the eng/Give-URLKeepingBlobAlive-a-top-origin-SecurityOriginData branch from c6db0fa to 54ff216 Compare February 13, 2023 20:29
@sysrqb
Copy link
Contributor Author

sysrqb commented Feb 13, 2023

EWS was all green on the last run, this run is just rebasing onto main now that #9253 is merged.

@achristensen07 achristensen07 added unsafe-merge-queue Applied to send a pull request to merge-queue, but skip building and testing and removed merging-blocked Applied to prevent a change from being merged labels Feb 14, 2023
https://bugs.webkit.org/show_bug.cgi?id=251218
rdar://104704879

Reviewed by Chris Dumez.

In this patch we construct the URLKeepingBlobAlive with its associated
top-level SecurityOrigin(Data). This will be helpful in a future patch where we
partition the Blob registry using that top-level origin. URLKeepingBlobAlive
needs this information, in particular, because it is responsible for
automatically registering and unregistering its Blob URL handle - thus keeping
the blob alive as long as it exists, as the class name implies.

* Source/WebCore/Modules/fetch/FetchRequest.cpp:
(WebCore::FetchRequest::FetchRequest):
(WebCore::m_signal):
(WebCore::FetchRequest::initializeWith):
(WebCore::FetchRequest::create):
(WebCore::FetchRequest::clone):
(WebCore::FetchRequest::stop):
* Source/WebCore/Modules/fetch/FetchRequest.h:
(WebCore::FetchRequest::FetchRequest): Deleted.
* Source/WebCore/dom/Document.cpp:
(WebCore::Document::setURL):
* Source/WebCore/fileapi/Blob.cpp:
(WebCore::Blob::Blob):
(WebCore::Blob::handle const):
* Source/WebCore/fileapi/Blob.h:
* Source/WebCore/fileapi/URLKeepingBlobAlive.cpp:
(WebCore::URLKeepingBlobAlive::URLKeepingBlobAlive):
(WebCore::URLKeepingBlobAlive::clear):
(WebCore::URLKeepingBlobAlive::operator=):
(WebCore::URLKeepingBlobAlive::isolatedCopy const):
(WebCore::URLKeepingBlobAlive::isolatedCopy):
* Source/WebCore/fileapi/URLKeepingBlobAlive.h:
(WebCore::URLKeepingBlobAlive::URLKeepingBlobAlive): Deleted.
(WebCore::URLKeepingBlobAlive::operator=): Deleted.
* Source/WebCore/loader/NavigationScheduler.cpp:
* Source/WebCore/loader/PolicyChecker.cpp:
(WebCore::FrameLoader::PolicyChecker::extendBlobURLLifetimeIfNecessary const):
(WebCore::FrameLoader::PolicyChecker::checkNavigationPolicy):
(WebCore::FrameLoader::PolicyChecker::checkNewWindowPolicy):
* Source/WebCore/loader/PolicyChecker.h:
* Source/WebCore/workers/WorkerGlobalScope.cpp:
(WebCore::WorkerGlobalScope::importScripts):
* Source/WebCore/workers/shared/SharedWorker.cpp:
(WebCore::SharedWorker::SharedWorker):
(WebCore::SharedWorker::didFinishLoading):
* Source/WebCore/xml/XMLHttpRequest.cpp:
(WebCore::XMLHttpRequest::open):
(WebCore::XMLHttpRequest::createRequest):
(WebCore::XMLHttpRequest::clearRequest):
(WebCore::XMLHttpRequest::didFinishLoading):

Canonical link: https://commits.webkit.org/260266@main
@webkit-early-warning-system webkit-early-warning-system force-pushed the eng/Give-URLKeepingBlobAlive-a-top-origin-SecurityOriginData branch from 54ff216 to 6f0e501 Compare February 14, 2023 19:17
@webkit-commit-queue
Copy link
Collaborator

Committed 260266@main (6f0e501): https://commits.webkit.org/260266@main

Reviewed commits have been landed. Closing PR #9184 and removing active labels.

@webkit-commit-queue webkit-commit-queue removed the unsafe-merge-queue Applied to send a pull request to merge-queue, but skip building and testing label Feb 14, 2023
@webkit-early-warning-system webkit-early-warning-system merged commit 6f0e501 into WebKit:main Feb 14, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
6 participants