| Differences between
and this patch
- a/LayoutTests/ChangeLog +20 lines
Lines 1-3 a/LayoutTests/ChangeLog_sec1
1
2009-08-18  Aaron Boodman  <aa@chromium.org>
2
3
        Reviewed by NOBODY (OOPS!).
4
5
        https://bugs.webkit.org/show_bug.cgi?id=24853: Provide a way for WebKit clients to
6
        specify a more granular policy for cross-origin XHR access.
7
8
        * http/tests/xmlhttprequest/origin-whitelisting-all-expected.txt: Added.
9
        * http/tests/xmlhttprequest/origin-whitelisting-all.html: Added.
10
        * http/tests/xmlhttprequest/origin-whitelisting-exact-match-expected.txt: Added.
11
        * http/tests/xmlhttprequest/origin-whitelisting-exact-match.html: Added.
12
        * http/tests/xmlhttprequest/origin-whitelisting-https-expected.txt: Added.
13
        * http/tests/xmlhttprequest/origin-whitelisting-https.html: Added.
14
        * http/tests/xmlhttprequest/origin-whitelisting-ip-addresses-expected.txt: Added.
15
        * http/tests/xmlhttprequest/origin-whitelisting-ip-addresses-with-subdomains-expected.txt: Added.
16
        * http/tests/xmlhttprequest/origin-whitelisting-ip-addresses-with-subdomains.html: Added.
17
        * http/tests/xmlhttprequest/origin-whitelisting-ip-addresses.html: Added.
18
        * http/tests/xmlhttprequest/origin-whitelisting-subdomains-expected.txt: Added.
19
        * http/tests/xmlhttprequest/origin-whitelisting-subdomains.html: Added.
20
1
2009-08-18  Shinichiro Hamaji  <hamaji@chromium.org>
21
2009-08-18  Shinichiro Hamaji  <hamaji@chromium.org>
2
22
3
        Reviewed by Eric Seidel.
23
        Reviewed by Eric Seidel.
- a/LayoutTests/http/tests/xmlhttprequest/origin-whitelisting-all-expected.txt +11 lines
Line 0 a/LayoutTests/http/tests/xmlhttprequest/origin-whitelisting-all-expected.txt_sec1
1
Tests the special case of whitelisting all origins.
2
3
Testing: http://localhost:8000/xmlhttprequest/resources/get.txt (sync)
4
PASS: PASS
5
Testing: http://localhost:8000/xmlhttprequest/resources/get.txt (async)
6
PASS: PASS
7
Testing: http://127.0.0.1:8000/xmlhttprequest/resources/get.txt (sync)
8
PASS: PASS
9
Testing: http://127.0.0.1:8000/xmlhttprequest/resources/get.txt (async)
10
PASS: PASS
11
- a/LayoutTests/http/tests/xmlhttprequest/origin-whitelisting-all.html +58 lines
Line 0 a/LayoutTests/http/tests/xmlhttprequest/origin-whitelisting-all.html_sec1
1
<p>Tests the special case of whitelisting all origins.</p>
2
3
<pre id="console"></pre>
4
<script>
5
layoutTestController.dumpAsText();
6
layoutTestController.waitUntilDone();
7
layoutTestController.resetOriginAccessWhiteLists();
8
layoutTestController.whiteListAccessToOrigin("http://127.0.0.1:8000", "", true, false);
9
layoutTestController.whiteListAccessToOrigin("http://localhost:8000", "", true, false);
10
11
function log(message)
12
{
13
    document.getElementById('console').appendChild(document.createTextNode(message + '\n'));
14
}
15
16
function testDomain()
17
{
18
    var url = "http://localhost:8000/xmlhttprequest/resources/get.txt";
19
    log("Testing: " + url + " (sync)");
20
    var req = new XMLHttpRequest();
21
    req.open("GET", url, false);
22
    try {
23
        req.send(null);
24
        log("PASS: " + req.responseText);
25
    } catch (e) {
26
        log("FAIL: " + e);
27
    }
28
29
    log("Testing: " + url + " (async)");
30
    req = new XMLHttpRequest();
31
    req.open("GET", url, true);
32
    req.onload = function() {
33
        log("PASS: " + req.responseText);
34
        testIPAddress();
35
    };
36
    req.onerror = function() {
37
        log("FAIL: " + req.status);
38
        testIPAddress();
39
    };
40
    req.send(null);
41
}
42
43
function testIPAddress()
44
{
45
    var iframe = document.createElement("iframe");
46
    document.body.appendChild(iframe);
47
    iframe.src = "http://localhost:8000/xmlhttprequest/resources/origin-whitelisting-ip-address-test.html";
48
    window.addEventListener("message", function(e) {
49
        if (e.data == "DONE") {
50
            layoutTestController.resetOriginAccessWhiteLists();
51
            layoutTestController.notifyDone();
52
        } else
53
            log(e.data);
54
    }, false);
55
}
56
57
testDomain();
58
</script>
- a/LayoutTests/http/tests/xmlhttprequest/origin-whitelisting-exact-match-expected.txt +7 lines
Line 0 a/LayoutTests/http/tests/xmlhttprequest/origin-whitelisting-exact-match-expected.txt_sec1
1
Tests the behavior of whitelisting origins using exact matching.
2
3
Testing: http://localhost:8000/xmlhttprequest/resources/get.txt (sync)
4
PASS: PASS
5
Testing: http://localhost:8000/xmlhttprequest/resources/get.txt (async)
6
PASS: PASS
7
- a/LayoutTests/http/tests/xmlhttprequest/origin-whitelisting-exact-match.html +62 lines
Line 0 a/LayoutTests/http/tests/xmlhttprequest/origin-whitelisting-exact-match.html_sec1
1
<p>Tests the behavior of whitelisting origins using exact matching.</p>
2
3
<pre id="console"></pre>
4
<script>
5
layoutTestController.dumpAsText();
6
layoutTestController.waitUntilDone();
7
layoutTestController.resetOriginAccessWhiteLists();
8
layoutTestController.whiteListAccessToOrigin("http://127.0.0.1:8000", "localhost", false, false);
9
10
function log(message)
11
{
12
    document.getElementById('console').appendChild(document.createTextNode(message + '\n'));
13
}
14
15
function test(url, expectSuccess)
16
{
17
    log("Testing: " + url + " (sync)");
18
    var req = new XMLHttpRequest();
19
    req.open("GET", url, false);
20
    try {
21
        req.send(null);
22
        log((expectSuccess ? "PASS: " : "FAIL: ") + req.responseText);
23
    } catch (e) {
24
        log((expectSuccess ? "FAIL: " : "PASS: ") + e);
25
    }
26
27
    log("Testing: " + url + " (async)");
28
    req = new XMLHttpRequest();
29
    req.open("GET", url, true);
30
    req.onload = function() {
31
        log((expectSuccess ? "PASS: " : "FAIL: ") + req.responseText);
32
        nextTest();
33
    };
34
    req.onerror = function() {
35
        log((expectSuccess ? "FAIL: " : "PASS: ") + req.status);
36
        nextTest();
37
    };
38
    req.send(null);
39
}
40
41
var tests = [
42
    ["http://localhost:8000/xmlhttprequest/resources/get.txt", true]
43
    // FIXME: Is it possible to setup the following tests?
44
    // ["http://localhost:8001/xmlhttprequest/resources/get.txt", false],
45
    // ["http://foo.localhost:8000/xmlhttprequest/resources/get.txt", false],
46
    // ["https://localhost:8000/xmlhttprequest/resources/get.txt", false]
47
];
48
49
var currentTest = 0;
50
51
function nextTest()
52
{
53
    if (currentTest < tests.length)
54
        test.apply(null, tests[currentTest++]);
55
    else {
56
        layoutTestController.resetOriginAccessWhiteLists();
57
        layoutTestController.notifyDone();
58
    }
59
}
60
61
nextTest();
62
</script>
- a/LayoutTests/http/tests/xmlhttprequest/origin-whitelisting-https-expected.txt +7 lines
Line 0 a/LayoutTests/http/tests/xmlhttprequest/origin-whitelisting-https-expected.txt_sec1
1
Tests that origin whitelisting for https does not match http URLs.
2
3
Testing: http://localhost:8000/xmlhttprequest/resources/get.txt (sync)
4
PASS: Error: NETWORK_ERR: XMLHttpRequest Exception 101
5
Testing: http://localhost:8000/xmlhttprequest/resources/get.txt (async)
6
PASS: 0
7
- a/LayoutTests/http/tests/xmlhttprequest/origin-whitelisting-https.html +60 lines
Line 0 a/LayoutTests/http/tests/xmlhttprequest/origin-whitelisting-https.html_sec1
1
<p>Tests that origin whitelisting for https does not match http URLs.</p>
2
3
<pre id="console"></pre>
4
<script>
5
layoutTestController.dumpAsText();
6
layoutTestController.waitUntilDone();
7
layoutTestController.resetOriginAccessWhiteLists();
8
layoutTestController.whiteListAccessToOrigin("http://127.0.0.1:8000", "localhost", false, true);
9
10
function log(message)
11
{
12
    document.getElementById('console').appendChild(document.createTextNode(message + '\n'));
13
}
14
15
function test(url, expectSuccess)
16
{
17
    log("Testing: " + url + " (sync)");
18
    var req = new XMLHttpRequest();
19
    req.open("GET", url, false);
20
    try {
21
        req.send(null);
22
        log((expectSuccess ? "PASS: " : "FAIL: ") + req.responseText);
23
    } catch (e) {
24
        log((expectSuccess ? "FAIL: " : "PASS: ") + e);
25
    }
26
27
    log("Testing: " + url + " (async)");
28
    req = new XMLHttpRequest();
29
    req.open("GET", url, true);
30
    req.onload = function() {
31
        log((expectSuccess ? "PASS: " : "FAIL: ") + req.responseText);
32
        nextTest();
33
    };
34
    req.onerror = function() {
35
        log((expectSuccess ? "FAIL: " : "PASS: ") + req.status);
36
        nextTest();
37
    };
38
    req.send(null);
39
}
40
41
var tests = [
42
    ["http://localhost:8000/xmlhttprequest/resources/get.txt", false]
43
    // FIXME: Is it possible to setup the following tests?
44
    // ["https://localhost:8000/xmlhttprequest/resources/get.txt", true]
45
];
46
47
var currentTest = 0;
48
49
function nextTest()
50
{
51
    if (currentTest < tests.length)
52
        test.apply(null, tests[currentTest++]);
53
    else {
54
        layoutTestController.resetOriginAccessWhiteLists();
55
        layoutTestController.notifyDone();
56
    }
57
}
58
59
nextTest();
60
</script>
- a/LayoutTests/http/tests/xmlhttprequest/origin-whitelisting-ip-addresses-expected.txt +7 lines
Line 0 a/LayoutTests/http/tests/xmlhttprequest/origin-whitelisting-ip-addresses-expected.txt_sec1
1
Tests origin whitelisting with IP addresses.
2
3
Testing: http://127.0.0.1:8000/xmlhttprequest/resources/get.txt (sync)
4
PASS: PASS
5
Testing: http://127.0.0.1:8000/xmlhttprequest/resources/get.txt (async)
6
PASS: PASS
7
- a/LayoutTests/http/tests/xmlhttprequest/origin-whitelisting-ip-addresses-with-subdomains-expected.txt +7 lines
Line 0 a/LayoutTests/http/tests/xmlhttprequest/origin-whitelisting-ip-addresses-with-subdomains-expected.txt_sec1
1
Specifying that an IP address should match subdomains doesn't make sense. This test verifies that it doesn't do anything.
2
3
Testing: http://127.0.0.1:8000/xmlhttprequest/resources/get.txt (sync)
4
FAIL: Error: NETWORK_ERR: XMLHttpRequest Exception 101
5
Testing: http://127.0.0.1:8000/xmlhttprequest/resources/get.txt (async)
6
FAIL: 0
7
- a/LayoutTests/http/tests/xmlhttprequest/origin-whitelisting-ip-addresses-with-subdomains.html +24 lines
Line 0 a/LayoutTests/http/tests/xmlhttprequest/origin-whitelisting-ip-addresses-with-subdomains.html_sec1
1
<p>Specifying that an IP address should match subdomains doesn't make sense. This test verifies that it doesn't do anything.</p>
2
<pre id="console"></pre>
3
<script>
4
layoutTestController.dumpAsText();
5
layoutTestController.waitUntilDone();
6
layoutTestController.resetOriginAccessWhiteLists();
7
layoutTestController.whiteListAccessToOrigin("http://localhost:8000", "*.0.0.1", true, false);
8
9
function log(message)
10
{
11
    document.getElementById('console').appendChild(document.createTextNode(message + '\n'));
12
}
13
14
var iframe = document.createElement("iframe");
15
document.body.appendChild(iframe);
16
iframe.src = "http://localhost:8000/xmlhttprequest/resources/origin-whitelisting-ip-address-test.html";
17
window.addEventListener("message", function(e) {
18
    if (e.data == "DONE") {
19
        layoutTestController.resetOriginAccessWhiteLists();
20
        layoutTestController.notifyDone();
21
    } else
22
        log(e.data);
23
}, false);
24
</script>
- a/LayoutTests/http/tests/xmlhttprequest/origin-whitelisting-ip-addresses.html +24 lines
Line 0 a/LayoutTests/http/tests/xmlhttprequest/origin-whitelisting-ip-addresses.html_sec1
1
<p>Tests origin whitelisting with IP addresses.</p>
2
<pre id="console"></pre>
3
<script>
4
layoutTestController.dumpAsText();
5
layoutTestController.waitUntilDone();
6
layoutTestController.resetOriginAccessWhiteLists();
7
layoutTestController.whiteListAccessToOrigin("http://localhost:8000", "127.0.0.1", false, false);
8
9
function log(message)
10
{
11
    document.getElementById('console').appendChild(document.createTextNode(message + '\n'));
12
}
13
14
var iframe = document.createElement("iframe");
15
document.body.appendChild(iframe);
16
iframe.src = "http://localhost:8000/xmlhttprequest/resources/origin-whitelisting-ip-address-test.html";
17
window.addEventListener("message", function(e) {
18
    if (e.data == "DONE") {
19
        layoutTestController.resetOriginAccessWhiteLists();
20
        layoutTestController.notifyDone();
21
    } else
22
        log(e.data);
23
}, false);
24
</script>
- a/LayoutTests/http/tests/xmlhttprequest/origin-whitelisting-subdomains-expected.txt +7 lines
Line 0 a/LayoutTests/http/tests/xmlhttprequest/origin-whitelisting-subdomains-expected.txt_sec1
1
Tests origin whitelisting subdomain behavior.
2
3
Testing: http://localhost:8000/xmlhttprequest/resources/get.txt (sync)
4
PASS: PASS
5
Testing: http://localhost:8000/xmlhttprequest/resources/get.txt (async)
6
PASS: PASS
7
- a/LayoutTests/http/tests/xmlhttprequest/origin-whitelisting-subdomains.html +62 lines
Line 0 a/LayoutTests/http/tests/xmlhttprequest/origin-whitelisting-subdomains.html_sec1
1
<p>Tests origin whitelisting subdomain behavior.</p>
2
3
<pre id="console"></pre>
4
<script>
5
layoutTestController.dumpAsText();
6
layoutTestController.waitUntilDone();
7
layoutTestController.resetOriginAccessWhiteLists();
8
layoutTestController.whiteListAccessToOrigin("http://127.0.0.1:8000", "localhost", true, false);
9
10
function log(message)
11
{
12
    document.getElementById('console').appendChild(document.createTextNode(message + '\n'));
13
}
14
15
function test(url, expectSuccess)
16
{
17
    log("Testing: " + url + " (sync)");
18
    var req = new XMLHttpRequest();
19
    req.open("GET", url, false);
20
    try {
21
        req.send(null);
22
        log((expectSuccess ? "PASS: " : "FAIL: ") + req.responseText);
23
    } catch (e) {
24
        log((expectSuccess ? "FAIL: " : "PASS: ") + e);
25
    }
26
27
    log("Testing: " + url + " (async)");
28
    req = new XMLHttpRequest();
29
    req.open("GET", url, true);
30
    req.onload = function() {
31
        log((expectSuccess ? "PASS: " : "FAIL: ") + req.responseText);
32
        nextTest();
33
    };
34
    req.onerror = function() {
35
        log((expectSuccess ? "FAIL: " : "PASS: ") + req.status);
36
        nextTest();
37
    };
38
    req.send(null);
39
}
40
41
var tests = [
42
    ["http://localhost:8000/xmlhttprequest/resources/get.txt", true]
43
    // FIXME: Is it possible to setup the following tests?
44
    // ["http://foo.localhost:8000/xmlhttprequest/resources/get.txt", true]
45
    // ["http://bar.foo.localhost:8000/xmlhttprequest/resources/get.txt", true]
46
    // ["http://foolocalhost:8000/xmlhttprequest/resources/get.txt", false]
47
];
48
49
var currentTest = 0;
50
51
function nextTest()
52
{
53
    if (currentTest < tests.length)
54
        test.apply(null, tests[currentTest++]);
55
    else {
56
        layoutTestController.resetOriginAccessWhiteLists();
57
        layoutTestController.notifyDone();
58
    }
59
}
60
61
nextTest();
62
</script>
- a/WebCore/ChangeLog +25 lines
Lines 1-3 a/WebCore/ChangeLog_sec1
1
2009-08-18  Aaron Boodman  <aa@chromium.org>
2
3
        Reviewed by NOBODY (OOPS!).
4
5
        https://bugs.webkit.org/show_bug.cgi?id=24853: Provide a way for WebKit clients to
6
        specify a more granular policy for cross-origin XHR access.
7
8
        Tests: http/tests/xmlhttprequest/origin-whitelisting-all.html
9
               http/tests/xmlhttprequest/origin-whitelisting-exact-match.html
10
               http/tests/xmlhttprequest/origin-whitelisting-https.html
11
               http/tests/xmlhttprequest/origin-whitelisting-ip-addresses-with-subdomains.html
12
               http/tests/xmlhttprequest/origin-whitelisting-ip-addresses.html
13
               http/tests/xmlhttprequest/origin-whitelisting-subdomains.html
14
15
        * WebCore.base.exp: Export methods to manipulate origin access whitelists to enable
16
        testing via layout tests.
17
        * page/SecurityOrigin.cpp: Implement origin acces whitelists.
18
        (WebCore::OriginAccessWhiteListEntry::OriginAccessWhiteListEntry): Ditto.
19
        (WebCore::OriginAccessWhiteListEntry::matchesOrigin): Ditto.
20
        (WebCore::originAccessMap): Ditto.
21
        (WebCore::SecurityOrigin::canRequest): Ditto.
22
        (WebCore::SecurityOrigin::whiteListAccessToOrigin): Ditto.
23
        (WebCore::SecurityOrigin::resetOriginAccessWhiteLists): Ditto.
24
        * page/SecurityOrigin.h: Ditto.
25
1
2009-08-18  Kent Tamura  <tkent@chromium.org>
26
2009-08-18  Kent Tamura  <tkent@chromium.org>
2
27
3
        Reviewed by Eric Seidel.
28
        Reviewed by Eric Seidel.
- a/WebCore/WebCore.base.exp +3 lines
Lines 313-318 __ZN7WebCore14ResourceLoader14cancelledErrorEv a/WebCore/WebCore.base.exp_sec1
313
__ZN7WebCore14ResourceLoader19setShouldBufferDataEb
313
__ZN7WebCore14ResourceLoader19setShouldBufferDataEb
314
__ZN7WebCore14SecurityOrigin24registerURLSchemeAsLocalERKNS_6StringE
314
__ZN7WebCore14SecurityOrigin24registerURLSchemeAsLocalERKNS_6StringE
315
__ZN7WebCore14SecurityOrigin6createERKNS_4KURLE
315
__ZN7WebCore14SecurityOrigin6createERKNS_4KURLE
316
__ZN7WebCore14SecurityOrigin16createFromStringERKNS_6StringE
317
__ZN7WebCore14SecurityOrigin23whiteListAccessToOriginERKS0_RKNS_6StringEbb
318
__ZN7WebCore14SecurityOrigin27resetOriginAccessWhiteListsEv
316
__ZN7WebCore15ArchiveResource6createEN3WTF10PassRefPtrINS_12SharedBufferEEERKNS_4KURLERKNS_6StringESA_SA_RKNS_16ResourceResponseE
319
__ZN7WebCore15ArchiveResource6createEN3WTF10PassRefPtrINS_12SharedBufferEEERKNS_4KURLERKNS_6StringESA_SA_RKNS_16ResourceResponseE
317
__ZN7WebCore15BackForwardList10removeItemEPNS_11HistoryItemE
320
__ZN7WebCore15BackForwardList10removeItemEPNS_11HistoryItemE
318
__ZN7WebCore15BackForwardList10setEnabledEb
321
__ZN7WebCore15BackForwardList10setEnabledEb
- a/WebCore/page/SecurityOrigin.cpp -1 / +91 lines
Lines 36-41 a/WebCore/page/SecurityOrigin.cpp_sec1
36
36
37
namespace WebCore {
37
namespace WebCore {
38
38
39
class OriginAccessWhiteListEntry {
40
public:
41
    OriginAccessWhiteListEntry(const String& host, bool includeSubdomains, bool secure) : m_host(host), m_includeSubdomains(includeSubdomains), m_secure(secure) { }
42
43
    bool matchesOrigin(const SecurityOrigin& origin)
44
    {
45
        if (m_secure && origin.protocol() != "https")
46
            return false;
47
48
        if (!m_secure && origin.protocol() != "http")
49
            return false;
50
51
        // Special case: Include subdomains and empty host means "all hosts, including ip addresses".
52
        if (m_includeSubdomains && m_host.isEmpty())
53
            return true;
54
55
        // Exact match.
56
        if (m_host == origin.host())
57
            return true;
58
59
        // Otherwise we can only match if we're matching subdomains.
60
        if (!m_includeSubdomains)
61
            return false;
62
63
        // Don't try to do subdomain matching on IP addresses. Assume that any host that ends with a digit is trying to be an IP address.
64
        UChar last = m_host[m_host.length() - 1];
65
        if (last >= '0' && last <= '9')
66
            return false;
67
68
        // Match subdomains.
69
        // FIXME: This hasn't actually been tested as I can't figure out a way to test it with the layout test system.
70
        if (origin.host().length() > m_host.length() && origin.host()[origin.host().length() - m_host.length() - 1] == '.' && origin.host().endsWith(m_host, true))
71
            return true;
72
73
        return false;
74
    }
75
76
private:
77
    String m_host;
78
    bool m_includeSubdomains;
79
    bool m_secure;
80
};
81
82
typedef Vector<OriginAccessWhiteListEntry*> OriginAccessWhiteList;
83
typedef HashMap<String, OriginAccessWhiteList*> OriginAccessMap;
84
85
static OriginAccessMap& originAccessMap()
86
{
87
    DEFINE_STATIC_LOCAL(OriginAccessMap, originAccessMap, ());
88
    return originAccessMap;
89
}
90
39
static URLSchemesMap& localSchemes()
91
static URLSchemesMap& localSchemes()
40
{
92
{
41
    DEFINE_STATIC_LOCAL(URLSchemesMap, localSchemes, ());
93
    DEFINE_STATIC_LOCAL(URLSchemesMap, localSchemes, ());
Lines 198-204 bool SecurityOrigin::canRequest(const KURL& url) const a/WebCore/page/SecurityOrigin.cpp_sec2
198
250
199
    // We call isSameSchemeHostPort here instead of canAccess because we want
251
    // We call isSameSchemeHostPort here instead of canAccess because we want
200
    // to ignore document.domain effects.
252
    // to ignore document.domain effects.
201
    return isSameSchemeHostPort(targetOrigin.get());
253
    if (isSameSchemeHostPort(targetOrigin.get()))
254
        return true;
255
256
    OriginAccessWhiteList* list = originAccessMap().get(toString());
257
    if (list)
258
        for (size_t i = 0; i < list->size(); ++i)
259
            if (list->at(i)->matchesOrigin(*targetOrigin))
260
                return true;
261
262
    return false;
202
}
263
}
203
264
204
void SecurityOrigin::grantLoadLocalResources()
265
void SecurityOrigin::grantLoadLocalResources()
Lines 414-417 bool SecurityOrigin::shouldTreatURLSchemeAsNoAccess(const String& scheme) a/WebCore/page/SecurityOrigin.cpp_sec3
414
    return noAccessSchemes().contains(scheme);
475
    return noAccessSchemes().contains(scheme);
415
}
476
}
416
477
478
// static
479
void SecurityOrigin::whiteListAccessToOrigin(const SecurityOrigin& source, const String& domain, bool includeSubdomains, bool secure)
480
{
481
    // FIXME: We leak these objects at process shutdown. Is that OK?
482
    OriginAccessWhiteList* list = originAccessMap().get(source.toString());
483
    if (!list)
484
    {
485
        list = new OriginAccessWhiteList();
486
        originAccessMap().set(source.toString(), list);
487
    }
488
    list->append(new OriginAccessWhiteListEntry(domain, includeSubdomains, secure));
489
}
490
491
// static
492
void SecurityOrigin::resetOriginAccessWhiteLists()
493
{
494
    OriginAccessMap& map = originAccessMap();
495
    for (OriginAccessMap::iterator iter = map.begin(); iter != map.end(); ++iter)
496
    {
497
        OriginAccessWhiteList* list = iter->second;
498
        for (size_t i = 0; i < list->size(); ++i)
499
            delete list->at(i);
500
501
        delete list;
502
    }
503
504
    map.clear();
505
}
506
417
} // namespace WebCore
507
} // namespace WebCore
- a/WebCore/page/SecurityOrigin.h +3 lines
Lines 141-146 namespace WebCore { a/WebCore/page/SecurityOrigin.h_sec1
141
        static void registerURLSchemeAsNoAccess(const String&);
141
        static void registerURLSchemeAsNoAccess(const String&);
142
        static bool shouldTreatURLSchemeAsNoAccess(const String&);
142
        static bool shouldTreatURLSchemeAsNoAccess(const String&);
143
143
144
        static void whiteListAccessToOrigin(const SecurityOrigin& source, const String& domain, bool includeSubdomains, bool secure);
145
        static void resetOriginAccessWhiteLists();
146
144
    private:
147
    private:
145
        explicit SecurityOrigin(const KURL&);
148
        explicit SecurityOrigin(const KURL&);
146
        explicit SecurityOrigin(const SecurityOrigin*);
149
        explicit SecurityOrigin(const SecurityOrigin*);
- a/WebKit/mac/ChangeLog +13 lines
Lines 1-3 a/WebKit/mac/ChangeLog_sec1
1
2009-08-18  Aaron Boodman  <aa@chromium.org>
2
3
        Reviewed by NOBODY (OOPS!).
4
5
        https://bugs.webkit.org/show_bug.cgi?id=24853: Provide a way for WebKit clients to
6
        specify a more granular policy for cross-origin XHR access.
7
8
        * WebView/WebView.mm:
9
        (+[WebView _whiteListAccessToOrigin:host:includeSubdomains:secure:]): SPI to allow
10
        testing origin access whitelists via layout tests.
11
        (+[WebView _resetOriginAccessWhiteLists]): Ditto.
12
        * WebView/WebViewPrivate.h: Ditto.
13
1
2009-08-17  Darin Adler  <darin@apple.com>
14
2009-08-17  Darin Adler  <darin@apple.com>
2
15
3
        Reviewed by Sam Weinig.
16
        Reviewed by Sam Weinig.
- a/WebKit/mac/WebView/WebView.mm +9 lines
Lines 2092-2097 static inline IMP getMethod(id o, SEL s) a/WebKit/mac/WebView/WebView.mm_sec1
2092
    return _private ? _private->insertionPasteboard : nil;
2092
    return _private ? _private->insertionPasteboard : nil;
2093
}
2093
}
2094
2094
2095
+ (void)_whiteListAccessToOrigin:(NSString*)sourceOrigin host:(NSString*)host includeSubdomains:(BOOL)includeSubdomains secure:(BOOL)secure
2096
{
2097
    SecurityOrigin::whiteListAccessToOrigin(*SecurityOrigin::createFromString(sourceOrigin), host, includeSubdomains, secure);
2098
}
2099
2100
+ (void)_resetOriginAccessWhiteLists
2101
{
2102
    SecurityOrigin::resetOriginAccessWhiteLists();
2103
}
2095
2104
2096
- (void)_updateActiveState
2105
- (void)_updateActiveState
2097
{
2106
{
- a/WebKit/mac/WebView/WebViewPrivate.h +9 lines
Lines 443-448 Could be worth adding to the API. a/WebKit/mac/WebView/WebViewPrivate.h_sec1
443
// Which pasteboard text is coming from in editing delegate methods such as shouldInsertNode.
443
// Which pasteboard text is coming from in editing delegate methods such as shouldInsertNode.
444
- (NSPasteboard *)_insertionPasteboard;
444
- (NSPasteboard *)_insertionPasteboard;
445
445
446
// Whitelists access from an origin (sourceOrigin) to a set of one or more origins described by the parameters:
447
// - host: The host to grant access to.
448
// - includeSubdomains: If host is a domain, setting this to YES will whitelist host and all its subdomains, recursively.
449
// - secure: Whether to grant access to https or http origins. If yes, only https origins will be whitelisted. If no, only http origins will be.
450
+ (void)_whiteListAccessToOrigin:(NSString*)sourceOrigin host:(NSString*)host includeSubdomains:(BOOL)includeSubdomains secure:(BOOL)secure;
451
452
// Clears all whitelists created by _whiteListAccessToOrigin.
453
+ (void)_resetOriginAccessWhiteLists;
454
446
@end
455
@end
447
456
448
@interface WebView (WebViewPrintingPrivate)
457
@interface WebView (WebViewPrintingPrivate)
- a/WebKitTools/ChangeLog +17 lines
Lines 1-3 a/WebKitTools/ChangeLog_sec1
1
2009-08-18  Aaron Boodman  <aa@chromium.org>
2
3
        Reviewed by NOBODY (OOPS!).
4
5
        https://bugs.webkit.org/show_bug.cgi?id=24853: Provide a way for WebKit clients to
6
        specify a more granular policy for cross-origin XHR access.
7
8
        * DumpRenderTree/LayoutTestController.cpp: Add plumbing to be able to manipulate
9
        origin access whitelists from layout tests.
10
        (whiteListAccessToOriginCallback): Ditto.
11
        (resetOriginAccessWhiteListsCallback): Ditto.
12
        (LayoutTestController::staticFunctions): Ditto.
13
        * DumpRenderTree/LayoutTestController.h: Ditto.
14
        * DumpRenderTree/mac/LayoutTestControllerMac.mm: Ditto.
15
        (LayoutTestController::whiteListAccessToOrigin): Ditto.
16
        (LayoutTestController::resetOriginAccessWhiteLists): Ditto.
17
1
2009-08-17  Shinichiro Hamaji  <hamaji@chromium.org>
18
2009-08-17  Shinichiro Hamaji  <hamaji@chromium.org>
2
19
3
        Reviewed by Darin Adler.
20
        Reviewed by Darin Adler.
- a/WebKitTools/DumpRenderTree/LayoutTestController.cpp +26 lines
Lines 874-879 static JSValueRef waitForPolicyDelegateCallback(JSContextRef context, JSObjectRe a/WebKitTools/DumpRenderTree/LayoutTestController.cpp_sec1
874
    return JSValueMakeUndefined(context);
874
    return JSValueMakeUndefined(context);
875
}
875
}
876
876
877
static JSValueRef whiteListAccessToOriginCallback(JSContextRef context, JSObjectRef, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef* exception)
878
{
879
    if (argumentCount != 4)
880
        return JSValueMakeUndefined(context);
881
882
    JSRetainPtr<JSStringRef> sourceOrigin(Adopt, JSValueToStringCopy(context, arguments[0], exception));
883
    ASSERT(!*exception);
884
    JSRetainPtr<JSStringRef> host(Adopt, JSValueToStringCopy(context, arguments[1], exception));
885
    ASSERT(!*exception);
886
    bool includeSubdomains = JSValueToBoolean(context, arguments[2]);
887
    bool secure = JSValueToBoolean(context, arguments[3]);
888
889
    LayoutTestController* controller = static_cast<LayoutTestController*>(JSObjectGetPrivate(thisObject));
890
    controller->whiteListAccessToOrigin(sourceOrigin.get(), host.get(), includeSubdomains, secure);
891
    return JSValueMakeUndefined(context);
892
}
893
894
static JSValueRef resetOriginAccessWhiteListsCallback(JSContextRef context, JSObjectRef, JSObjectRef thisObject, size_t, const JSValueRef[], JSValueRef*)
895
{
896
    LayoutTestController* controller = static_cast<LayoutTestController*>(JSObjectGetPrivate(thisObject));
897
    controller->resetOriginAccessWhiteLists();
898
    return JSValueMakeUndefined(context);
899
}
900
877
// Static Values
901
// Static Values
878
902
879
static JSValueRef getGlobalFlagCallback(JSContextRef context, JSObjectRef thisObject, JSStringRef propertyName, JSValueRef* exception)
903
static JSValueRef getGlobalFlagCallback(JSContextRef context, JSObjectRef thisObject, JSStringRef propertyName, JSValueRef* exception)
Lines 984-989 JSStaticFunction* LayoutTestController::staticFunctions() a/WebKitTools/DumpRenderTree/LayoutTestController.cpp_sec2
984
        { "queueNonLoadingScript", queueNonLoadingScriptCallback, kJSPropertyAttributeReadOnly | kJSPropertyAttributeDontDelete },
1008
        { "queueNonLoadingScript", queueNonLoadingScriptCallback, kJSPropertyAttributeReadOnly | kJSPropertyAttributeDontDelete },
985
        { "queueReload", queueReloadCallback, kJSPropertyAttributeReadOnly | kJSPropertyAttributeDontDelete },
1009
        { "queueReload", queueReloadCallback, kJSPropertyAttributeReadOnly | kJSPropertyAttributeDontDelete },
986
        { "repaintSweepHorizontally", repaintSweepHorizontallyCallback, kJSPropertyAttributeReadOnly | kJSPropertyAttributeDontDelete },
1010
        { "repaintSweepHorizontally", repaintSweepHorizontallyCallback, kJSPropertyAttributeReadOnly | kJSPropertyAttributeDontDelete },
1011
        { "resetOriginAccessWhiteLists", resetOriginAccessWhiteListsCallback, kJSPropertyAttributeReadOnly | kJSPropertyAttributeDontDelete },
987
        { "setAcceptsEditing", setAcceptsEditingCallback, kJSPropertyAttributeReadOnly | kJSPropertyAttributeDontDelete },
1012
        { "setAcceptsEditing", setAcceptsEditingCallback, kJSPropertyAttributeReadOnly | kJSPropertyAttributeDontDelete },
988
        { "setAuthorAndUserStylesEnabled", setAuthorAndUserStylesEnabledCallback, kJSPropertyAttributeReadOnly | kJSPropertyAttributeDontDelete },
1013
        { "setAuthorAndUserStylesEnabled", setAuthorAndUserStylesEnabledCallback, kJSPropertyAttributeReadOnly | kJSPropertyAttributeDontDelete },
989
        { "setAppCacheMaximumSize", setAppCacheMaximumSizeCallback, kJSPropertyAttributeReadOnly | kJSPropertyAttributeDontDelete }, 
1014
        { "setAppCacheMaximumSize", setAppCacheMaximumSizeCallback, kJSPropertyAttributeReadOnly | kJSPropertyAttributeDontDelete }, 
Lines 1014-1019 JSStaticFunction* LayoutTestController::staticFunctions() a/WebKitTools/DumpRenderTree/LayoutTestController.cpp_sec3
1014
        { "waitForPolicyDelegate", waitForPolicyDelegateCallback, kJSPropertyAttributeReadOnly | kJSPropertyAttributeDontDelete },
1039
        { "waitForPolicyDelegate", waitForPolicyDelegateCallback, kJSPropertyAttributeReadOnly | kJSPropertyAttributeDontDelete },
1015
        { "waitUntilDone", waitUntilDoneCallback, kJSPropertyAttributeReadOnly | kJSPropertyAttributeDontDelete },
1040
        { "waitUntilDone", waitUntilDoneCallback, kJSPropertyAttributeReadOnly | kJSPropertyAttributeDontDelete },
1016
        { "windowCount", windowCountCallback, kJSPropertyAttributeReadOnly | kJSPropertyAttributeDontDelete },
1041
        { "windowCount", windowCountCallback, kJSPropertyAttributeReadOnly | kJSPropertyAttributeDontDelete },
1042
        { "whiteListAccessToOrigin", whiteListAccessToOriginCallback, kJSPropertyAttributeReadOnly | kJSPropertyAttributeDontDelete },
1017
        { 0, 0, 0 }
1043
        { 0, 0, 0 }
1018
    };
1044
    };
1019
1045
- a/WebKitTools/DumpRenderTree/LayoutTestController.h -1 / +4 lines
Lines 178-184 public: a/WebKitTools/DumpRenderTree/LayoutTestController.h_sec1
178
    bool pauseAnimationAtTimeOnElementWithId(JSStringRef animationName, double time, JSStringRef elementId);
178
    bool pauseAnimationAtTimeOnElementWithId(JSStringRef animationName, double time, JSStringRef elementId);
179
    bool pauseTransitionAtTimeOnElementWithId(JSStringRef propertyName, double time, JSStringRef elementId);
179
    bool pauseTransitionAtTimeOnElementWithId(JSStringRef propertyName, double time, JSStringRef elementId);
180
    unsigned numberOfActiveAnimations() const;
180
    unsigned numberOfActiveAnimations() const;
181
    
181
182
    void whiteListAccessToOrigin(JSStringRef sourceOrigin, JSStringRef host, bool includeSubdomains, bool secure);
183
    void resetOriginAccessWhiteLists();
184
182
private:
185
private:
183
    bool m_dumpAsText;
186
    bool m_dumpAsText;
184
    bool m_dumpAsPDF;
187
    bool m_dumpAsPDF;
- a/WebKitTools/DumpRenderTree/mac/LayoutTestControllerMac.mm +14 lines
Lines 437-439 void LayoutTestController::waitForPolicyDelegate() a/WebKitTools/DumpRenderTree/mac/LayoutTestControllerMac.mm_sec1
437
    [policyDelegate setControllerToNotifyDone:this];
437
    [policyDelegate setControllerToNotifyDone:this];
438
    [[mainFrame webView] setPolicyDelegate:policyDelegate];
438
    [[mainFrame webView] setPolicyDelegate:policyDelegate];
439
}
439
}
440
441
void LayoutTestController::whiteListAccessToOrigin(JSStringRef sourceOrigin, JSStringRef host, bool includeSubdomains, bool secure)
442
{
443
    RetainPtr<CFStringRef> sourceOriginCF(AdoptCF, JSStringCopyCFString(kCFAllocatorDefault, sourceOrigin));
444
    NSString *sourceOriginNS = (NSString *)sourceOriginCF.get();
445
    RetainPtr<CFStringRef> hostCF(AdoptCF, JSStringCopyCFString(kCFAllocatorDefault, host));
446
    NSString *hostNS = (NSString *)hostCF.get();
447
    [WebView _whiteListAccessToOrigin:sourceOriginNS host:hostNS includeSubdomains:includeSubdomains secure:secure];
448
}
449
450
void LayoutTestController::resetOriginAccessWhiteLists()
451
{
452
    [WebView _resetOriginAccessWhiteLists];
453
}

Return to Bug 24853