Skip to content

High-performance browser automation bridge and multi-instance orchestrator with advanced stealth injection and real-time dashboard.

feat(e2e): add security control verification tests

Bosch5b2bc5c10181
diff --git a/tests/e2e/Dockerfile.pinchtab-secure b/tests/e2e/Dockerfile.pinchtab-secure
new file mode 100644
index 00000000..4107d7ed
--- /dev/null
+++ b/tests/e2e/Dockerfile.pinchtab-secure
@@ -0,0 +1,56 @@
+# Pinchtab with STRICT security settings (features DISABLED)
+# Used to test that security controls actually block requests
+
+# Build stage
+FROM golang:1.26-alpine AS builder
+RUN apk add --no-cache git
+WORKDIR /build
+COPY go.mod go.sum ./
+RUN go mod download
+COPY . .
+RUN go build -ldflags="-s -w" -o pinchtab ./cmd/pinchtab
+
+# Runtime stage
+FROM alpine:latest
+
+# Install Chromium and dependencies (same as main Dockerfile)
+RUN apk add --no-cache \
+ chromium \
+ nss \
+ freetype \
+ harfbuzz \
+ ca-certificates \
+ ttf-freefont \
+ curl \
+ dumb-init
+
+# Create non-root user and state directory
+RUN adduser -D -g '' pinchtab && \
+ mkdir -p /data && \
+ chown pinchtab:pinchtab /data
+
+# Copy binary from builder
+COPY --from=builder /build/pinchtab /usr/local/bin/pinchtab
+
+# Stay as root for --no-sandbox Chrome
+WORKDIR /data
+
+# Environment variables for headless Chrome in Docker
+ENV PINCHTAB_BIND=0.0.0.0 \
+ PINCHTAB_PORT=9999 \
+ PINCHTAB_HEADLESS=true \
+ PINCHTAB_STATE_DIR=/data \
+ CHROME_BIN=/usr/bin/chromium-browser
+
+# STRICT security config:
+# - evaluate DISABLED
+# - download DISABLED
+# - upload DISABLED
+# - IDPI ENABLED with empty allowlist (blocks all navigation)
+RUN mkdir -p /root/.config/pinchtab && \
+ echo '{"browser":{"extraFlags":"--no-sandbox --disable-dev-shm-usage"},"instanceDefaults":{"maxTabs":10,"tabEvictionPolicy":"close_lru"},"security":{"allowEvaluate":false,"allowDownload":false,"allowUpload":false,"idpi":{"enabled":true,"strictMode":true,"allowedDomains":[]}}}' > /root/.config/pinchtab/config.json
+
+EXPOSE 9999
+
+ENTRYPOINT ["/usr/bin/dumb-init", "--"]
+CMD ["pinchtab", "server"]
diff --git a/tests/e2e/docker-compose.yml b/tests/e2e/docker-compose.yml
index 7cd1d0fb..862c45c3 100644
--- a/tests/e2e/docker-compose.yml
+++ b/tests/e2e/docker-compose.yml
@@ -1,4 +1,5 @@
services:
+ # Main instance: security features ENABLED (permissive)
pinchtab:
build:
context: ../..
@@ -14,6 +15,21 @@ services:
retries: 20
start_period: 15s
+ # Secure instance: security features DISABLED (restrictive)
+ pinchtab-secure:
+ build:
+ context: ../..
+ dockerfile: tests/e2e/Dockerfile.pinchtab-secure
+ ports:
+ - "9998:9999"
+ shm_size: '2gb'
+ healthcheck:
+ test: ["CMD", "curl", "-sf", "http://localhost:9999/health"]
+ interval: 3s
+ timeout: 10s
+ retries: 20
+ start_period: 15s
+
fixtures:
image: nginx:alpine
volumes:
@@ -30,10 +46,13 @@ services:
depends_on:
pinchtab:
condition: service_healthy
+ pinchtab-secure:
+ condition: service_healthy
fixtures:
condition: service_healthy
environment:
- PINCHTAB_URL=http://pinchtab:9999
+ - PINCHTAB_SECURE_URL=http://pinchtab-secure:9999
- FIXTURES_URL=http://fixtures:80
volumes:
- ./scenarios:/scenarios:ro
diff --git a/tests/e2e/scenarios/11-security.sh b/tests/e2e/scenarios/11-security.sh
new file mode 100755
index 00000000..8f286c25
--- /dev/null
+++ b/tests/e2e/scenarios/11-security.sh
@@ -0,0 +1,128 @@
+#!/bin/bash
+# 11-security.sh — Security controls verification
+#
+# Tests that security features properly block/allow requests based on config.
+# Uses two pinchtab instances:
+# - PINCHTAB_URL: permissive (evaluate/download/upload enabled)
+# - PINCHTAB_SECURE_URL: restrictive (all disabled)
+
+source "$(dirname "$0")/common.sh"
+
+# Helper to target the secure (restrictive) instance
+secure_get() {
+ local path="$1"
+ shift
+ local old_url="$PINCHTAB_URL"
+ PINCHTAB_URL="$PINCHTAB_SECURE_URL"
+ pt_get "$path" "$@"
+ PINCHTAB_URL="$old_url"
+}
+
+secure_post() {
+ local path="$1"
+ shift
+ local old_url="$PINCHTAB_URL"
+ PINCHTAB_URL="$PINCHTAB_SECURE_URL"
+ pt_post "$path" "$@"
+ PINCHTAB_URL="$old_url"
+}
+
+# ═══════════════════════════════════════════════════════════════════
+# EVALUATE SECURITY
+# ═══════════════════════════════════════════════════════════════════
+
+start_test "security: evaluate ALLOWED when enabled"
+
+pt_post /navigate -d '{"url":"about:blank"}'
+pt_post /evaluate -d '{"expression":"1+1"}'
+assert_ok "evaluate allowed"
+
+end_test
+
+# ─────────────────────────────────────────────────────────────────
+start_test "security: evaluate BLOCKED when disabled"
+
+secure_post /navigate -d '{"url":"about:blank"}'
+secure_post /evaluate -d '{"expression":"1+1"}'
+assert_http_status 403 "evaluate blocked"
+assert_contains "$RESULT" "evaluate_disabled" "correct error code"
+
+end_test
+
+# ═══════════════════════════════════════════════════════════════════
+# DOWNLOAD SECURITY
+# ═══════════════════════════════════════════════════════════════════
+
+start_test "security: download ALLOWED when enabled"
+
+pt_get "/download?url=https://httpbin.org/robots.txt"
+assert_ok "download allowed"
+
+end_test
+
+# ─────────────────────────────────────────────────────────────────
+start_test "security: download BLOCKED when disabled"
+
+secure_get "/download?url=https://httpbin.org/robots.txt"
+assert_http_status 403 "download blocked"
+assert_contains "$RESULT" "download_disabled" "correct error code"
+
+end_test
+
+# ═══════════════════════════════════════════════════════════════════
+# UPLOAD SECURITY
+# ═══════════════════════════════════════════════════════════════════
+
+start_test "security: upload ALLOWED when enabled"
+
+pt_post /navigate -d "{\"url\":\"${FIXTURES_URL}/upload.html\"}"
+sleep 1
+pt_post /upload -d '{"selector":"#single-file","files":["data:text/plain;base64,dGVzdA=="]}'
+assert_ok "upload allowed"
+
+end_test
+
+# ─────────────────────────────────────────────────────────────────
+start_test "security: upload BLOCKED when disabled"
+
+# Note: navigation might fail due to IDPI, but upload check happens first
+secure_post /upload -d '{"selector":"#single-file","files":["data:text/plain;base64,dGVzdA=="]}'
+assert_http_status 403 "upload blocked"
+assert_contains "$RESULT" "upload_disabled" "correct error code"
+
+end_test
+
+# ═══════════════════════════════════════════════════════════════════
+# IDPI (Navigation Security)
+# ═══════════════════════════════════════════════════════════════════
+
+start_test "security: IDPI allows whitelisted domains"
+
+# Main instance has fixtures in allowlist
+pt_post /navigate -d "{\"url\":\"${FIXTURES_URL}/index.html\"}"
+assert_ok "navigate to allowed domain"
+
+end_test
+
+# ─────────────────────────────────────────────────────────────────
+start_test "security: IDPI blocks non-whitelisted domains"
+
+# Secure instance has empty allowlist - should block all navigation
+secure_post /navigate -d '{"url":"https://example.com"}'
+assert_http_status 403 "navigate blocked by IDPI"
+assert_contains "$RESULT" "IDPI\|blocked\|allowed" "IDPI error message"
+
+end_test
+
+# ═══════════════════════════════════════════════════════════════════
+# VERIFY ERROR RESPONSE FORMAT
+# ═══════════════════════════════════════════════════════════════════
+
+start_test "security: blocked responses include helpful info"
+
+secure_post /evaluate -d '{"expression":"1"}'
+assert_http_status 403 "returns 403"
+assert_json_exists "$RESULT" ".code" "has error code"
+assert_json_exists "$RESULT" ".error" "has error message"
+
+end_test
diff --git a/tests/e2e/scenarios/common.sh b/tests/e2e/scenarios/common.sh
index 332c98f5..d037da5c 100755
--- a/tests/e2e/scenarios/common.sh
+++ b/tests/e2e/scenarios/common.sh
@@ -14,6 +14,7 @@ NC='\033[0m'
# Defaults from environment
PINCHTAB_URL="${PINCHTAB_URL:-http://localhost:9999}"
+PINCHTAB_SECURE_URL="${PINCHTAB_SECURE_URL:-http://localhost:9998}"
FIXTURES_URL="${FIXTURES_URL:-http://localhost:8080}"
RESULTS_DIR="${RESULTS_DIR:-/results}"