Bug 34296 - Provide a way for WebKit clients to specify a more granular policy for cross-origin frame access
Summary: Provide a way for WebKit clients to specify a more granular policy for cross-...
Status: RESOLVED FIXED
Alias: None
Product: WebKit
Classification: Unclassified
Component: WebCore Misc. (show other bugs)
Version: 528+ (Nightly build)
Hardware: All All
: P2 Normal
Assignee: Nobody
URL:
Keywords: InRadar
Depends on:
Blocks:
 
Reported: 2010-01-28 17:43 PST by Mike Thole
Modified: 2010-03-09 15:48 PST (History)
7 users (show)

See Also:


Attachments
Add whitelist check to SecurityOrigin::canAccess() (560 bytes, patch)
2010-01-29 11:12 PST, Mike Thole
no flags Details | Formatted Diff | Diff
New patch. Adds SecurityOrigin::allowDOMAccessFromOrigin() for explicitly granting cross-origin DOM access via a whitelist (63.46 KB, patch)
2010-03-03 13:02 PST, Mike Thole
no flags Details | Formatted Diff | Diff
Updated patch: Updates chromium's WebSecurityPolicy (67.49 KB, patch)
2010-03-04 11:47 PST, Mike Thole
no flags Details | Formatted Diff | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Mike Thole 2010-01-28 17:43:20 PST
Similar to https://bugs.webkit.org/show_bug.cgi?id=24853, which provides whitelist functionality for XHR access, WebKit should provide a similar method for allow cross-origin frame access.
Comment 1 Mike Thole 2010-01-29 11:12:06 PST
Created attachment 47724 [details]
Add whitelist check to SecurityOrigin::canAccess()
Comment 2 Mike Thole 2010-01-29 11:20:48 PST
In related bug 24853, Aaron Boodman mentioned that:
"For example, we don't really need (and probably don't want) the ability to do cross-frame scripting."

I wonder what the rationale for not wanting the ability to do cross-frame scripting was?  I added patch (47724) that adds a whiltelist check to SecuriyOrigin::canAccess().  If we still don't want cross-frame access to go along with XHR access, we'll need to do something a little more involved.
Comment 3 Adam Barth 2010-01-29 20:16:55 PST
I don't think this patch is a good idea.  In particular, asymmetric access relations are the source of many security vulnerabilities.  For more information, please read:

http://www.adambarth.com/papers/2009/barth-jackson-li.pdf
Comment 4 Mike Thole 2010-02-18 16:33:37 PST
Currently, a WebKit client that wants to allow cross-origin frame access can do so using WebView's registerURLSchemeAsLocal:, assuming that the allowUniversalAccessFromFileURLs() setting enabled.

What I'm trying to do is allow cross-origin frame access without also treating the custom URL protocol as a local protocol.  The asymmetric access vulnerabilities mentioned in the linked paper are valid reasons for caution, but they can be prevented with careful programming.  WebKit clients should be able to choose to allow cross-frame access without going crazy and giving the URL protocol local access.

The white list functionality added for 24853 seemed ideal for this purpose.  Maybe that API could be modified or added to, such that a WebKit client could explicitly opt-in to cross-origin frame access?  One simple solution would be to add an additional parameter to whiteListAccessFromOrigin() that specified what type of access was whitelisted (just XHR or frame access).

Do you have any suggestions on how this could best be accomplished?
Comment 5 Maciej Stachowiak 2010-02-19 18:43:04 PST
(In reply to comment #4)
> Currently, a WebKit client that wants to allow cross-origin frame access can do
> so using WebView's registerURLSchemeAsLocal:, assuming that the
> allowUniversalAccessFromFileURLs() setting enabled.
> 
> What I'm trying to do is allow cross-origin frame access without also treating
> the custom URL protocol as a local protocol.  The asymmetric access
> vulnerabilities mentioned in the linked paper are valid reasons for caution,
> but they can be prevented with careful programming.  WebKit clients should be
> able to choose to allow cross-frame access without going crazy and giving the
> URL protocol local access.
> 
> The white list functionality added for 24853 seemed ideal for this purpose. 
> Maybe that API could be modified or added to, such that a WebKit client could
> explicitly opt-in to cross-origin frame access?  One simple solution would be
> to add an additional parameter to whiteListAccessFromOrigin() that specified
> what type of access was whitelisted (just XHR or frame access).
> 
> Do you have any suggestions on how this could best be accomplished?

I can see how clients may have valid use cases for an XHR-only whitelist, given Adam's paper. I can also understand that there are valid use cases for giving cross-frame scripting access without granting local access.

I think your idea of extending the whitelisting mechanism makes sense. That way both sets of use cases can be satisfied.
Comment 6 Adam Barth 2010-02-19 20:21:27 PST
I really think we should keep canAccess symmetric.  The web platform isn't designed for asymmetric access.  It might appear to work, but, in reality, the "lesser" origin can almost always compromise the "greater" origin.
Comment 7 Mike Thole 2010-02-22 19:12:59 PST
Although canAccess() isn't entirely symmetric today, given that some SecurityOrigins are granted universal access and canAccess() respects that.
Comment 8 Adam Barth 2010-02-22 22:39:40 PST
> Although canAccess() isn't entirely symmetric today, given that some
> SecurityOrigins are granted universal access and canAccess() respects that.

Indeed.  I'm been on a multi-year odyssey to remove these cases.  I think this situation is removed in the default settings for every port except the Mac port.  My understanding is that future version of Safari will use a the non-default setting but that we're worried about non-Safari clients of WebKit relying on the old (insecure) behavior.
Comment 9 Mike Thole 2010-03-03 13:02:42 PST
Created attachment 49934 [details]
New patch.  Adds SecurityOrigin::allowDOMAccessFromOrigin() for explicitly granting cross-origin DOM access via a whitelist

I think it would be more useful to discuss the specifics of a patch, rather than generalities.  I've created a full patch that renames SecurityOrigin::whiteListAccessFromOrigin() to SecurityOrigin::allowNetworkAccessFromOrigin() and adds SecurityOrigin::allowDOMAccessFromOrigin().  This provides the SPI needed by some clients to explicitly choose to whitelist cross-origin DOM access.
Comment 10 WebKit Review Bot 2010-03-03 13:17:26 PST
Attachment 49934 [details] did not build on chromium:
Build output: http://webkit-commit-queue.appspot.com/results/329033
Comment 11 Darin Adler 2010-03-03 14:34:49 PST
Comment on attachment 49934 [details]
New patch.  Adds SecurityOrigin::allowDOMAccessFromOrigin() for explicitly granting cross-origin DOM access via a whitelist

Chromium build failure:

src/WebSecurityPolicy.cpp: In static member function ‘static void WebKit::WebSecurityPolicy::whiteListAccessFromOrigin(const WebKit::WebURL&, const WebKit::WebString&, const WebKit::WebString&, bool)’:
src/WebSecurityPolicy.cpp:64: error: ‘whiteListAccessFromOrigin’ is not a member of ‘WebCore::SecurityOrigin’
src/WebSecurityPolicy.cpp: In static member function ‘static void WebKit::WebSecurityPolicy::resetOriginAccessWhiteLists()’:
src/WebSecurityPolicy.cpp:71: error: ‘resetOriginAccessWhiteLists’ is not a member of ‘WebCore::SecurityOrigin’
Comment 12 Adam Barth 2010-03-03 19:03:35 PST
Maciej makes the point that we already have a number of dangerous APIs that we expose to the client.  It might make sense to have a large comment warning clients that this API is dangerous in subtle ways.

In any case, I feel like I've said my piece.  If another reviewer thinks the benefits of having this API outweigh the risks to unsuspecting clients, I'm not going to stand in the way.
Comment 13 Mike Thole 2010-03-04 11:47:46 PST
Created attachment 50042 [details]
Updated patch: Updates chromium's WebSecurityPolicy
Comment 14 Mike Thole 2010-03-09 15:48:08 PST
With Adam and Maciej's help I found a different way to achieve what I needed without adding this API.  Closing this bug.