forked from WebKit/WebKit
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Main frame PDFs served with CSP sandbox header do not load
https://bugs.webkit.org/show_bug.cgi?id=284594 rdar://141166987 Reviewed by NOBODY (OOPS!). The PDF plugin is an internal WebKit implementation detail, and thus should not be subjected to the CSP sandbox. This patch makes sure we bypass the sandbox in SubframeLoader::pluginIsLoadable(). Note that we only do so for main frame PDFs. The embedded PDF case's behavior is directed by whatwg/html#3958, and the WPT `html/semantics/embedded-content/the-iframe-element/sandbox_004.htm`. Also, add two new API tests that assert correct loading behavior. The latter enables UnifiedPDFPlugin while the former tests legacy PDF plugin. - ContentSecurityPolicy.LoadPDFWithSandboxCSPDirective - UnifiedPDF.LoadPDFWithSandboxCSPDirective The rest of the change involves adding new test helpers to facilitate the API tests, TestWKWebView interface to sample colors (which, by the way, should be adopted by many tests), and the fallout unified source build fixes required for a clean build. * Source/WebCore/html/HTMLPlugInImageElement.h: * Source/WebCore/loader/SubframeLoader.cpp: (WebCore::FrameLoader::SubframeLoader::pluginIsLoadable const): (WebCore::FrameLoader::SubframeLoader::requestPlugin): (WebCore::FrameLoader::SubframeLoader::pluginIsLoadable): Deleted. * Source/WebCore/loader/SubframeLoader.h: * Tools/TestWebKitAPI/SourcesCocoa.txt: * Tools/TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj: * Tools/TestWebKitAPI/Tests/WebKit/WKThumbnailView.mm: * Tools/TestWebKitAPI/Tests/WebKitCocoa/ContentSecurityPolicy.mm: (TEST(ContentSecurityPolicy, LoadPDFWithSandboxCSPDirective)): * Tools/TestWebKitAPI/Tests/WebKitCocoa/ContentSecurityPolicyTestHelpers.h: Copied from Tools/TestWebKitAPI/cocoa/CGImagePixelReader.h. * Tools/TestWebKitAPI/Tests/WebKitCocoa/ContentSecurityPolicyTestHelpers.mm: Copied from Tools/TestWebKitAPI/cocoa/CGImagePixelReader.h. (TestWebKitAPI::runLoadPDFWithSandboxCSPDirectiveTest): * Tools/TestWebKitAPI/Tests/WebKitCocoa/CookieAcceptPolicy.mm: * Tools/TestWebKitAPI/Tests/WebKitCocoa/DocumentEditingContext.mm: (applyStyle): Deleted. (applyAhemStyle): Deleted. * Tools/TestWebKitAPI/Tests/WebKitCocoa/EditorStateTests.mm: (): Deleted. (TestWebKitAPI::applyAhemStyle): Deleted. Fix ODR violation by pushing applyAhemStyle into specific namespaces. * Tools/TestWebKitAPI/Tests/WebKitCocoa/ElementTargetingTests.mm: * Tools/TestWebKitAPI/Tests/WebKitCocoa/NavigationAction.mm: * Tools/TestWebKitAPI/Tests/WebKitCocoa/SiteIsolation.mm: * Tools/TestWebKitAPI/Tests/WebKitCocoa/TextWidth.mm: * Tools/TestWebKitAPI/Tests/WebKitCocoa/UnifiedPDFTests.mm: (TestWebKitAPI::UNIFIED_PDF_TEST): (TestWebKitAPI::sampleColorsInWebView): Deleted. * Tools/TestWebKitAPI/Tests/ios/KeyboardInputTestsIOS.mm: * Tools/TestWebKitAPI/Tests/mac/WKWebViewMacEditingTests.mm: * Tools/TestWebKitAPI/cocoa/CGImagePixelReader.cpp: * Tools/TestWebKitAPI/cocoa/CGImagePixelReader.h: * Tools/TestWebKitAPI/cocoa/HTTPServer.h: (TestWebKitAPI::HTTPResponse::HTTPResponse): * Tools/TestWebKitAPI/cocoa/TestWKWebView.h: * Tools/TestWebKitAPI/cocoa/TestWKWebView.mm: (-[TestWKWebView sampleColors]): (-[TestWKWebView sampleColorsWithInterval:]):
- Loading branch information
Showing
28 changed files
with
455 additions
and
295 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
34 changes: 34 additions & 0 deletions
34
Tools/TestWebKitAPI/Tests/WebKitCocoa/ContentSecurityPolicyTestHelpers.h
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
/* | ||
* Copyright (C) 2024 Apple Inc. All rights reserved. | ||
* | ||
* Redistribution and use in source and binary forms, with or without | ||
* modification, are permitted provided that the following conditions | ||
* are met: | ||
* 1. Redistributions of source code must retain the above copyright | ||
* notice, this list of conditions and the following disclaimer. | ||
* 2. Redistributions in binary form must reproduce the above copyright | ||
* notice, this list of conditions and the following disclaimer in the | ||
* documentation and/or other materials provided with the distribution. | ||
* | ||
* THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS'' | ||
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, | ||
* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR | ||
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS | ||
* BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR | ||
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF | ||
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS | ||
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN | ||
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) | ||
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF | ||
* THE POSSIBILITY OF SUCH DAMAGE. | ||
*/ | ||
|
||
#pragma once | ||
|
||
OBJC_CLASS TestWKWebView; | ||
|
||
namespace TestWebKitAPI { | ||
|
||
void runLoadPDFWithSandboxCSPDirectiveTest(TestWKWebView *); | ||
|
||
} |
59 changes: 59 additions & 0 deletions
59
Tools/TestWebKitAPI/Tests/WebKitCocoa/ContentSecurityPolicyTestHelpers.mm
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
/* | ||
* Copyright (C) 2024 Apple Inc. All rights reserved. | ||
* | ||
* Redistribution and use in source and binary forms, with or without | ||
* modification, are permitted provided that the following conditions | ||
* are met: | ||
* 1. Redistributions of source code must retain the above copyright | ||
* notice, this list of conditions and the following disclaimer. | ||
* 2. Redistributions in binary form must reproduce the above copyright | ||
* notice, this list of conditions and the following disclaimer in the | ||
* documentation and/or other materials provided with the distribution. | ||
* | ||
* THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS'' | ||
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, | ||
* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR | ||
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS | ||
* BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR | ||
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF | ||
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS | ||
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN | ||
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) | ||
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF | ||
* THE POSSIBILITY OF SUCH DAMAGE. | ||
*/ | ||
|
||
#import "config.h" | ||
#import "ContentSecurityPolicyTestHelpers.h" | ||
|
||
#import "HTTPServer.h" | ||
#import "PlatformUtilities.h" | ||
#import "TestWKWebView.h" | ||
#import <WebCore/Color.h> | ||
#import <wtf/RetainPtr.h> | ||
#import <wtf/Vector.h> | ||
|
||
namespace TestWebKitAPI { | ||
|
||
static HTTPServer pdfServerWithSandboxCSPDirective() | ||
{ | ||
RetainPtr pdfURL = [NSBundle.test_resourcesBundle URLForResource:@"test" withExtension:@"pdf"]; | ||
HTTPResponse response { [NSData dataWithContentsOfURL:pdfURL.get()] }; | ||
response.headerFields.set("Content-Security-Policy"_s, "sandbox allow-scripts;"_s); | ||
return { { { "/"_s, response } } }; | ||
} | ||
|
||
void runLoadPDFWithSandboxCSPDirectiveTest(TestWKWebView *webView) | ||
{ | ||
HTTPServer server { pdfServerWithSandboxCSPDirective() }; | ||
|
||
[webView synchronouslyLoadRequest:[NSURLRequest requestWithURL:[NSBundle.test_resourcesBundle URLForResource:@"test" withExtension:@"pdf"]]]; | ||
auto colorsWithPlainResponse = [webView sampleColors]; | ||
|
||
[webView synchronouslyLoadRequest:server.request()]; | ||
auto colorsWithCSPResponse = [webView sampleColors]; | ||
|
||
EXPECT_EQ(colorsWithPlainResponse, colorsWithCSPResponse); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.