Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Replace TAOResponse.py with CustomCorsResponse.py #40933

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion common/CustomCorsResponse.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,16 @@ def query_parameter_or_default(param, default):
for k, v in headers.items():
response.headers.set(k, v)

img = request.GET.first(b'img') if b'img' in request.GET else None
if img:
response.headers.set(b"Content-Type", b"image/png")
with open(request.doc_root + "/resource-timing/resources/blue.png", "rb") as f:
response.content = f.read()
# Note that, in order to have out-of-the-box support for tests that don't call
# setup({'allow_uncaught_exception': true})
# we return a no-op JS payload. This approach will avoid syntax errors in
# script resources that would otherwise cause the test harness to fail.
response.content = json.loads(query_parameter_or_default(b'content',
b'"/* CustomCorsResponse.py content */"'))
response.status_code = json.loads(query_parameter_or_default(b'status',
b'200'))
b'200'))
8 changes: 4 additions & 4 deletions resource-timing/TAO-port-mismatch-means-crossorigin.html
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@
// have a Timing-Allow-Origin header value with the second port so this page's
// origin should not be a match.
const port_mismatch_url = `${location.protocol}//${ORIGINAL_HOST}:${PORT2}` +
`/resource-timing/resources/TAOResponse.py?` +
`tao=origin_port_${PORT2}`;
`/common/CustomCorsResponse.py?` +
`headers=${encodeURIComponent('{"Access-Control-Allow-Origin":"*","Timing-Allow-Origin":"${PORT2}"}')}`;
attribute_test(
fetch, port_mismatch_url, invariants.assert_tao_failure_resource,
"A port mismatch must fail the TAO check");
Expand All @@ -29,8 +29,8 @@
// the Timing-Allow-Origin header's value. Therefore, the subresource's timings
// must be exposed.
const port_match_url = `${location.protocol}//${ORIGINAL_HOST}:${PORT2}` +
`/resource-timing/resources/TAOResponse.py?` +
`tao=origin_port_${PORT}`;
`/common/CustomCorsResponse.py?` +
`headers=${encodeURIComponent('{"Access-Control-Allow-Origin":"*","Timing-Allow-Origin":"*"}')}`;
attribute_test(
fetch, port_match_url, invariants.assert_tao_pass_no_redirect_http,
"An identical port must pass the TAO check");
Expand Down
2 changes: 1 addition & 1 deletion resource-timing/cross-origin-iframe.html
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
promise_test(async t => {
const iframe = document.createElement('iframe');
t.add_cleanup(() => iframe.remove());
iframe.src = `${REMOTE_ORIGIN}/resource-timing/resources/TAOResponse.py?tao=wildcard`;
iframe.src = `${REMOTE_ORIGIN}/common/CustomCorsResponse.py?headers=${encodeURIComponent('{"Timing-Allow-Origin": "*"}')}`;
document.body.appendChild(iframe);
const entry = await observe_entry(iframe.src);
invariants.assert_tao_pass_no_redirect_http(entry);
Expand Down
20 changes: 10 additions & 10 deletions resource-timing/opaque-origin.html
Original file line number Diff line number Diff line change
Expand Up @@ -20,21 +20,21 @@ <h1>Description</h1>
<iframe id="frameContext"></iframe>
<script>
const {ORIGIN} = get_host_info();
const url = `${ORIGIN}/resource-timing/resources/TAOResponse.py`;
const url = `${ORIGIN}/common/CustomCorsResponse.py`;
const frame_content = `data:text/html;utf8,<body>
<script src="${ORIGIN}/resources/testharness.js"></` + `script>
<script src="${ORIGIN}/resource-timing/resources/entry-invariants.js">
</` + `script>
<script>
attribute_test(fetch, "${url}?tao=null",
invariants.assert_tao_pass_no_redirect_http,
"An opaque origin should be authorized to see resource timings when the" +
"TAO header is the string 'null'");
attribute_test(fetch, "${url}?tao=Null",
invariants.assert_tao_failure_resource,
"An opaque origin must not be authorized to see resource timings when " +
"the TAO header is the string 'Null'. (The check for 'null' must be " +
"case-sensitive)");
attribute_test(fetch, "${url}?headers=${encodeURIComponent('{%22Access-Control-Allow-Origin%22:%22null%22,%22Timing-Allow-Origin%22:%22null%22}')}",
invariants.assert_tao_pass_no_redirect_http,
"An opaque origin should be authorized to see resource timings when the" +
"TAO header is the string 'null'");
attribute_test(fetch, "${url}?headers=${encodeURIComponent('{%22Access-Control-Allow-Origin%22:%22null%22,%22Timing-Allow-Origin%22:%22Null%22}')}",
invariants.assert_tao_failure_resource,
"An opaque origin must not be authorized to see resource timings when " +
"the TAO header is the string 'Null'. (The check for 'null' must be " +
"case-sensitive)");
</` + `script>
</body>`;

Expand Down
64 changes: 0 additions & 64 deletions resource-timing/resources/TAOResponse.py

This file was deleted.

40 changes: 21 additions & 19 deletions resource-timing/resources/iframe-TAO-crossorigin-port.sub.html
Original file line number Diff line number Diff line change
@@ -1,31 +1,33 @@
<!DOCTYPE html>
<html>
<body>
<script>
const url = '{{location[scheme]}}://{{host}}:{{ports[http][1]}}/resource-timing/resources/TAOResponse.py?tao=origin_port_{{ports[http][1]}}';
const observe = (list, observer) => {
<body>
<script>
var origin = window.location.origin;
const url =
"{{location[scheme]}}://{{host}}:{{ports[http][1]}}/common/CustomCorsResponse.py?headers="+encodeURIComponent('{"Timing-Allow-Origin": "' + origin + '"}') ;
const observe = (list, observer) => {
const entry = list.getEntries()[0];
const sum = entry.redirectStart +
entry.redirectEnd +
entry.domainLookupStart +
entry.domainLookupEnd +
entry.connectStart +
entry.connectEnd +
entry.secureConnectionStart +
entry.requestStart +
entry.responseStart +
entry.transferSize +
entry.encodedBodySize +
entry.decodedBodySize;
entry.redirectEnd +
entry.domainLookupStart +
entry.domainLookupEnd +
entry.connectStart +
entry.connectEnd +
entry.secureConnectionStart +
entry.requestStart +
entry.responseStart +
entry.transferSize +
entry.encodedBodySize +
entry.decodedBodySize;

const result = sum == 0 ? 'PASS' : 'FAIL';
window.top.postMessage(result, '*');
}
let observer = new PerformanceObserver(observe);
observer.observe({ entryTypes: ["resource"] });
let observer = new PerformanceObserver(observe);
observer.observe({ entryTypes: ["resource"] });
fetch(url).then(r => r.text());
</script>
</body>
</script>
</body>
</html>


3 changes: 2 additions & 1 deletion resource-timing/resources/iframe_TAO_match_origin.html
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@
var dirName = dirname(location.href);
var client = new XMLHttpRequest,
// create a cross-origin request
url = dirName.replace('://', '://www.') + 'TAOResponse.py?tao=match_origin';
var origin = window.location.origin;
url = dirName.replace('://', '://www.') + `/common/CustomCorsResponse.py?headers=${encodeURIComponent('{"Timing-Allow-Origin": "' + origin + '"}')}`;
client.open("GET", url, false);
client.send(null);
}
Expand Down
4 changes: 2 additions & 2 deletions resource-timing/sizes-redirect-img.html
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@
// don't, so this test covers extra code paths beyond those covered by
// resource-timing-sizes-redirect.html.

const baseUrl = new URL('/resource-timing/resources/TAOResponse.py?tao=wildcard&img=true', location.href).href;
const baseUrl = new URL(`/common/CustomCorsResponse.py?img=true&headers=${encodeURIComponent('{"Timing-Allow-Origin":"*","Access-Control-Allow-Origin":"*"}')}`, location.href).href;

const expectedSize = 1010;
const expectedSize = 35;

const hostInfo = get_host_info();

Expand Down
36 changes: 21 additions & 15 deletions resource-timing/sizes-redirect.any.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,13 @@
// META: script=/resource-timing/resources/sizes-helper.js

const baseUrl =
new URL('/resource-timing/resources/TAOResponse.py?tao=wildcard', location.href).href;
const expectedSize = 4;
new URL(
`/common/CustomCorsResponse.py?headers=${
encodeURIComponent(
'{"Timing-Allow-Origin":"*","Access-Control-Allow-Origin":"*"}')}`,
location.href)
.href;
const expectedSize = 35;

const hostInfo = get_host_info();
performance.clearResourceTimings();
Expand All @@ -18,20 +23,21 @@ const accumulateEntry = () => {
});
};

const checkResourceSizes = () => {
const entries = performance.getEntriesByType('resource');
for (let entry of entries) {
checkSizeFields(entry, expectedSize, expectedSize + headerSize);
}
}
const checkResourceSizes =
() => {
const entries = performance.getEntriesByType('resource');
for (let entry of entries) {
checkSizeFields(entry, expectedSize, expectedSize + headerSize);
}
}

const redirectUrl = (redirectSourceOrigin, allowOrigin, targetUrl) => {
return redirectSourceOrigin +
'/resource-timing/resources/redirect-cors.py?allow_origin=' +
encodeURIComponent(allowOrigin) +
'&timing_allow_origin=*' +
'&location=' + encodeURIComponent(targetUrl);
}
const redirectUrl =
(redirectSourceOrigin, allowOrigin, targetUrl) => {
return redirectSourceOrigin +
'/resource-timing/resources/redirect-cors.py?allow_origin=*' +
'&timing_allow_origin=*' +
'&location=' + encodeURIComponent(targetUrl);
}

promise_test(() => {
// Use a different URL every time so that the cache behaviour does not
Expand Down