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

Fix bypasses not executing correctly #1134

Merged
merged 1 commit into from
Oct 1, 2023
Merged
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
4 changes: 2 additions & 2 deletions .github/workflows/codeql-analysis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -38,11 +38,11 @@ jobs:

steps:
- name: Checkout repository
uses: actions/checkout@v2
uses: actions/checkout@v3

# Initializes the CodeQL tools for scanning.
- name: Initialize CodeQL
uses: github/codeql-action/init@v1
uses: github/codeql-action/init@v2
with:
languages: ${{ matrix.language }}
# If you wish to specify custom queries, you can do so here or in a config file.
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ name: Package

on:
push:
branches: [main, manifest-v3]
branches: [main, manifest-v3, fixes]

workflow_dispatch:

Expand Down
6 changes: 4 additions & 2 deletions scripts/build_js/injection_script_template.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,14 @@ function matchingBypass(bypasses) {
for (const [key] of Object.entries(bypasses)) {
if (key.charAt(0) === '/' && key.charAt(key.length - 1) === '/') {
let pattern = new RegExp(key.substring(1, key.length - 1));
return pattern.test(location.href) ? key : null;
if (pattern.test(location.href)) {
return key;
}
} else if (key === location.host) {
return key;
}
return null;
}
return null;
}

if (matchingBypass(bypasses)) {
Expand Down
2 changes: 1 addition & 1 deletion src/bypasses/clictune.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,4 @@ export default class Clictune extends BypassDefinition {
}
}

export const matches = ['www.dlink2.com']
export const matches = ['www.dlink2.net', 'www.dlink2.com', 'www.clictune.com']
307 changes: 151 additions & 156 deletions src/js/background.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,189 +12,184 @@ if (isFirefox) {
browser.tabs.create({
url: 'html/consent.html',
});
} else {
// If consent has been already granted, execute background script
executeBackgroundScript();
return;
}
});
return;
}
});
} else {
// For non-Firefox browsers, execute background script
executeBackgroundScript();
}

function executeBackgroundScript() {
const brws = typeof browser !== 'undefined' ? browser : chrome;
const fetchDomains = ['crowd.fastforward.team', 'redirect-api.work.ink']; //only allow requests to these domains
const brws = typeof browser !== 'undefined' ? browser : chrome;
const fetchDomains = ['crowd.fastforward.team', 'redirect-api.work.ink']; //only allow requests to these domains

async function getOptions() {
return new Promise((resolve) => {
brws.storage.local.get('options').then((result) => {
resolve(result.options);
});
async function getOptions() {
return new Promise((resolve) => {
brws.storage.local.get('options').then((result) => {
resolve(result.options);
});
}
});
}

function ffclipboardClear() {
brws.storage.local.set({ ff_clipboard: '{}' });
}
function ffclipboardClear() {
brws.storage.local.set({ ff_clipboard: '{}' });
}

function clearCrowdIgnoredURLs() {
brws.storage.local.set({ crowd_ignore: '{}' });
}
function clearCrowdIgnoredURLs() {
brws.storage.local.set({ crowd_ignore: '{}' });
}

function firstrun(details) {
if (details.reason == 'install' || details.reason == 'update') {
brws.tabs.create({ url: 'https://fastforward.team/firstrun' });
ffclipboardClear();
brws.storage.local.set({ tempDisableCrowd: 'false' });
brws.storage.local.set({ version: brws.runtime.getManifest().version });
brws.runtime.openOptionsPage(); //required for loading default options, to do: implement a better way
brws.declarativeNetRequest.updateDynamicRules({
addRules: constants.beforeNavigateRules,
removeRuleIds: constants.beforeNavigateRules.map((rule) => rule.id),
});
}
function firstrun(details) {
if (details.reason == 'install' || details.reason == 'update') {
brws.tabs.create({ url: 'https://fastforward.team/firstrun' });
ffclipboardClear();
brws.storage.local.set({ tempDisableCrowd: 'false' });
brws.storage.local.set({ version: brws.runtime.getManifest().version });
brws.runtime.openOptionsPage(); //required for loading default options, to do: implement a better way
brws.declarativeNetRequest.updateDynamicRules({
addRules: constants.beforeNavigateRules,
removeRuleIds: constants.beforeNavigateRules.map((rule) => rule.id),
});
}
}

function preflight(details) {
let url = new URL(details.url);
if (url.hostname !== 'fastforward.team') {
return;
}
//navigate
if (url.pathname === '/bypassed') {
let ext_url = new URL(brws.runtime.getURL(''));
url.hostname = ext_url.hostname;
url.protocol = ext_url.protocol;
url.pathname = '/html' + url.pathname;
if (url.searchParams.get('crowd') === 'true') {
url.pathname =
url.pathname.split('/').slice(0, -1).join('/') +
'/crowd-bypassed.html';
} else {
url.pathname =
url.pathname.split('/').slice(0, -1).join('/') +
'/before-navigate.html';
}

brws.tabs.update(details.tabId, {
url: url.href,
});
}
function preflight(details) {
let url = new URL(details.url);
if (url.hostname !== 'fastforward.team') {
return;
}
//navigate
if (url.pathname === '/bypassed') {
let ext_url = new URL(brws.runtime.getURL(''));
url.hostname = ext_url.hostname;
url.protocol = ext_url.protocol;
url.pathname = '/html' + url.pathname;
if (url.searchParams.get('crowd') === 'true') {
url.pathname =
url.pathname.split('/').slice(0, -1).join('/') +
'/crowd-bypassed.html';
} else {
url.pathname =
url.pathname.split('/').slice(0, -1).join('/') +
'/before-navigate.html';
}

function reEnableCrowdBypassStartup() {
brws.storage.local.get(['tempDisableCrowd']).then((result) => {
if (result.tempDisableCrowd === 'true') {
brws.storage.local.get(['options']).then((result) => {
let opt = result.options;
opt.optionCrowdBypass = true;
brws.storage.local.set({ options: opt });
});
}
brws.storage.local.set({ tempDisableCrowd: 'false' });
brws.tabs.update(details.tabId, {
url: url.href,
});
}
}

brws.alarms.onAlarm.addListener((alarm) => {
brws.storage.local.get(['tempDisableCrowd']).then((result) => {
if (
alarm.name === 'enableCrowdBypass' &&
result.tempDisableCrowd === 'true'
) {
brws.storage.local.get(['options']).then((result) => {
let opt = result.options;
opt.optionCrowdBypass = true;
brws.storage.local.set({ options: opt });
brws.storage.local.set({ tempDisableCrowd: 'false' });
});
}
});
function reEnableCrowdBypassStartup() {
brws.storage.local.get(['tempDisableCrowd']).then((result) => {
if (result.tempDisableCrowd === 'true') {
brws.storage.local.get(['options']).then((result) => {
let opt = result.options;
opt.optionCrowdBypass = true;
brws.storage.local.set({ options: opt });
});
}
brws.storage.local.set({ tempDisableCrowd: 'false' });
});
}

brws.runtime.onInstalled.addListener(firstrun);
brws.runtime.onStartup.addListener(() => {
ffclipboardClear();
clearCrowdIgnoredURLs();
reEnableCrowdBypassStartup();
brws.storage.local.set({ version: brws.runtime.getManifest().version });
brws.alarms.onAlarm.addListener((alarm) => {
brws.storage.local.get(['tempDisableCrowd']).then((result) => {
if (
alarm.name === 'enableCrowdBypass' &&
result.tempDisableCrowd === 'true'
) {
brws.storage.local.get(['options']).then((result) => {
let opt = result.options;
opt.optionCrowdBypass = true;
brws.storage.local.set({ options: opt });
brws.storage.local.set({ tempDisableCrowd: 'false' });
});
}
});
});

brws.runtime.onInstalled.addListener(firstrun);
brws.runtime.onStartup.addListener(() => {
ffclipboardClear();
clearCrowdIgnoredURLs();
reEnableCrowdBypassStartup();
brws.storage.local.set({ version: brws.runtime.getManifest().version });
});

brws.runtime.onMessage.addListener((request, _, sendResponse) => {
(async () => {
let options = await getOptions();
if (options.optionCrowdBypass === false) {
return;
}
let url;
request.type === 'crowdQuery'
? (url = 'https://crowd.fastforward.team/crowd/query_v1')
: (url = 'https://crowd.fastforward.team/crowd/contribute_v1');

brws.runtime.onMessage.addListener((request, _, sendResponse) => {
(async () => {
let options = await getOptions();
if (options.optionCrowdBypass === false) {
return;
}
let url;
request.type === 'crowdQuery'
? (url = 'https://crowd.fastforward.team/crowd/query_v1')
: (url = 'https://crowd.fastforward.team/crowd/contribute_v1');

let params = new URLSearchParams();
let params = new URLSearchParams();

if (request.type !== 'followAndContribute') {
for (let key in request.detail) {
params.append(key, request.detail[key]);
}
} else {
for (let key in request.detail) {
if (key === 'target') {
let dest = new URL(request.detail[key]);
if (!fetchDomains.includes(dest.hostname)) {
return;
}
let res = await fetch(dest.href, {
method: 'GET',
redirect: 'follow',
});
params.append(key, res.url);
} else {
params.append(key, request.detail[key]);
if (request.type !== 'followAndContribute') {
for (let key in request.detail) {
params.append(key, request.detail[key]);
}
} else {
for (let key in request.detail) {
if (key === 'target') {
let dest = new URL(request.detail[key]);
if (!fetchDomains.includes(dest.hostname)) {
return;
}
let res = await fetch(dest.href, {
method: 'GET',
redirect: 'follow',
});
params.append(key, res.url);
} else {
params.append(key, request.detail[key]);
}
}
}

let response = await fetch(url, {
method: 'POST',
body: params.toString(),
headers: {
'Content-Type': 'application/x-www-form-urlencoded',
},
});
if (request.type === 'crowdQuery')
response.text().then((res) => {
sendResponse(res);
});
})();
return true;
});

let response = await fetch(url, {
method: 'POST',
body: params.toString(),
headers: {
'Content-Type': 'application/x-www-form-urlencoded',
},
brws.storage.onChanged.addListener(() => {
getOptions().then((options) => {
if (typeof options === 'undefined') {
return;
}
if (options.optionBlockIpLoggers === false) {
brws.declarativeNetRequest.updateEnabledRulesets({
disableRulesetIds: ['ipLoggerRuleset'],
});
} else {
brws.declarativeNetRequest.updateEnabledRulesets({
enableRulesetIds: ['ipLoggerRuleset'],
});
}
if (options.optionTrackerBypass === false) {
brws.declarativeNetRequest.updateEnabledRulesets({
disableRulesetIds: ['trackerRuleset'],
});
} else {
brws.declarativeNetRequest.updateEnabledRulesets({
enableRulesetIds: ['trackerRuleset'],
});
if (request.type === 'crowdQuery')
response.text().then((res) => {
sendResponse(res);
});
})();
return true;
}
});
});

brws.storage.onChanged.addListener(() => {
getOptions().then((options) => {
if (typeof options === 'undefined') {
return;
}
if (options.optionBlockIpLoggers === false) {
brws.declarativeNetRequest.updateEnabledRulesets({
disableRulesetIds: ['ipLoggerRuleset'],
});
} else {
brws.declarativeNetRequest.updateEnabledRulesets({
enableRulesetIds: ['ipLoggerRuleset'],
});
}
if (options.optionTrackerBypass === false) {
brws.declarativeNetRequest.updateEnabledRulesets({
disableRulesetIds: ['trackerRuleset'],
});
} else {
brws.declarativeNetRequest.updateEnabledRulesets({
enableRulesetIds: ['trackerRuleset'],
});
}
});
});
}