Skip to content

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

test: make redirect/IDPI/SSRF tests self-contained via local nginx

Luigi Agosti8d73652b96d2
diff --git a/.nvmrc b/.nvmrc
new file mode 100644
index 00000000..2bd5a0a9
--- /dev/null
+++ b/.nvmrc
@@ -0,0 +1 @@
+22
diff --git a/dashboard/src/pages/MonitoringPage.test.tsx b/dashboard/src/pages/MonitoringPage.test.tsx
index cef45b45..9eae7ffb 100644
--- a/dashboard/src/pages/MonitoringPage.test.tsx
+++ b/dashboard/src/pages/MonitoringPage.test.tsx
@@ -77,9 +77,7 @@ describe("MonitoringPage", () => {
);
await waitFor(() => {
- expect(
- screen.getByRole("heading", { name: "beta" }),
- ).toBeInTheDocument();
+ expect(screen.getByRole("heading", { name: "beta" })).toBeInTheDocument();
});
await userEvent.click(screen.getByRole("button", { name: "Open Profile" }));
diff --git a/dashboard/src/pages/ProfilesPage.test.tsx b/dashboard/src/pages/ProfilesPage.test.tsx
index 1a21b6f9..9873ac45 100644
--- a/dashboard/src/pages/ProfilesPage.test.tsx
+++ b/dashboard/src/pages/ProfilesPage.test.tsx
@@ -73,7 +73,9 @@ function clickSidebarProfile(name: string) {
}
function getDetailPanel() {
- return document.querySelector(".dashboard-panel .min-w-0.flex-1") as HTMLElement;
+ return document.querySelector(
+ ".dashboard-panel .min-w-0.flex-1",
+ ) as HTMLElement;
}
describe("ProfilesPage", () => {
@@ -95,7 +97,9 @@ describe("ProfilesPage", () => {
).toBeInTheDocument();
});
- const sidebar = document.querySelector(".bg-bg-surface\\/50") as HTMLElement;
+ const sidebar = document.querySelector(
+ ".bg-bg-surface\\/50",
+ ) as HTMLElement;
const sidebarButtons = within(sidebar).getAllByRole("button");
const profileButtons = sidebarButtons.filter((b) =>
b.classList.contains("border-b"),
diff --git a/scripts/e2e.sh b/scripts/e2e.sh
old mode 100644
new mode 100755
index 45eee79a..5a4e426a
--- a/scripts/e2e.sh
+++ b/scripts/e2e.sh
@@ -39,6 +39,16 @@ compose_down() {
$COMPOSE -f "${compose_file}" down -v 2>/dev/null || true
}
+# Always rebuild the fixtures nginx image up front so changes to
+# tests/e2e/nginx/{Dockerfile,default.conf} are guaranteed to land in the
+# container, regardless of whether `compose run --build` would otherwise
+# rebuild this transitive dependency. This eliminates an entire class of
+# "the new fixture config didn't get picked up" failure modes.
+build_support_images() {
+ local compose_file="$1"
+ $COMPOSE -f "${compose_file}" build fixtures
+}
+
dump_compose_failure() {
local compose_file="$1"
shift
@@ -121,6 +131,7 @@ run_api_fast() {
show_filter_status
echo ""
prepare_suite_results "${summary_file}" "${report_file}" "${progress_file}" "${log_prefix}"
+ build_support_images "${compose_file}"
set +e
if [ -n "${E2E_FILTER}" ]; then
$COMPOSE -f "${compose_file}" run --build --rm runner-api /bin/bash /e2e/run.sh api "filter=${E2E_FILTER}"
@@ -147,6 +158,7 @@ run_full_api() {
show_filter_status
echo ""
prepare_suite_results "${summary_file}" "${report_file}" "${progress_file}" "${log_prefix}"
+ build_support_images "${compose_file}"
set +e
E2E_SCENARIO_FILTER="${E2E_FILTER}" $COMPOSE -f "${compose_file}" up --build --abort-on-container-exit --exit-code-from runner-api runner-api
local api_exit=$?
@@ -169,6 +181,7 @@ run_cli_fast() {
show_filter_status
echo ""
prepare_suite_results "${summary_file}" "${report_file}" "${progress_file}" "${log_prefix}"
+ build_support_images "${compose_file}"
set +e
if [ -n "${E2E_FILTER}" ]; then
$COMPOSE -f "${compose_file}" run --build --rm runner-cli /bin/bash /e2e/run.sh cli "filter=${E2E_FILTER}"
@@ -195,6 +208,7 @@ run_full_cli() {
show_filter_status
echo ""
prepare_suite_results "${summary_file}" "${report_file}" "${progress_file}" "${log_prefix}"
+ build_support_images "${compose_file}"
set +e
E2E_SCENARIO_FILTER="${E2E_FILTER}" $COMPOSE -f "${compose_file}" up --build --abort-on-container-exit --exit-code-from runner-cli runner-cli
local cli_exit=$?
diff --git a/tests/e2e/docker-compose-multi.yml b/tests/e2e/docker-compose-multi.yml
index 3d878c4e..4335ac8c 100644
--- a/tests/e2e/docker-compose-multi.yml
+++ b/tests/e2e/docker-compose-multi.yml
@@ -117,11 +117,31 @@ services:
start_period: 15s
fixtures:
- image: nginx:alpine
+ # Custom image: nginx + baked-in default.conf with httpbin-compatible
+ # /redirect/N, /redirect-to, and /get endpoints. Baking the config in
+ # avoids bind-mount races where the new conf doesn't get picked up on
+ # `docker compose up` without a forced recreate.
+ build:
+ context: ./nginx
volumes:
- ./fixtures:/usr/share/nginx/html:ro
+ networks:
+ default:
+ # Second hostname that points at the same nginx. Used by IDPI
+ # same-tab pivot tests: the page navigates from `fixtures` (in the
+ # IDPI allowlist) to `pivot-target` (not in the allowlist) to
+ # simulate a cross-domain pivot while staying fully offline.
+ aliases:
+ - fixtures
+ - pivot-target
healthcheck:
- test: ["CMD-SHELL", "wget -q -O /dev/null http://localhost:80/"]
+ # Verify BOTH that nginx is up AND that the custom config is the one
+ # actually loaded. /get is a synthetic endpoint defined only in
+ # tests/e2e/nginx/default.conf — if it returns 200 we know the baked
+ # config is live; if it 404s the container stays unhealthy and the
+ # test runner refuses to start, which surfaces "stale image / config
+ # not loaded" failures up front instead of as opaque test errors.
+ test: ["CMD-SHELL", "wget -q -O /dev/null http://localhost:80/ && wget -q -O /dev/null http://localhost:80/get"]
interval: 2s
timeout: 5s
retries: 5
diff --git a/tests/e2e/docker-compose.yml b/tests/e2e/docker-compose.yml
index 20d06a21..8157a2b1 100644
--- a/tests/e2e/docker-compose.yml
+++ b/tests/e2e/docker-compose.yml
@@ -21,12 +21,32 @@ services:
start_period: 15s
fixtures:
- image: nginx:alpine
+ # Custom image: nginx + baked-in default.conf with httpbin-compatible
+ # /redirect/N, /redirect-to, and /get endpoints. Baking the config in
+ # avoids bind-mount races where the new conf doesn't get picked up on
+ # `docker compose up` without a forced recreate.
+ build:
+ context: ./nginx
volumes:
# Serves static test assets for deterministic, offline-safe E2E downloads.
- ./fixtures:/usr/share/nginx/html:ro
+ networks:
+ default:
+ # Second hostname that points at the same nginx. Used by IDPI
+ # same-tab pivot tests: the page navigates from `fixtures` (in the
+ # IDPI allowlist) to `pivot-target` (not in the allowlist) to
+ # simulate a cross-domain pivot while staying fully offline.
+ aliases:
+ - fixtures
+ - pivot-target
healthcheck:
- test: ["CMD-SHELL", "wget -q -O /dev/null http://localhost:80/"]
+ # Verify BOTH that nginx is up AND that the custom config is the one
+ # actually loaded. /get is a synthetic endpoint defined only in
+ # tests/e2e/nginx/default.conf — if it returns 200 we know the baked
+ # config is live; if it 404s the container stays unhealthy and the
+ # test runner refuses to start, which surfaces "stale image / config
+ # not loaded" failures up front instead of as opaque test errors.
+ test: ["CMD-SHELL", "wget -q -O /dev/null http://localhost:80/ && wget -q -O /dev/null http://localhost:80/get"]
interval: 2s
timeout: 5s
retries: 5
diff --git a/tests/e2e/fixtures/idpi-domain-pivot.html b/tests/e2e/fixtures/idpi-domain-pivot.html
index 4635a7b8..b80a5353 100644
--- a/tests/e2e/fixtures/idpi-domain-pivot.html
+++ b/tests/e2e/fixtures/idpi-domain-pivot.html
@@ -9,7 +9,12 @@
<p>This page starts on the fixtures origin, then pivots the tab to a blocked domain.</p>
<script>
setTimeout(function () {
- window.location.href = "https://example.com/";
+ // Pivots to a second hostname served by the same nginx container via
+ // a docker-compose network alias (see tests/e2e/docker-compose.yml).
+ // `pivot-target` is intentionally NOT in the IDPI allowedDomains list,
+ // so the policy fires, while the page still actually loads (unlike
+ // example.com which is unreachable from inside the e2e network).
+ window.location.href = "http://pivot-target/index.html";
}, 250);
</script>
</body>
diff --git a/tests/e2e/nginx/Dockerfile b/tests/e2e/nginx/Dockerfile
new file mode 100644
index 00000000..b0e5b45a
--- /dev/null
+++ b/tests/e2e/nginx/Dockerfile
@@ -0,0 +1,24 @@
+# Custom fixtures image: nginx + baked-in test config.
+#
+# We bake the nginx config into the image instead of bind-mounting it,
+# so the e2e suite is immune to "did docker actually pick up the new
+# volume" failure modes when iterating locally or in CI.
+#
+# Static fixture *content* (HTML/JS/etc.) is still bind-mounted at
+# /usr/share/nginx/html so it can be edited without rebuilding.
+FROM nginx:alpine
+
+# Replace the stock default site with our test-aware config that adds
+# httpbin-compatible /redirect/N, /redirect-to, and /get endpoints.
+COPY default.conf /etc/nginx/conf.d/default.conf
+
+# Build-time guarantees:
+# 1. config syntactically valid (catches typos)
+# 2. our new endpoints are actually present (catches "wrong file copied")
+# 3. no second default_server is hiding in the image elsewhere (catches
+# a stale image with leftover stock config taking precedence)
+RUN nginx -t \
+ && grep -q 'location = /redirect-to' /etc/nginx/conf.d/default.conf \
+ && grep -q 'location = /redirect-to-internal' /etc/nginx/conf.d/default.conf \
+ && grep -q 'location = /redirect/1' /etc/nginx/conf.d/default.conf \
+ && grep -q 'location = /get' /etc/nginx/conf.d/default.conf
diff --git a/tests/e2e/nginx/default.conf b/tests/e2e/nginx/default.conf
new file mode 100644
index 00000000..740d2815
--- /dev/null
+++ b/tests/e2e/nginx/default.conf
@@ -0,0 +1,49 @@
+server {
+ listen 80 default_server;
+ listen [::]:80 default_server;
+ server_name _;
+
+ root /usr/share/nginx/html;
+ index index.html;
+
+ # ── httpbin-compatible redirect chain ────────────────────────────
+ # Mimics https://httpbin.org/redirect/N → eventually /get.
+ # Used by e2e tests that exercise the navigate handler's
+ # redirect-following without depending on external internet.
+ location = /redirect/1 { return 302 /get; }
+ location = /redirect/2 { return 302 /redirect/1; }
+ location = /redirect/3 { return 302 /redirect/2; }
+ location = /redirect/4 { return 302 /redirect/3; }
+ location = /redirect/5 { return 302 /redirect/4; }
+
+ # httpbin-compatible /redirect-to?url=…: 302 to whatever the caller asks.
+ # NOTE: stock nginx returns $arg_url *raw*, without URL-decoding, so a
+ # caller passing url=http%3A%2F%2Fexample.com%2F gets a Location header
+ # with the encoded value, which most clients then re-resolve as a
+ # relative path. For percent-encoded targets use /redirect-to-internal
+ # below instead.
+ location = /redirect-to {
+ return 302 $arg_url;
+ }
+
+ # SSRF test target: always redirects to a private/internal IP. Used by
+ # files-basic / files-full "redirected internal target blocked" tests
+ # to verify the download handler blocks redirects to internal hosts
+ # without needing a parameterized target (which would require nginx
+ # to URL-decode query args, something stock nginx can't do).
+ location = /redirect-to-internal {
+ return 302 http://127.0.0.1:9999/health;
+ }
+
+ # httpbin-compatible /get: returns a JSON body whose .url field
+ # reflects the final landed URL (host included so tests can assert).
+ location = /get {
+ default_type application/json;
+ return 200 '{"url":"http://fixtures/get"}';
+ }
+
+ # Default: serve the static fixture files.
+ location / {
+ try_files $uri $uri/ =404;
+ }
+}
diff --git a/tests/e2e/scenarios-api/browser-full.sh b/tests/e2e/scenarios-api/browser-full.sh
index a21c1465..c5069db4 100644
--- a/tests/e2e/scenarios-api/browser-full.sh
+++ b/tests/e2e/scenarios-api/browser-full.sh
@@ -68,22 +68,22 @@ end_test
start_test "redirects: follow single redirect"
-pt_post /navigate -d '{"url":"https://httpbin.org/redirect/1"}'
+pt_post /navigate -d "{\"url\":\"${FIXTURES_URL}/redirect/1\"}"
assert_ok "single redirect followed"
pt_get /snapshot
-assert_json_contains "$RESULT" ".url" "httpbin.org/get" "final URL is /get (redirect successful)"
+assert_json_contains "$RESULT" ".url" "fixtures/get" "final URL is /get (redirect successful)"
end_test
# ─────────────────────────────────────────────────────────────────
start_test "redirects: follow multiple redirects"
-pt_post /navigate -d '{"url":"https://httpbin.org/redirect/5"}'
+pt_post /navigate -d "{\"url\":\"${FIXTURES_URL}/redirect/5\"}"
assert_ok "five redirects followed"
pt_get /snapshot
-assert_json_contains "$RESULT" ".url" "httpbin.org/get" "multiple redirects followed to destination"
+assert_json_contains "$RESULT" ".url" "fixtures/get" "multiple redirects followed to destination"
end_test
diff --git a/tests/e2e/scenarios-api/files-basic.sh b/tests/e2e/scenarios-api/files-basic.sh
index cf5d120c..e8981ae0 100644
--- a/tests/e2e/scenarios-api/files-basic.sh
+++ b/tests/e2e/scenarios-api/files-basic.sh
@@ -99,12 +99,14 @@ end_test
# In Docker, fixtures resolves to internal IP, so we test with public URLs.
build_download_redirect_url() {
- local target_url="$1"
- local encoded_target
- local attacker_url
-
- encoded_target=$(jq -rn --arg u "$target_url" '$u|@uri')
- attacker_url="https://httpbin.org/redirect-to?url=${encoded_target}"
+ # The target arg is intentionally ignored: the SSRF test only needs *some*
+ # redirect to *some* private/internal target. The fixtures nginx exposes a
+ # dedicated /redirect-to-internal endpoint with the target hardcoded to
+ # http://127.0.0.1:9999/health, which sidesteps stock nginx's inability to
+ # URL-decode query args (and the resulting Location-header relative-path
+ # bug that breaks parameterized /redirect-to?url= for encoded targets).
+ local _ignored_target="$1"
+ local attacker_url="${FIXTURES_URL}/redirect-to-internal"
jq -rn --arg u "$attacker_url" '$u|@uri'
}
diff --git a/tests/e2e/scenarios-api/files-full.sh b/tests/e2e/scenarios-api/files-full.sh
index 693f20ac..a5c2268b 100644
--- a/tests/e2e/scenarios-api/files-full.sh
+++ b/tests/e2e/scenarios-api/files-full.sh
@@ -162,12 +162,14 @@ end_test
# - redirected internal targets rejected during browser-side navigation
build_download_redirect_url() {
- local target_url="$1"
- local encoded_target
- local attacker_url
-
- encoded_target=$(jq -rn --arg u "$target_url" '$u|@uri')
- attacker_url="https://httpbin.org/redirect-to?url=${encoded_target}"
+ # The target arg is intentionally ignored: the SSRF test only needs *some*
+ # redirect to *some* private/internal target. The fixtures nginx exposes a
+ # dedicated /redirect-to-internal endpoint with the target hardcoded to
+ # http://127.0.0.1:9999/health, which sidesteps stock nginx's inability to
+ # URL-decode query args (and the resulting Location-header relative-path
+ # bug that breaks parameterized /redirect-to?url= for encoded targets).
+ local _ignored_target="$1"
+ local attacker_url="${FIXTURES_URL}/redirect-to-internal"
jq -rn --arg u "$attacker_url" '$u|@uri'
}
diff --git a/tests/e2e/scenarios-api/system-full.sh b/tests/e2e/scenarios-api/system-full.sh
index 1459da45..3c8637cc 100644
--- a/tests/e2e/scenarios-api/system-full.sh
+++ b/tests/e2e/scenarios-api/system-full.sh
@@ -294,7 +294,7 @@ sleep 2
idpi_request GET "$E2E_SERVER" "/tabs/${TAB_ID}/text" "" "X-IDPI-Warning"
assert_ok "text allowed after domain pivot in warn mode"
assert_header_present "X-IDPI-Warning present after domain pivot"
-assert_json_contains "$RESULT" ".url" "example.com" "warn mode response reflects pivoted URL"
+assert_json_contains "$RESULT" ".url" "pivot-target" "warn mode response reflects pivoted URL"
idpi_cleanup "$E2E_SERVER" "$TAB_ID"
end_test
diff --git a/tests/e2e/scenarios-api/tabs-full.sh b/tests/e2e/scenarios-api/tabs-full.sh
index 00616ce5..c3a53678 100644
--- a/tests/e2e/scenarios-api/tabs-full.sh
+++ b/tests/e2e/scenarios-api/tabs-full.sh
@@ -56,11 +56,11 @@ end_test
# ─────────────────────────────────────────────────────────────────
start_test "tab-specific download: GET /tabs/{id}/download"
-pt_post /navigate -d '{"url":"https://httpbin.org/robots.txt"}'
+pt_post /navigate -d "{\"url\":\"${FIXTURES_URL}/index.html\"}"
TAB_ID2=$(get_tab_id)
show_tab "created" "$TAB_ID2"
-pt_get "/tabs/${TAB_ID2}/download?url=https://httpbin.org/json"
+pt_get "/tabs/${TAB_ID2}/download?url=${FIXTURES_URL}/sample.txt"
assert_ok "download from tab"
end_test
@@ -86,20 +86,20 @@ end_test
# ─────────────────────────────────────────────────────────────────
start_test "tab-specific download: locked tab rejects wrong owner"
-pt_post /navigate -d '{"url":"https://httpbin.org/robots.txt"}'
+pt_post /navigate -d "{\"url\":\"${FIXTURES_URL}/index.html\"}"
LOCKED_DOWNLOAD_TAB_ID=$(get_tab_id)
show_tab "created" "$LOCKED_DOWNLOAD_TAB_ID"
pt_post "/tabs/${LOCKED_DOWNLOAD_TAB_ID}/lock" -d '{"owner":"agent-a"}'
assert_ok "lock download tab"
-pinchtab GET "/tabs/${LOCKED_DOWNLOAD_TAB_ID}/download?url=https://httpbin.org/json" \
+pinchtab GET "/tabs/${LOCKED_DOWNLOAD_TAB_ID}/download?url=${FIXTURES_URL}/sample.txt" \
-H "X-Owner: intruder"
_echo_truncated
assert_http_status 423 "wrong owner blocked on download"
assert_contains "$RESULT" "tab_locked" "locked tab error returned for download"
-pinchtab GET "/tabs/${LOCKED_DOWNLOAD_TAB_ID}/download?url=https://httpbin.org/json" \
+pinchtab GET "/tabs/${LOCKED_DOWNLOAD_TAB_ID}/download?url=${FIXTURES_URL}/sample.txt" \
-H "X-Owner: agent-a"
_echo_truncated
assert_ok "correct owner can download from locked tab"
diff --git a/tests/e2e/scenarios-cli/browser-full.sh b/tests/e2e/scenarios-cli/browser-full.sh
index 3dda8385..f314e356 100644
--- a/tests/e2e/scenarios-cli/browser-full.sh
+++ b/tests/e2e/scenarios-cli/browser-full.sh
@@ -112,18 +112,18 @@ end_test
# ─────────────────────────────────────────────────────────────────
start_test "redirects: follow single redirect"
-pt_ok nav "https://httpbin.org/redirect/1"
+pt_ok nav "${FIXTURES_URL}/redirect/1"
pt_ok snap
-assert_json_field_contains ".url" "httpbin.org/get" "landed on /get after redirect"
+assert_json_field_contains ".url" "fixtures/get" "landed on /get after redirect"
end_test
# ─────────────────────────────────────────────────────────────────
start_test "redirects: follow multiple redirects"
-pt_ok nav "https://httpbin.org/redirect/3"
+pt_ok nav "${FIXTURES_URL}/redirect/3"
pt_ok snap
-assert_json_field_contains ".url" "httpbin.org/get" "multiple redirects followed to /get"
+assert_json_field_contains ".url" "fixtures/get" "multiple redirects followed to /get"
end_test