Skip to content

A free, open-source alternative to Burp Suite: an intercepting proxy and web app security testing suite with Repeater, Intruder, Collaborator and a built-in OWASP ZAP scanner. Linux, AGPL-3.0.

4.9 KB
Raw Blame
#!/usr/bin/env bash
# Download a standalone, redistributable Chromium into the product so the
# embedded browser works on machines with no browser installed.
# Plain open-source Chromium (BSD-licensed), not Chrome for Testing, so there
# is no "automated testing" banner and it can be shipped freely.
#
# The snapshot revision and the sha256 of both archives are pinned in
# tools/versions, so every machine installs identical, verified bytes rather
# than whatever snapshot is latest that day. Google's snapshot storage does
# not publish a sha256, so the pin is the hash of the downloaded archive;
# tools/check-updates.sh reports when a newer snapshot exists.
set -euo pipefail
DIR="$(cd "$(dirname "$0")" && pwd)"
DEST="$DIR/browser"
mkdir -p "$DEST"
source "$DIR/tools/versions"

case "$(uname -s)-$(uname -m)" in
    Linux-x86_64)
        PLAT=Linux_x64; REV="$CHROMIUM_REVISION"; NAME=chrome-linux; DRV=chromedriver_linux64
        CHROME_SHA="$CHROMIUM_CHROME_SHA256"; DRIVER_SHA="$CHROMIUM_DRIVER_SHA256"; BIN=chrome ;;
    Darwin-arm64)
        PLAT=Mac_Arm; REV="$CHROMIUM_REVISION_MAC_ARM"; NAME=chrome-mac; DRV=chromedriver_mac64
        CHROME_SHA="$CHROMIUM_CHROME_SHA256_MAC_ARM"; DRIVER_SHA="$CHROMIUM_DRIVER_SHA256_MAC_ARM"
        BIN=Chromium.app/Contents/MacOS/Chromium ;;
    MINGW*-x86_64|MSYS*-x86_64)
        PLAT=Win_x64; REV="$CHROMIUM_REVISION_WINDOWS"; NAME=chrome-win; DRV=chromedriver_win32
        CHROME_SHA="$CHROMIUM_CHROME_SHA256_WINDOWS"; DRIVER_SHA="$CHROMIUM_DRIVER_SHA256_WINDOWS"; BIN=chrome.exe
        DRVBIN=chromedriver.exe ;;
    *) echo "No pinned Chromium for $(uname -s) $(uname -m)" >&2; exit 1 ;;
esac
DRVBIN="${DRVBIN:-chromedriver}"
BASE="https://commondatastorage.googleapis.com/chromium-browser-snapshots/$PLAT"
# Downloads land in a scratch directory and only move into browser/ once
# complete and verified, so an interrupted or tampered run never leaves a
# half-extracted or unverified tree behind.
TMP="$(mktemp -d)"
trap 'rm -rf "$TMP"' EXIT

check() { # <file> <expected sha256>
    local got
    got="$( { sha256sum "$1" 2>/dev/null || shasum -a 256 "$1"; } | cut -d' ' -f1)"
    if [ "$got" != "$2" ]; then
        echo "sha256 mismatch for $1:" >&2
        echo "  expected $2 (update the pin in tools/versions?)" >&2
        echo "  got      $got" >&2
        exit 1
    fi
}

unpack() { # <zip> <folder>: unzip where it is installed, else Windows' or Python's own unpacker
    if command -v unzip >/dev/null 2>&1; then unzip -q "$1" -d "$2"
    elif command -v powershell >/dev/null 2>&1; then
        powershell -NoProfile -Command "\$ProgressPreference='SilentlyContinue'; Expand-Archive -Force '$(cygpath -w "$1")' '$(cygpath -w "$2")'"
    else
        # Python's unpacker alone drops what the browser needs: which files are
        # programs, and the symbolic links inside the macOS app bundle.
        python3 -I - "$1" "$2" <<'PY'
import os, stat, sys, zipfile
src, dest = sys.argv[1], os.path.realpath(sys.argv[2])
with zipfile.ZipFile(src) as z:
    for i in z.infolist():
        out = os.path.realpath(os.path.join(dest, i.filename))
        if out != dest and not out.startswith(dest + os.sep): sys.exit("unsafe path in archive: " + i.filename)
        mode = i.external_attr >> 16
        if stat.S_ISLNK(mode):
            os.makedirs(os.path.dirname(out), exist_ok=True)
            os.symlink(z.read(i).decode(), os.path.join(dest, i.filename))
            continue
        z.extract(i, dest)
        if mode and not i.is_dir(): os.chmod(out, stat.S_IMODE(mode))
PY
    fi
}

echo "Installing pinned Chromium snapshot $REV (edit tools/versions to change)..."
echo "Downloading Chromium..."
curl -fSL -o "$TMP/chrome.zip" "$BASE/$REV/$NAME.zip"
check "$TMP/chrome.zip" "$CHROME_SHA"
echo "Extracting..."
# unzip restores the symbolic links inside the macOS app bundle.
unpack "$TMP/chrome.zip" "$TMP"
# The Windows snapshot carries a test program a third of its size that nothing here runs.
rm -f "$TMP/$NAME/interactive_ui_tests.exe"
rm -rf "$DEST/chrome-linux" "$DEST/chrome-mac" "$DEST/chrome-win"
mv -f "$TMP/$NAME" "$DEST/$NAME"
chmod +x "$DEST/$NAME/$BIN" 2>/dev/null || true
echo "$REV" > "$DEST/$NAME/REVISION"
echo "Bundled Chromium ready at $DEST/$NAME/$BIN"
"$DEST/$NAME/$BIN" --version 2>/dev/null || true

# The matching chromedriver from the same snapshot, so ZAP's AJAX spider can
# drive this exact Chromium headlessly. Versions must match, so it comes from
# the same revision as the browser above.
echo "Downloading matching chromedriver..."
curl -fSL -o "$TMP/chromedriver.zip" "$BASE/$REV/$DRV.zip"
check "$TMP/chromedriver.zip" "$DRIVER_SHA"
unpack "$TMP/chromedriver.zip" "$TMP"
# Flatten to browser/chromedriver, where EmbeddedBrowser.findDriver looks first.
rm -rf "$DEST/chromedriver" "$DEST/chromedriver.exe" "$DEST/$DRV"
mv -f "$TMP/$DRV/$DRVBIN" "$DEST/$DRVBIN"
chmod +x "$DEST/$DRVBIN" 2>/dev/null || true
echo "Bundled chromedriver ready at $DEST/$DRVBIN"
"$DEST/$DRVBIN" --version 2>/dev/null || true