From aeaf8059f9a14419031b258bb9592f394e43b4c6 Mon Sep 17 00:00:00 2001 From: fanboynz Date: Fri, 28 Jul 2023 13:05:01 +0200 Subject: [PATCH] Remove set-cookie specific filters --- filter_lists/regional.json | 6 -- resources/brave-set-cookie-reload.js | 79 --------------------- resources/brave-set-cookie.js | 62 ---------------- resources/brave-set-local-storage-item.js | 63 ---------------- resources/brave-set-session-storage-item.js | 63 ---------------- 5 files changed, 273 deletions(-) delete mode 100644 resources/brave-set-cookie-reload.js delete mode 100644 resources/brave-set-cookie.js delete mode 100644 resources/brave-set-local-storage-item.js delete mode 100644 resources/brave-set-session-storage-item.js diff --git a/filter_lists/regional.json b/filter_lists/regional.json index 24c41308..f796cc30 100644 --- a/filter_lists/regional.json +++ b/filter_lists/regional.json @@ -16,12 +16,6 @@ "title": "EasyList-Cookie", "format": "Standard", "support_url": "https://forums.lanik.us/" - }, - { - "url": "https://raw.githubusercontent.com/brave/adblock-lists/master/brave-lists/brave-cookie-specific.txt", - "title": "Brave additions to EasyList-Cookie", - "format": "Standard", - "support_url": "https://github.com/brave/adblock-lists" } ] }, diff --git a/resources/brave-set-cookie-reload.js b/resources/brave-set-cookie-reload.js deleted file mode 100644 index 80c586d2..00000000 --- a/resources/brave-set-cookie-reload.js +++ /dev/null @@ -1,79 +0,0 @@ -/// - `name` - required, cookie name to be set -/// - `value` - required, cookie value; possible values: -/// - number `>= 0 && <= 15` -/// - one of the predefined constants: -/// - `true` / `True` -/// - `false` / `False` -/// - `yes` / `Yes` / `Y` -/// - `no` -/// - `ok` / `OK` -/// - `path` - optional, cookie path, defaults to `/`; possible values: -/// - `/` — root path -/// - `none` — to set no path at all -(function () { - const arg1 = '{{1}}' - const arg2 = '{{2}}' - const arg3 = '{{3}}' - if (arg1 === '' || arg1 === '{{1}}' || arg2 === '{{2}}') { - throw new Error('Invalid set-cookie scriptlet arguments: ' + - `name=${arg1}, value=${arg2}`) - } - const cookieName = arg1 - const cookieValue = arg2 - const cookiePath = (arg3 === '{{3}}') ? '/' : arg3 - const isCookieSetWithValue = (cookieString, name, value) => { - return cookieString.split(';').some(cookieStr => { - const pos = cookieStr.indexOf('=') - if (pos === -1) { - return false - } - const cookieName = cookieStr.slice(0, pos).trim() - const cookieValue = cookieStr.slice(pos + 1).trim() - return name === cookieName && value === cookieValue - }) - } - const getLimitedCookieValue = value => { - if (!value) { - throw new Error('Invalid empty cookie value') - } - const validConsts = new Set(['true', 'True', 'false', 'False', 'yes', - 'Yes', 'Y', 'no', 'ok', 'OK']) - if (validConsts.has(value)) { - return value - } - if (/^\d+$/.test(value)) { - const floatVal = parseFloat(value) - if (isNaN(floatVal)) { - throw new Error(`Invalid cookie value: ${floatVal}`) - } - if (Math.abs(floatVal) < 0 || Math.abs(floatVal) > 15) { - throw new Error(`Invalid cookie value: ${floatVal}`) - } - return value - } - throw new Error(`Invalid cookie value: ${value}`) - } - const isValidCookieRawPath = (rawPath) => { - return rawPath === '/' || rawPath === 'none' - } - const getCookiePath = (rawPath) => { - return (rawPath === '/') ? 'path=/' : '' - } - const createCookieStr = (rawName, rawValue, rawPath) => { - if (!isValidCookieRawPath(rawPath)) { - throw new Error(`Invalid cookie path: ${rawPath}`) - } - return ''.concat(encodeURIComponent(rawName), '=') - .concat(encodeURIComponent(rawValue), '; ') - .concat(getCookiePath(rawPath)) - } - if (isCookieSetWithValue(document.cookie, cookieName, cookieValue)) { - return - } - const limitedCookieValue = getLimitedCookieValue(cookieValue) - const cookieStr = createCookieStr(cookieName, limitedCookieValue, cookiePath) - document.cookie = cookieStr - if (isCookieSetWithValue(document.cookie, cookieName, limitedCookieValue)) { - window.location.reload() - } -})(); diff --git a/resources/brave-set-cookie.js b/resources/brave-set-cookie.js deleted file mode 100644 index cd48ad0b..00000000 --- a/resources/brave-set-cookie.js +++ /dev/null @@ -1,62 +0,0 @@ -/// - `name` - required, cookie name to be set -/// - `value` - required, cookie value; possible values: -/// - number `>= 0 && <= 15` -/// - one of the predefined constants: -/// - `true` / `True` -/// - `false` / `False` -/// - `yes` / `Yes` / `Y` -/// - `no` -/// - `ok` / `OK` -/// - `path` - optional, cookie path, defaults to `/`; possible values: -/// - `/` — root path -/// - `none` — to set no path at all -(function () { - const arg1 = '{{1}}' - const arg2 = '{{2}}' - const arg3 = '{{3}}' - if (arg1 === '' || arg1 === '{{1}}' || arg2 === '{{2}}') { - throw new Error('Invalid set-cookie scriptlet arguments: ' + - `name=${arg1}, value=${arg2}`) - } - const cookieName = arg1 - const cookieValue = arg2 - const cookiePath = (arg3 === '{{3}}') ? '/' : arg3 - const getLimitedCookieValue = value => { - if (!value) { - throw new Error('Invalid empty cookie value') - } - const validConsts = new Set(['true', 'True', 'false', 'False', 'yes', - 'Yes', 'Y', 'no', 'ok', 'OK']) - if (validConsts.has(value)) { - return value - } - if (/^\d+$/.test(value)) { - const floatVal = parseFloat(value) - if (isNaN(floatVal)) { - throw new Error(`Invalid cookie value: ${floatVal}`) - } - if (Math.abs(floatVal) < 0 || Math.abs(floatVal) > 15) { - throw new Error(`Invalid cookie value: ${floatVal}`) - } - return floatVal - } - throw new Error(`Invalid cookie value: ${value}`) - } - const isValidCookieRawPath = (rawPath) => { - return rawPath === '/' || rawPath === 'none' - } - const getCookiePath = (rawPath) => { - return (rawPath === '/') ? 'path=/' : '' - } - const createCookieStr = (rawName, rawValue, rawPath) => { - if (!isValidCookieRawPath(rawPath)) { - throw new Error(`Invalid cookie path: ${rawPath}`) - } - return ''.concat(encodeURIComponent(rawName), '=') - .concat(encodeURIComponent(rawValue), '; ') - .concat(getCookiePath(rawPath)) - } - const limitedCookieValue = getLimitedCookieValue(cookieValue) - const cookieStr = createCookieStr(cookieName, limitedCookieValue, cookiePath) - document.cookie = cookieStr -})(); diff --git a/resources/brave-set-local-storage-item.js b/resources/brave-set-local-storage-item.js deleted file mode 100644 index 443c03cc..00000000 --- a/resources/brave-set-local-storage-item.js +++ /dev/null @@ -1,63 +0,0 @@ -/// - `key` - required, key name to be set. -/// - `value` - required, key value; possible values: -/// - positive decimal integer `<= 32767` -/// - one of the predefined constants: -/// - `undefined` -/// - `false` -/// - `true` -/// - `null` -/// - `emptyObj` - empty object -/// - `emptyArr` - empty array -/// - `''` - empty string -/// - `yes` -/// - `no` -(function () { - const arg1 = '{{1}}' - const arg2 = '{{2}}' - if (arg1 === '' || arg1 === '{{1}}' || arg2 === '{{2}}') { - throw new Error(`Invalid arguments: name=${arg1}, value=${arg2}`) - } - const key = arg1 - const value = arg2 - const getLimitedStorageItemValue = value => { - if (!value) { - throw new Error('Invalid empty storage value') - } - switch (value) { - case 'undefined': - return undefined - case 'false': - return false - case 'true': - return true - case 'null': - return null - case 'emptyArr': - return '[]' - case 'emptyObj': - return '{}' - case 'yes': - case 'no': - return value - case '': - return '' - } - if (/^\d+$/.test(value)) { - const numericValue = parseFloat(value) - if (isNaN(numericValue)) { - throw new Error(`Invalid storage item value: ${value}`) - } - if (Math.abs(numericValue) > 0x7FFF) { - throw new Error(`Invalid storage item value: ${value}`) - } - return numericValue - } - throw new Error(`Invalid storage item value: ${value}`) - } - try { - const safeValue = getLimitedStorageItemValue(value) - window.localStorage[key]= safeValue - } catch (e) { - throw new Error(`Unable to apply set-local-storage-item scriptlet: ${e}`) - } -})(); diff --git a/resources/brave-set-session-storage-item.js b/resources/brave-set-session-storage-item.js deleted file mode 100644 index 6ebff979..00000000 --- a/resources/brave-set-session-storage-item.js +++ /dev/null @@ -1,63 +0,0 @@ -/// - `key` - required, key name to be set. -/// - `value` - required, key value; possible values: -/// - positive decimal integer `<= 32767` -/// - one of the predefined constants: -/// - `undefined` -/// - `false` -/// - `true` -/// - `null` -/// - `emptyObj` - empty object -/// - `emptyArr` - empty array -/// - `''` - empty string -/// - `yes` -/// - `no` -(function () { - const arg1 = '{{1}}' - const arg2 = '{{2}}' - if (arg1 === '' || arg1 === '{{1}}' || arg2 === '{{2}}') { - throw new Error(`Invalid arguments: name=${arg1}, value=${arg2}`) - } - const key = arg1 - const value = arg2 - const getLimitedStorageItemValue = value => { - if (!value) { - throw new Error('Invalid empty storage value') - } - switch (value) { - case 'undefined': - return undefined - case 'false': - return false - case 'true': - return true - case 'null': - return null - case 'emptyArr': - return '[]' - case 'emptyObj': - return '{}' - case 'yes': - case 'no': - return value - case '': - return '' - } - if (/^\d+$/.test(value)) { - const numericValue = parseFloat(value) - if (isNaN(numericValue)) { - throw new Error(`Invalid storage item value: ${value}`) - } - if (Math.abs(numericValue) > 0x7FFF) { - throw new Error(`Invalid storage item value: ${value}`) - } - return numericValue - } - throw new Error(`Invalid storage item value: ${value}`) - } - try { - const safeValue = getLimitedStorageItemValue(value) - window.sessionStorage[key] = safeValue - } catch (e) { - throw new Error(`Unable to apply set-session-storage-item scriptlet: ${e}`) - } -})();