Skip to content

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

fix: e2e test api with private ip validation

Mario51e474d765de
diff --git a/docs/endpoints.md b/docs/endpoints.md
index 3331bca6..fb34cee9 100644
--- a/docs/endpoints.md
+++ b/docs/endpoints.md
@@ -223,7 +223,7 @@ Notes:
- download and upload endpoints are gated by `security.allowDownload` and `security.allowUpload`
- download automatically decompresses `.gz` files and returns the decompressed content
-- `security.downloadAllowedDomains` can whitelist specific domains (bypasses SSRF checks for those domains)
+- `security.downloadAllowedDomains` can whitelist specific domains (bypasses SSRF checks for those domains). Setting `["*"]` matches every host and disables all private-IP protection on the download endpoint.
- clipboard endpoints are gated by `security.allowClipboard`
- upload uses a JSON body with `selector` and `files`
diff --git a/docs/guides/security.md b/docs/guides/security.md
index 159e85d8..3055537a 100644
--- a/docs/guides/security.md
+++ b/docs/guides/security.md
@@ -152,7 +152,7 @@ Why they are considered dangerous:
- `evaluate` can execute JavaScript in page context
- `macro` can trigger higher-level automation flows
- `screencast` can stream live page contents
-- `download` can fetch and persist remote content
+- `download` can fetch and persist remote content. When `security.downloadAllowedDomains` is set, listed domains bypass private-IP SSRF checks (intended for internal hosts such as Docker services). `["*"]` matches every host and disables all private-IP protection on the download endpoint.
- `upload` can push local files into browser flows
These are not the same as authentication.
diff --git a/internal/handlers/download.go b/internal/handlers/download.go
index acd15713..354f04ca 100644
--- a/internal/handlers/download.go
+++ b/internal/handlers/download.go
@@ -42,6 +42,21 @@ func newDownloadURLGuard(allowedDomains []string) *downloadURLGuard {
return &downloadURLGuard{allowedDomains: append([]string(nil), allowedDomains...)}
}
+// isDomainAllowed reports whether rawURL's domain is on the configured
+// allowlist. Allowlisted domains bypass private-IP checks because they
+// are explicitly trusted by the operator (e.g. internal docker hosts).
+func (g *downloadURLGuard) isDomainAllowed(rawURL string) bool {
+ if len(g.allowedDomains) == 0 {
+ return false
+ }
+ result := idpi.CheckDomain(rawURL, config.IDPIConfig{
+ Enabled: true,
+ AllowedDomains: append([]string(nil), g.allowedDomains...),
+ StrictMode: true,
+ })
+ return !result.Blocked
+}
+
func (g *downloadURLGuard) Validate(rawURL string) error {
parsed, err := url.Parse(rawURL)
if err != nil {
@@ -355,14 +370,16 @@ func (h *Handlers) HandleDownload(w http.ResponseWriter, r *http.Request) {
requestID = e.RequestID
responseMIME = e.Response.MimeType
responseStatus = int(e.Response.Status)
- if err := validateDownloadRemoteIPAddress(e.Response.RemoteIPAddress); err != nil {
- requestGuard.NoteBlocked(err)
- select {
- case done <- struct{}{}:
- default:
+ if !validator.isDomainAllowed(e.Response.URL) {
+ if err := validateDownloadRemoteIPAddress(e.Response.RemoteIPAddress); err != nil {
+ requestGuard.NoteBlocked(err)
+ select {
+ case done <- struct{}{}:
+ default:
+ }
+ tCancel()
+ return
}
- tCancel()
- return
}
if contentLength, ok := parseContentLengthHeader(e.Response.Headers); ok && contentLength > int64(maxDownloadBytes) {
requestGuard.NoteBlocked(downloadTooLargeError(contentLength, maxDownloadBytes))
diff --git a/tests/e2e/scenarios-api/files-basic.sh b/tests/e2e/scenarios-api/files-basic.sh
index 40d9bf43..cf5d120c 100644
--- a/tests/e2e/scenarios-api/files-basic.sh
+++ b/tests/e2e/scenarios-api/files-basic.sh
@@ -118,12 +118,12 @@ assert_ok "download public"
end_test
# ─────────────────────────────────────────────────────────────────
-start_test "pinchtab download (SSRF blocked)"
+start_test "pinchtab download (non-allowed domain blocked)"
-pt_get "/download?url=${FIXTURES_URL}/sample.txt"
+pt_get "/download?url=http://not-on-allowlist.local/sample.txt"
assert_http_status 400 "download blocked"
-assert_contains "$RESULT" "blocked\|private" "SSRF error message"
+assert_contains "$RESULT" "not allowed\|blocked" "domain rejection error message"
end_test
diff --git a/tests/e2e/scenarios-api/files-full.sh b/tests/e2e/scenarios-api/files-full.sh
index c4b55edc..693f20ac 100644
--- a/tests/e2e/scenarios-api/files-full.sh
+++ b/tests/e2e/scenarios-api/files-full.sh
@@ -171,11 +171,11 @@ build_download_redirect_url() {
jq -rn --arg u "$attacker_url" '$u|@uri'
}
-start_test "download security: direct internal target blocked"
+start_test "download security: non-allowed domain blocked"
-pt_get "/download?url=${FIXTURES_URL}/sample.txt"
-assert_http_status 400 "direct internal target blocked"
-assert_contains "$RESULT" "blocked\|private" "direct SSRF error message"
+pt_get "/download?url=http://not-on-allowlist.local/sample.txt"
+assert_http_status 400 "non-allowed domain blocked"
+assert_contains "$RESULT" "not allowed\|blocked" "domain rejection error message"
end_test
diff --git a/tests/e2e/scenarios-cli/files-basic.sh b/tests/e2e/scenarios-cli/files-basic.sh
index 9cd2152c..6051d469 100644
--- a/tests/e2e/scenarios-cli/files-basic.sh
+++ b/tests/e2e/scenarios-cli/files-basic.sh
@@ -31,9 +31,9 @@ fi
end_test
# ─────────────────────────────────────────────────────────────────
-start_test "pinchtab download (rejects private IP)"
+start_test "pinchtab download (rejects non-allowed domain)"
-pt_fail download "${FIXTURES_URL}/index.html"
+pt_fail download "http://not-on-allowlist.local/index.html"
end_test
diff --git a/tests/e2e/scenarios-cli/files-full.sh b/tests/e2e/scenarios-cli/files-full.sh
index 12142b49..ca14dedd 100644
--- a/tests/e2e/scenarios-cli/files-full.sh
+++ b/tests/e2e/scenarios-cli/files-full.sh
@@ -66,22 +66,15 @@ end_test
start_test "pinchtab download .gz file (gzip fallback)"
# fixtures domain allowlisted in e2e config for this test
-GZ_URL="${FIXTURES_URL:-http://fixtures:80}/sitemap.xml.gz"
+GZ_URL="${FIXTURES_URL}/sitemap.xml.gz"
pt_ok download "$GZ_URL" -o /tmp/e2e-download-gz.xml
+assert_file_exists /tmp/e2e-download-gz.xml ".gz download file created"
+
if [ -f /tmp/e2e-download-gz.xml ]; then
- if grep -q "example.com" /tmp/e2e-download-gz.xml; then
- echo -e " ${GREEN}✓${NC} .gz file downloaded and decompressed"
- ((ASSERTIONS_PASSED++)) || true
- else
- echo -e " ${RED}✗${NC} file downloaded but content not decompressed"
- cat /tmp/e2e-download-gz.xml | head -5
- ((ASSERTIONS_FAILED++)) || true
- fi
- rm -f /tmp/e2e-download-gz.xml
-else
- echo -e " ${RED}✗${NC} .gz download file not created"
- ((ASSERTIONS_FAILED++)) || true
+ PT_OUT=$(cat /tmp/e2e-download-gz.xml)
+ assert_output_contains "example.com" ".gz file decompressed correctly"
fi
+rm -f /tmp/e2e-download-gz.xml
end_test