Bug 64813 - HTMLImageElement::crossOrigin is hard to use because of caching
: HTMLImageElement::crossOrigin is hard to use because of caching
Product: WebKit
Classification: Unclassified
Component: Page Loading
: 528+ (Nightly build)
: All All
: P2 Normal
Assigned To: Kenneth Russell
Depends on:
  Show dependency treegraph
Reported: 2011-07-19 11:05 PDT by Adam Barth
Modified: 2011-07-22 17:18 PDT (History)
4 users (show)

See Also:

Patch (7.42 KB, patch)
2011-07-22 15:32 PDT, Kenneth Russell
no flags Details | Formatted Diff | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Adam Barth 2011-07-19 11:05:21 PDT
The crossorigin attribute of HTMLImageElement is hard to use correctly because image responses are often cached.  For example, consider the case where the server always response with the following header:

Access-Control-Allow-Origin: *

If we request the image first without the crossorigin attribute, then we'll send credentials and cache the response in the MemoryCache.  Later, if we request the image with the crossorigin attribute, we'll grab the response out of the MemoryCache, but the CORS check will fail because we'll remember that we sent credentials the first time.

This behavior can be frustrating for web developers who don't understand why the second request isn't allowed.  After all, they said their image was allowed by *.

One possible solution to this problem is to examine the allowCredentials flag when deciding whether the resource in the MemoryCache is appropriate for the given request.  The CachedResourceLoader and CachedResource have a bunch of logic for deciding whether an existing CachedResource is valid for a new request or whether we should evict it and request the resource again.  We could try fixing this issue by including logic to compare the allowCredentials flag in this code path.
Comment 1 Kenneth Russell 2011-07-21 17:59:53 PDT
Looking into this.
Comment 2 Kenneth Russell 2011-07-22 15:32:06 PDT
Created attachment 101779 [details]
Comment 3 Adam Barth 2011-07-22 15:34:19 PDT
Comment on attachment 101779 [details]

Look great.  Thanks!
Comment 4 WebKit Review Bot 2011-07-22 17:18:49 PDT
Comment on attachment 101779 [details]

Clearing flags on attachment: 101779

Committed r91626: <http://trac.webkit.org/changeset/91626>
Comment 5 WebKit Review Bot 2011-07-22 17:18:53 PDT
All reviewed patches have been landed.  Closing bug.