Skip to content

Commit

Permalink
Chrome/Edge support and block page
Browse files Browse the repository at this point in the history
  • Loading branch information
OllieJC committed Mar 3, 2022
1 parent 5e6e0a8 commit 877d6d7
Show file tree
Hide file tree
Showing 13 changed files with 2,054 additions and 65 deletions.
6 changes: 6 additions & 0 deletions .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,11 @@ module.exports = {
ecmaVersion: 'latest'
},
rules: {
"no-global-assign": [
"error", {"exceptions": ["browser", "chrome", "module"]}
],
"no-unused-vars": [
"off"
]
}
}
22 changes: 19 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,18 @@
# firefox-no-direct-ip
# no-direct-ip

## What it does

This basic Firefox extension blocks all external / public IP v4 and v6 addresses.
This basic extension blocks all external / public IP v4 and v6 addresses.

## Features

Multi-language support in the _blocked_ page (based of browser's language).

Blocked page follows browser's dark mode.

Blocks both IPv4 and v6 addresses.

Multi-browser support (Edge, Chrome and Firefox tested).

The following IP addresses are allowed:
* 127.0.0.0/8
Expand All @@ -13,6 +23,12 @@ The following IP addresses are allowed:
* ::1/128
* fd00::/8

## Screenshot

<img src="screenshot-dark-mode-en.jpg" alt="Screenshot of the English blocked page in dark mode" width="450px"/>

<img src="screenshot-light-mode-fr.jpg" alt="Screenshot of the French blocked page in light mode" width="450px"/>

## Version

0.1
0.2.0
24 changes: 16 additions & 8 deletions background.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
/* global browser, chrome, module */

if (typeof (chrome) !== 'undefined') {
browser = chrome
}

function isPrivateIPv4 (ip) {
const parts = ip.split('.')
const result = (parts[0] === '10' || parts[0] === '127' ||
Expand Down Expand Up @@ -47,21 +53,23 @@ function checkIp (details) {

if (cancel) {
console.log(`no-direct-ip: blocked access to ${ipType} address: ${hostname}`)
if (typeof (browser) !== 'undefined') {
return { redirectUrl: browser.runtime.getURL('resources/blocked.html?hostname=' + hostname) }
}
}

return { cancel: cancel }
}

/*eslint-disable */
if (typeof(browser) != "undefined") {
if (typeof (browser) !== 'undefined') {
browser.webRequest.onBeforeRequest.addListener(
checkIp,
{urls: ["<all_urls>"]},
["blocking"]
);
{ urls: ['<all_urls>'] },
['blocking']
)
console.log('no-direct-ip: added listener to browser')
}

if (typeof(module) != "undefined") {
module.exports = checkIp;
if (typeof (module) !== 'undefined') {
module.exports = checkIp
}
/* eslint-enable */
Binary file modified icons/block.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
13 changes: 12 additions & 1 deletion icons/block.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
18 changes: 10 additions & 8 deletions manifest.json
Original file line number Diff line number Diff line change
@@ -1,24 +1,26 @@
{
"description": "No Direct IP",
"description": "no-direct-ip",
"manifest_version": 2,
"name": "no-direct-ip",
"version": "0.1",
"homepage_url": "https://github.com/OllieJC/firefox-no-direct-ip",
"version": "0.2.0",
"homepage_url": "https://github.com/OllieJC/no-direct-ip",
"icons": {
"48": "icons/block.svg"
"48": "icons/block.svg",
"96": "icons/block.svg"
},

"permissions": [
"webRequest", "webRequestBlocking", "<all_urls>"
],

"background": {
"scripts": ["background.js"]
},

"browser_specific_settings": {
"gecko": {
"strict_min_version": "57.0a1"
}
}
},
"web_accessible_resources": [
"resources/*",
"icons/*"
]
}
Loading

0 comments on commit 877d6d7

Please sign in to comment.