JavaScript Restrictor
Browser extension that improves privacy and security
Loading...
Searching...
No Matches
http_shield_common.js File Reference

This file contains common functions for Network Boundary Shield. More...

Functions

function nbsLoadConfiguration ()
 
function isIPV4 (url)
 
function isIPV6 (url)
 
function isIPV4Private (ipAddr)
 
function isIPV6Private (ipAddr)
 
function parseCSV (csv, ipv4)
 
function CSVToArray (strData)
 
function expandIPV6 (ip6addr)
 
function isNbsWhitelisted (hostname)
 
function notifyBlockedRequest (origin, target, tabId)
 
function clearNbsNotification (tabId)
 
function async createCumulativeNotification (tabId)
 
function showNbsNotification (tabId)
 
function nbsMessageListener ({message, site}, sender)
 The event listener, hooked up to the webExtension onMessage event.
 
function nbsSettingsListener (message)
 The event listener, hooked up to the webExtension onMessage event.
 
function nbsCommonMessageListener (message, sender)
 

Variables

var localIPV4DNSZones
 
var localIPV6DNSZones
 
var doNotBlockHosts = {}
 
var nbsSettings = {}
 
var nbsNotifications = {}
 
const NBS_DEF_SETTINGS
 

Detailed Description

This file contains common functions for Network Boundary Shield.

Author
Copyright (C) 2020 Pavel Pohner
Copyright (C) 2020-2021 Martin Bednář
Copyright (C) 2022 Marek Salon
License:
SPDX-License-Identifier: GPL-3.0-or-later

This file contains basic logic of the NBS, NBS global variables and objects, functions for reading and parsing CSV files, and functions for identifying and processing IP addresses and checking IP ranges.

Function Documentation

◆ clearNbsNotification()

function clearNbsNotification (   tabId)

Clear notification data for the tab.

Parameters
tabIdTab ID of notification.

◆ createCumulativeNotification()

function async createCumulativeNotification (   tabId)

Create second notification containing a summary of accumulated data. This notification is shown after the initial one if a page continues to access local network.

Parameters
tabIdInteger number representing ID of browser tab.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ CSVToArray()

function CSVToArray (   strData)

Auxillary function for parsing CSV files. Converts CSV to array.

Parameters
strDataLoaded CSV file as a string.
Returns
array containing CSV rows.
Here is the caller graph for this function:

◆ expandIPV6()

function expandIPV6 (   ip6addr)

Function for expanding shorten ipv6 addresses.

Parameters
ip6addrValid ipv6 address.
Returns
expanded ipv6 address in string.
Here is the caller graph for this function:

◆ isIPV4()

function isIPV4 (   url)

Checks validity of IPv4 addresses.

Parameters
urlAn URL that may or may not contains an IPv4 address instead of a domain name.
Returns
TRUE if the url matches IPv4 regex, FALSE otherwise.
Here is the caller graph for this function:

◆ isIPV4Private()

function isIPV4Private (   ipAddr)

Checks whether the ipAddr is found in IPv4 localZones. If the IPv4 address is found in any IPv4 local zone, it means that this IPv4 address is private. IPv4 local zone is e.g. 192.168.000.000/16.

Parameters
ipAddrValid IPv4 address.
Returns
TRUE if ipAddr exists in localZones fetched from IANA, FALSE otherwise.
Here is the caller graph for this function:

◆ isIPV6()

function isIPV6 (   url)

Checks validity IPV6 address.

Parameters
urlAn URL that may or may not contains an IPv6 address instead of a domain name.
Returns
TRUE, if URL is valid IPV6 address, FALSE otherwise.
Here is the caller graph for this function:

◆ isIPV6Private()

function isIPV6Private (   ipAddr)

Checks whether the ipAddr is found in IPv6 localZones. If the IPv6 address is found in any IPv6 local zone, it means that this IPv6 address is private. IPv6 local zone is e.g. fe80::/10.

Parameters
ipAddrValid IPv6 address.
Returns
TRUE if ipAddr exists in localZones fetched from IANA, FALSE otherwise.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ isNbsWhitelisted()

function isNbsWhitelisted (   hostname)

Check if the hostname or any of it's domains is whitelisted.

Parameters
hostnameAny hostname (subdomains allowed).
Returns
TRUE when domain (or subdomain) is whitelisted, FALSE otherwise.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ nbsCommonMessageListener()

function nbsCommonMessageListener (   message,
  sender 
)

Event listener hooked up to webExtensions onMessage event. Does appropriate action based on message (e.g. Turn on/off the NBS, add/remove a site to/from whitelist, ...).

Parameters
messageReceives full message.
senderSender of the message.
Here is the call graph for this function:

◆ nbsLoadConfiguration()

function nbsLoadConfiguration ( )

The function that loads module configuration from sync storage.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ nbsMessageListener()

function nbsMessageListener (   {message, site},
  sender 
)

The event listener, hooked up to the webExtension onMessage event.

The listener sends message response which contains information if the current site is whitelisted or not.

Parameters
messageReceives full message (destructured as {message, site}).
senderSender of the message.

◆ nbsSettingsListener()

function nbsSettingsListener (   message)

The event listener, hooked up to the webExtension onMessage event.

The listener sends message response which contains information about cuurent module settings.

Parameters
messageReceives full message.
Here is the call graph for this function:

◆ notifyBlockedRequest()

function notifyBlockedRequest (   origin,
  target,
  tabId 
)

Log data about NBS blocking in context of tabs. This data will be used for notification creation.

Parameters
originOrigin of the request.
targetTarget of the request.
tabIdTab ID of blocked request.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ parseCSV()

function parseCSV (   csv,
  ipv4 
)

Function for parsing CSV files obtained from IANA. It strips .IN-ADDR and .IP6 from zones and comma delimiter, merges them into array by CSV rows.

Parameters
csvCSV obtained from IANA.
ipv4Boolean, saying whether the csv is IPv4 CSV or IPv6.
Returns
an array of parsed CSV values.
Here is the call graph for this function:

◆ showNbsNotification()

function showNbsNotification (   tabId)

Creates and presents notification about blocked requests.

Parameters
tabIdInteger number representing ID of browser tab.
Here is the caller graph for this function:

Variable Documentation

◆ doNotBlockHosts

var doNotBlockHosts = {}

Associtive array of hosts, that are currently among trusted "do not blocked" hosts.

◆ localIPV4DNSZones

var localIPV4DNSZones

Locally served IPV4 DNS zones loaded from IANA.

◆ localIPV6DNSZones

var localIPV6DNSZones

Locally served IPV6 DNS zones loaded from IANA.

◆ NBS_DEF_SETTINGS

const NBS_DEF_SETTINGS

Definition of settings supported by this module.

◆ nbsNotifications

var nbsNotifications = {}

Object holding active notifications of this module.

◆ nbsSettings

var nbsSettings = {}

Associtive array of settings supported by this module.