Changeset 149422 in webkit


Ignore:
Timestamp:
Apr 30, 2013, 10:16:04 PM (12 years ago)
Author:
ap@apple.com
Message:

<rdar://problem/13574729> Implement file path restrictions in WebKit Objective C API
https://bugs.webkit.org/show_bug.cgi?id=115321

Reviewed by Darin Adler.

  • UIProcess/API/C/WKPage.cpp:
  • UIProcess/API/C/WKPage.h:
  • UIProcess/WebPageProxy.cpp: (WebKit::WebPageProxy::loadFile):
  • UIProcess/WebPageProxy.h: Added and implemented a C API to load a file while only opening sandbox for a specific directory.
  • UIProcess/API/mac/WKBrowsingContextController.h: Fixed a typo in a comment.
  • UIProcess/API/mac/WKBrowsingContextController.mm: (-[WKBrowsingContextController loadFileURL:restrictToFilesWithin:]): Respect allowedDirectory argument. Updated the function to raise an exception for incorrect input, as decribed in header file.
Location:
trunk/Source/WebKit2
Files:
7 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebKit2/ChangeLog

    r149417 r149422  
     12013-04-28  Alexey Proskuryakov  <ap@apple.com>
     2
     3        <rdar://problem/13574729> Implement file path restrictions in WebKit Objective C API
     4        https://bugs.webkit.org/show_bug.cgi?id=115321
     5
     6        Reviewed by Darin Adler.
     7
     8        * UIProcess/API/C/WKPage.cpp:
     9        * UIProcess/API/C/WKPage.h:
     10        * UIProcess/WebPageProxy.cpp: (WebKit::WebPageProxy::loadFile):
     11        * UIProcess/WebPageProxy.h:
     12        Added and implemented a C API to load a file while only opening sandbox for
     13        a specific directory.
     14
     15        * UIProcess/API/mac/WKBrowsingContextController.h: Fixed a typo in a comment.
     16
     17        * UIProcess/API/mac/WKBrowsingContextController.mm:
     18        (-[WKBrowsingContextController loadFileURL:restrictToFilesWithin:]):
     19        Respect allowedDirectory argument. Updated the function to raise an exception for
     20        incorrect input, as decribed in header file.
     21
    1222013-04-29  Sam Weinig  <sam@webkit.org>
    223
  • trunk/Source/WebKit2/UIProcess/API/C/WKPage.cpp

    r148420 r149422  
    9393}
    9494
     95void WKPageLoadFile(WKPageRef pageRef, WKURLRef fileURL, WKURLRef resourceDirectoryURL)
     96{
     97    toImpl(pageRef)->loadFile(toWTFString(fileURL), toWTFString(resourceDirectoryURL));
     98}
     99
    95100void WKPageStopLoading(WKPageRef pageRef)
    96101{
  • trunk/Source/WebKit2/UIProcess/API/C/WKPage.h

    r148420 r149422  
    363363WK_EXPORT void WKPageLoadPlainTextString(WKPageRef page, WKStringRef plainTextString);
    364364WK_EXPORT void WKPageLoadWebArchiveData(WKPageRef page, WKDataRef webArchiveData);
     365WK_EXPORT void WKPageLoadFile(WKPageRef page, WKURLRef fileURL, WKURLRef resourceDirectoryURL);
    365366
    366367WK_EXPORT void WKPageStopLoading(WKPageRef page);
  • trunk/Source/WebKit2/UIProcess/API/mac/WKBrowsingContextController.h

    r134681 r149422  
    5151
    5252/* Load a file: URL. Opens the sandbox only for files within allowedDirectory.
    53     - Passing a non-file: URL to either parameter will yeild an exception.
     53    - Passing a non-file: URL to either parameter will yield an exception.
    5454    - Passing nil as the allowedDirectory will open the entire file-system for
    55       reading. 
     55      reading.
    5656*/
    5757- (void)loadFileURL:(NSURL *)URL restrictToFilesWithin:(NSURL *)allowedDirectory;
  • trunk/Source/WebKit2/UIProcess/API/mac/WKBrowsingContextController.mm

    r149255 r149422  
    120120- (void)loadFileURL:(NSURL *)URL restrictToFilesWithin:(NSURL *)allowedDirectory
    121121{
    122     if (![URL isFileURL])
    123         return;
    124 
    125     /* FIXME: Implement restrictions. */
     122    if (![URL isFileURL] || (allowedDirectory && ![allowedDirectory isFileURL]))
     123        [NSException raise:NSInvalidArgumentException format:@"Attempted to load a non-file URL"];
    126124
    127125    WKRetainPtr<WKURLRef> wkURL = adoptWK(WKURLCreateWithCFURL((CFURLRef)URL));
    128     WKPageLoadURL(self._pageRef, wkURL.get());
     126    WKRetainPtr<WKURLRef> wkAllowedDirectory = adoptWK(WKURLCreateWithCFURL((CFURLRef)allowedDirectory));
     127   
     128    WKPageLoadFile(self._pageRef, wkURL.get(), wkAllowedDirectory.get());
    129129}
    130130
  • trunk/Source/WebKit2/UIProcess/WebPageProxy.cpp

    r149279 r149422  
    732732}
    733733
     734void WebPageProxy::loadFile(const String& fileURLString, const String& resourceDirectoryURLString)
     735{
     736    if (!isValid())
     737        reattachToWebProcess();
     738
     739    KURL fileURL = KURL(KURL(), fileURLString);
     740    if (!fileURL.isLocalFile())
     741        return;
     742
     743    String resourceDirectoryPath;
     744    if (!resourceDirectoryURLString.isNull()) {
     745        KURL resourceDirectoryURL = KURL(KURL(), resourceDirectoryURLString);
     746        if (!resourceDirectoryURL.isLocalFile())
     747            return;
     748        resourceDirectoryPath = resourceDirectoryURL.fileSystemPath();
     749    } else
     750        resourceDirectoryPath = ASCIILiteral("/");
     751
     752    SandboxExtension::Handle sandboxExtensionHandle;
     753    SandboxExtension::createHandle(resourceDirectoryPath, SandboxExtension::ReadOnly, sandboxExtensionHandle);
     754    m_process->assumeReadAccessToBaseURL(resourceDirectoryPath);
     755    m_process->send(Messages::WebPage::LoadURL(fileURL, sandboxExtensionHandle), m_pageID);
     756    m_process->responsivenessTimer()->start();
     757}
     758
    734759void WebPageProxy::stopLoading()
    735760{
  • trunk/Source/WebKit2/UIProcess/WebPageProxy.h

    r149147 r149422  
    289289    void loadPlainTextString(const String& string);
    290290    void loadWebArchiveData(const WebData*);
     291    void loadFile(const String& fileURL, const String& resourceDirectoryURL);
    291292
    292293    void stopLoading();
Note: See TracChangeset for help on using the changeset viewer.