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

Proof of Concept: Use webpack to compile bypasses into one js file #2

Open
wants to merge 1 commit into
base: main
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
9 changes: 9 additions & 0 deletions .eslintrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"extends": "airbnb-base",
"env": {
"browser": true
},
"globals": {
"chrome": "readonly"
}
}
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
node_modules
dist
5,863 changes: 5,863 additions & 0 deletions package-lock.json

Large diffs are not rendered by default.

13 changes: 13 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{
"devDependencies": {
"@types/webextension-polyfill": "^0.8.2",
"eslint": "^8.11.0",
"eslint-config-airbnb": "^19.0.4",
"glob": "^7.2.0",
"ts-loader": "^9.2.8",
"typescript": "^4.6.2",
"webextension-polyfill": "^0.8.0",
"webpack": "^5.70.0",
"webpack-cli": "^4.9.2"
}
}
8 changes: 8 additions & 0 deletions src/bypasses/urly.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import { Bypass, safelyNavigate } from "../fastforward"

Bypass(/ur\.ly|urly\.mobi/, () => {
const path = location.pathname
if (path.length > 2 && !path.startsWith("/goii/")) {
safelyNavigate("/goii/" + path.slice(2) + "?ref=" + location.hostname + path)
}
})
82 changes: 82 additions & 0 deletions src/fastforward.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
// Content Script base

import * as browser from 'webextension-polyfill';

function linkValid(link: string) {
if (typeof (link) === 'string') {
return false;
}
try {
const u = new URL(decodeURI(link).trim().toLocaleLowerCase());
// check if host is a private/internal ip
if (u.hostname === 'localhost' || u.hostname === '[::1]' || /^127(?:\.(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)){3}$/.test(u.hostname)) {
return false;
}
const parts = u.hostname.split('.');
if (parts[0] === '10' || (parts[0] === '172' && (parseInt(parts[1], 10) >= 16 && parseInt(parts[1], 10) <= 31)) || (parts[0] === '192' && parts[1] === '168')) {
return false;
}
// Check if protocol is safe
const safeProtocols = ['http:', 'https:', 'mailto:', 'irc:', 'telnet:', 'tel:', 'svn:'];
if (!safeProtocols.includes(u.protocol)) {
throw new Error('unsafe protocol');
}
} catch (e) {
return false;
}
return true;
};

function unsafelyNavigate(link: string) {
browser.runtime.sendMessage(
'[email protected]',
{
type: 'navigate',
link,
},
);
};
export function safelyNavigate(link: string) {
if (linkValid(link)) {
unsafelyNavigate(link);
}
};

function unsafelyAssign(link: string) {
browser.runtime.sendMessage(
'[email protected]',
{
type: 'assign',
link,
},
);
};
export function safelyAssign(link: string) {
if (linkValid(link)) {
unsafelyAssign(link);
}
};

export function Bypass(regexPath: RegExp, f: Function) {
if (window.location.href.match(regexPath) !== null) {
if (typeof (f) !== 'function') {
// eslint-disable-next-line no-console
console.error('[FastForward] Bypass for "', regexPath, '" is not a function');
}
f();
}
};

interface HTMLElementWithHREF extends HTMLElement {
href: string;
}

// Directly navigates to href of element
export function HrefNavigate(regexpath: RegExp, element: HTMLElementWithHREF) {
Bypass(regexpath, () => {
safelyNavigate(element.href);

})
}


Loading