2023-12-12 13:09:57 +09:00
|
|
|
export const TYPES = ['cookie', 'font', 'css', 'image', 'media', 'script', 'xhr', 'frame', 'other'];
|
|
|
|
export const TYPE_MAP = {
|
2023-04-29 21:50:32 +09:00
|
|
|
'stylesheet': 'css',
|
|
|
|
'font': 'font',
|
|
|
|
'image': 'image',
|
|
|
|
'imageset': 'image',
|
|
|
|
'media': 'media',
|
|
|
|
'script': 'script',
|
|
|
|
'beacon': 'xhr',
|
|
|
|
'xmlhttprequest': 'xhr',
|
|
|
|
'websocket': 'xhr',
|
|
|
|
'sub_frame': 'frame',
|
|
|
|
};
|
|
|
|
|
2023-12-12 13:09:57 +09:00
|
|
|
export var shouldAllow = function(rules, context, hostname, type) {
|
2023-04-29 21:50:32 +09:00
|
|
|
var hostnames = ['*', hostname];
|
|
|
|
var parts = hostname.split('.');
|
|
|
|
while (parts.length > 2) {
|
|
|
|
parts.shift();
|
|
|
|
hostnames.push(parts.join('.'));
|
|
|
|
}
|
|
|
|
if (context !== '*' && hostnames.some(h => h === context)) {
|
|
|
|
hostnames.push('first-party');
|
|
|
|
}
|
|
|
|
|
|
|
|
return [context, '*'].some(c => {
|
|
|
|
return rules[c] && hostnames.some(h => {
|
|
|
|
return rules[c][h] && [type, '*'].some(t => {
|
|
|
|
return !!rules[c][h][t];
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
};
|