Commit 3e224d9c authored by gorhill's avatar gorhill

#924: proof of concept of what uBO *could* do

parent 5cac23df
......@@ -1978,9 +1978,13 @@ var httpObserver = {
}
// 'Content-Security-Policy' MUST come last in the array. Need to
// revised this eventually.
// revise this eventually.
var responseHeaders = [];
var value = this.getResponseHeader(channel, 'Content-Security-Policy');
var value = this.getResponseHeader(channel, 'Content-Type');
if ( value !== undefined ) {
responseHeaders.push({ name: 'Content-Type', value: value });
}
value = this.getResponseHeader(channel, 'Content-Security-Policy');
if ( value !== undefined ) {
responseHeaders.push({ name: 'Content-Security-Policy', value: value });
}
......
......@@ -340,6 +340,70 @@ var onHeadersReceived = function(details) {
if ( requestType === 'sub_frame' ) {
return onFrameHeadersReceived(details);
}
// https://github.com/gorhill/uBlock/issues/924
// Evaluate resources requested through non-javascript request type, but
// returned as javascript.
if ( requestType === 'script' ) {
return;
}
var i = headerIndexFromName('content-type', details.responseHeaders);
if ( i === -1 ) {
return;
}
// https://github.com/gorhill/uBlock/issues/924
// If we reach this point, this means a javascript resource was returned
// in response for a non-explicit javascript request.
var value = details.responseHeaders[i].value;
if ( value.indexOf('/javascript') === -1 ) {
return;
}
console.log('"%s" requested, "javascript" returned: %s', requestType, details.url);
var µb = µBlock;
µb.tabContextManager.push(tabId, details.url);
// Lookup the page store associated with this tab id.
var pageStore = µb.pageStoreFromTabId(tabId);
if ( !pageStore ) {
pageStore = µb.bindTabToPageStats(tabId, 'beforeRequest');
}
// I can't think of how pageStore could be null at this point.
var context = pageStore.createContextFromFrameId(details.parentFrameId);
context.requestURL = details.url;
context.requestHostname = details.hostname;
context.requestType = 'script';
var result = pageStore.filterRequestNoCache(context);
pageStore.logRequest(context, result);
if ( µb.logger.isEnabled() ) {
µb.logger.writeOne(
tabId,
'net',
result,
'script',
details.url,
context.rootHostname,
context.pageHostname
);
}
if ( µb.isAllowResult(result) ) {
return;
}
µb.updateBadgeAsync(tabId);
return { 'cancel': true };
};
/******************************************************************************/
......@@ -355,7 +419,7 @@ var onRootFrameHeadersReceived = function(details) {
if ( !pageStore ) {
pageStore = µb.bindTabToPageStats(tabId, 'beforeRequest');
}
// I can't think of how pageStore could be null at this point.
// pageStore will never be null at this point.
var context = pageStore.createContextFromPage();
context.requestURL = details.url;
......@@ -554,7 +618,8 @@ vAPI.net.onHeadersReceived = {
],
types: [
"main_frame",
"sub_frame"
"sub_frame",
"xmlhttprequest"
],
extra: [ 'blocking', 'responseHeaders' ],
callback: onHeadersReceived
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment