Skip to content

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

4 Commits
 
 
 
 
 
 

Repository files navigation

Polarity Web Custom-Script Injector v1.0.0

A Bash utility that lets you inject your own JavaScript into the index.html shipped inside Polarity Web’s Docker image and bind-mount the modified assets into your running stack. Useful for cases where a customer needs to run custom tracking or agent code in the web application.


Table of Contents

  1. Features
  2. Prerequisites
  3. Usage

Features

  • Lists local Docker images whose repository contains web and helps you pick one.
  • Validates the selected image actually exists (docker image inspect).
  • Prompts for the JavaScript file to inject (defaults to script.js).
  • Copies /usr/share/caddy out of the image into /tmp.
  • Injects your script just after <head> in index.html.
  • Copies the modified assets to /app/polarity-web-modified.
  • Prints the docker-compose.yml volume snippet and SELinux relabel command you need.
  • Cleans up all temporary artefacts.

Prerequisites

Requirement Notes
Bash 4+ Uses mapfile and here-strings.
Docker 19+ Needs permission to run docker images, docker create, docker cp, etc.
Local Polarity Web image Usually tagged …/web:<version>.
SELinux users The :z flag and chcon command apply when SELinux is enforcing.

Usage

  1. Copy the script somewhere in your PATH:
cp copy-polarity-web.sh /home/<user>

Alternatively, clone this repository into your user directory

Replace {{user}} with your user directory

cd /home/{{user}}
git clone https://github.com/breachintelligence/polarity-web-custom-index-html.git
cd polarity-web-custom-index-html
  1. Make the copy-polarity-web.sh script executable:
chmod +x copy-polarity-web.sh
  1. Place your custom JavaScript (default: script.js) in the same directory or supply another path when prompted.

  2. Run it:

./copy-polarity-web.sh
  1. Edit /app/docker-compose.yml and add the bind-mount:
services:
  web:            
    volumes:
      - /app/polarity-web-modified:/usr/share/caddy:z
  1. Restart the stack:
cd /app && ./down.sh && ./up.sh
  1. If selinux is enabled and in enforcing mode you may need to run the following:
sudo chcon -Rt svirt_sandbox_file_t /app/polarity-web-modified
  1. Re-run the script anytime Polarity Web is updated. Modifying the docker-compose.yml should be a one-time operation unless the compose file has been overwritten.

In Script Configuration Variables

The following configuration variables are used by the script. In most cases you will not need to change these defaults.

# default JS source file
SCRIPT_FILE="script.js"                   

# host dir for patched assets
VOLUME_PATH="/app/polarity-web-modified"  

# Temp container name when copying current web container content
TEMP_CONTAINER_NAME="polarity-web-app-script-injected-temp"

# Temp location to write container content to before modifying `index.html` file
TMP_DIR="/tmp/polarity-web-tmp"

If you need to modify one of the variables you can do so by editing the value at the top of the copy-polarity-web.sh file.

About

Allow customers to inject custom javascript into polarity-web index.html file

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Used by

Contributors

Languages