High-performance browser automation bridge and multi-instance orchestrator with advanced stealth injection and real-time dashboard.
fix: an empty allowlist is read as every host explicitly allowed, disabling the private-IP SSRF block when IDPI is on (PIN-285)
Luigi Agosti0306b7d55bf3
diff --git a/docs/guides/security.md b/docs/guides/security.mdindex 6692fa09..60ddac50 100644--- a/docs/guides/security.md+++ b/docs/guides/security.md@@ -297,7 +297,15 @@ The default local-only IDPI config is:Important notes:-- if `allowedDomains` is empty, the main domain restriction is not doing useful work+- an empty `allowedDomains` **lifts the domain restriction and grants nothing**. It is+ not an allowance: no host counts as explicitly allowed, so the SSRF/private-IP guard+ keeps refusing private and internal addresses exactly as it does with IDPI off.+ (Enabling IDPI with an empty list used to *remove* that protection, because "the+ scanner found nothing suspicious" was read as "the operator allowed this host".)+- listing a private or internal host explicitly — `["10.0.0.5"]`, or the default+ `["127.0.0.1", "localhost", "::1"]` — is what permits navigation to it. That is the+ only way the private-IP guard is relaxed, and it is a positive match against a+ non-empty list, never the absence of one.- if `allowedDomains` contains `"*"`, the whitelist effectively allows everything- `security.allowedDomains` is the canonical config path. `security.idpi.allowedDomains` is still accepted when loading older config files, but new saves are normalized to `security.allowedDomains`- `strictMode = true` blocks disallowed domains and suspicious contentdiff --git a/internal/handlers/navigation_host_forms_test.go b/internal/handlers/navigation_host_forms_test.goindex 4354f928..d050a029 100644--- a/internal/handlers/navigation_host_forms_test.go+++ b/internal/handlers/navigation_host_forms_test.go@@ -98,16 +98,14 @@ func TestAnUnlistedSingleLabelHostIsRefusedNamingTheAllowlist(t *testing.T) {// landing on one and not the other leaves the bypass reachable. They are driven// against the same table here rather than trusted to share it.//-// IDPI is OFF in this fixture, and deliberately: with IDPI enabled and NO allowlist-// configured, ShieldGuard.DomainAllowed answers true for every URL (nothing scored,-// so nothing blocked), that becomes allowExplicitInternal, and the private-IP block-// is overridden before the spelling ever matters. That is a separate defect, recorded-// on the card; turning IDPI off here is what lets this test measure the spelling-// property it is about rather than that one.+// It runs with IDPI ENABLED and an empty allowlist — the configuration in which this+// used to be unable to see anything, because an empty allowlist made+// ShieldGuard.DomainAllowed answer true for every URL and the private-IP block was+// overridden before the spelling could matter. Disabling IDPI here was a fixture+// configured into the safe corner, which reads as coverage while proving nothing; it+// is enabled now, and that is part of what proves the empty-allowlist fix landed.func TestBothNavigatePathsRefuseEverySpellingOfAPrivateHost(t *testing.T) {- cfg := hostFormConfig(nil)- cfg.IDPI = config.IDPIConfig{}- h := New(&policyMockBridge{}, cfg, nil, nil, nil)+ h := New(&policyMockBridge{}, hostFormConfig(nil), nil, nil, nil)for _, raw := range []string{`https://10.0.0.5/x`,@@ -131,3 +129,52 @@ func TestBothNavigatePathsRefuseEverySpellingOfAPrivateHost(t *testing.T) {})}}++// The five rows the card measured, on BOTH paths that feed this boolean into+// navguard's allowExplicitInternal. The shape of the defect: enabling IDPI with an+// empty allowlist REMOVED a protection that is present with IDPI off, because+// "the shield found nothing suspicious" was read as "the operator allowed this host".+//+// The last row is the override working as intended and must keep working — a fix that+// also refuses an explicitly listed internal host has over-corrected.+func TestAnEmptyAllowlistNeverGrantsThePrivateIPOverride(t *testing.T) {+ const privateTarget = "https://10.0.0.5/x"++ for _, tc := range []struct {+ name string+ idpi bool+ allowed []string+ allow bool+ }{+ {"idpi on, empty allowlist", true, nil, false},+ {"idpi on, unrelated host listed", true, []string{"example.com"}, false},+ {"idpi off, empty allowlist", false, nil, false},+ {"idpi off, unrelated host listed", false, []string{"example.com"}, false},+ {"idpi on, the internal host explicitly listed", true, []string{"10.0.0.5"}, true},+ } {+ t.Run(tc.name, func(t *testing.T) {+ cfg := hostFormConfig(tc.allowed)+ if !tc.idpi {+ cfg.IDPI = config.IDPIConfig{}+ }+ h := New(&policyMockBridge{}, cfg, nil, nil, nil)++ if got := h.IDPIGuard.DomainAllowed(privateTarget); got != tc.allow {+ t.Errorf("DomainAllowed = %v, want %v — this boolean is allowExplicitInternal, so it must mean 'the operator allowed this host', never 'nothing looked wrong'", got, tc.allow)+ }++ w := httptest.NewRecorder()+ _, navigateOK := h.validateNavigateTargets(w, httptest.NewRequest("GET", "/navigate", nil), "", privateTarget, h.Config)+ if navigateOK != tc.allow {+ t.Errorf("navigate path allowed=%v, want %v: %d %s", navigateOK, tc.allow, w.Code, w.Body.String())+ }++ // The audit-page path consumes the same boolean, so a fix landing on one+ // leaves the other exposed.+ _, auditErr := h.validateAuditTarget(privateTarget, h.Config)+ if auditOK := auditErr == nil; auditOK != tc.allow {+ t.Errorf("audit-page path allowed=%v, want %v (err=%v)", auditOK, tc.allow, auditErr)+ }+ })+ }+}diff --git a/internal/idpi/domain_allowed_owner_test.go b/internal/idpi/domain_allowed_owner_test.gonew file mode 100644index 00000000..7b598ce8--- /dev/null+++ b/internal/idpi/domain_allowed_owner_test.go@@ -0,0 +1,114 @@+package idpi++import (+ "testing"++ "github.com/pinchtab/pinchtab/internal/config"+ "github.com/pinchtab/pinchtab/internal/security"+ "github.com/pinchtab/pinchtab/internal/srccensus"+)++// Every implementation behind Guard.DomainAllowed must answer the same question, and+// the answer that matters is what an EMPTY allowlist means. ShieldGuard used to say+// "allowed" for every URL under an empty list, while the free function and noopGuard+// said "not explicitly allowed" — two answers to one question, and the consumers feed+// it straight into navguard's private-IP override.+func TestEveryDomainAllowedImplementationAgreesOnAnEmptyAllowlist(t *testing.T) {+ const target = "https://10.0.0.5/x"+ enabled := config.IDPIConfig{Enabled: true, StrictMode: true}++ guards := map[string]Guard{+ "noop": noopGuard{},+ "shield": NewShieldGuard(enabled, nil),+ }+ for name, guard := range guards {+ if guard.DomainAllowed(target) {+ t.Errorf("%s.DomainAllowed = true under an empty allowlist; this boolean is allowExplicitInternal, and an absent list is no restriction, never an explicit allowance", name)+ }+ }+ if DomainAllowed(target, enabled, nil) {+ t.Error("the free DomainAllowed granted an explicit allowance from an empty list")+ }++ // The override the fix must preserve: a positive match against a NON-empty list+ // still grants it, or the correction has removed the capability instead of the bug.+ if !NewShieldGuard(enabled, []string{"10.0.0.5"}).DomainAllowed(target) {+ t.Error("an explicitly listed internal host no longer grants the override; the fix has over-corrected")+ }+}++// security.HostAllowed answers a DIFFERENT question — "is this host permitted by the+// allowlist" — where an empty list imposes no restriction and the answer is true. It is+// asserted here, in the package whose fix could most easily have been swept into it,+// because a change that "made them consistent" would break the allowlist itself.+func TestTheAllowlistPredicateKeepsItsOwnEmptyListMeaning(t *testing.T) {+ if !security.HostAllowed("https://10.0.0.5/x", nil) {+ t.Error("security.HostAllowed refuses under an empty allowlist; an empty list imposes no restriction, and refusing here would block every navigation")+ }+ if security.HostAllowed("https://evil.com/x", []string{"example.com"}) {+ t.Error("security.HostAllowed permitted an unlisted host")+ }+}++// One owner, pinned by measurement rather than by reading: for every combination of+// config, allowlist and target, the guard's method and the free function give the same+// answer. A re-divergence reds here however it is written.+func TestTheGuardAndTheFreeFunctionAgreeOnEveryCombination(t *testing.T) {+ configs := map[string]config.IDPIConfig{+ "enabled strict": {Enabled: true, StrictMode: true},+ "enabled": {Enabled: true},+ "disabled": {},+ }+ allowlists := map[string][]string{+ "empty": nil,+ "unrelated": {"example.com"},+ "the target host": {"10.0.0.5"},+ "wildcard": {"*"},+ "wildcard subdomain": {"*.corp.example.com"},+ }+ targets := []string{+ "https://10.0.0.5/x",+ "https://example.com/x",+ "https://api.corp.example.com/x",+ "//10.0.0.5/x",+ "about:blank",+ "",+ }++ compared := 0+ for cfgName, cfg := range configs {+ for listName, allowed := range allowlists {+ guard := NewShieldGuard(cfg, allowed)+ for _, target := range targets {+ compared+++ if got, want := guard.DomainAllowed(target), DomainAllowed(target, cfg, allowed); got != want {+ t.Errorf("cfg=%s allowlist=%s target=%q: guard says %v, the owner says %v — two answers to one question is the defect, not a detail of it",+ cfgName, listName, target, got, want)+ }+ }+ }+ }+ if compared < len(configs)*len(allowlists)*len(targets) {+ t.Fatalf("compared %d combinations; the matrix is not being walked", compared)+ }+}++// The specific re-divergence to keep out: answering the explicit-allowance question+// from the shield's own threat scan. Every CheckDomain call inside this package must+// sit in a function named CheckDomain — the one that asks that question — so a+// DomainAllowed method reaching for the scan again reds by file and line.+//+// The census matches the bare name because that is the spelling the AST produces for a+// call through a field receiver (g.shield.CheckDomain): the callee's X is itself a+// selector, so the receiver does not survive into the callee name. Calls(t, ...) fails+// on zero matches, which is the floor — a rename cannot silently disarm this.+func TestTheShieldScanIsCalledOnlyWhereItAnswersItsOwnQuestion(t *testing.T) {+ pkg := srccensus.Load(t, ".", 5)++ for _, site := range pkg.Calls(t, "CheckDomain") {+ if site.Func != "CheckDomain" {+ t.Errorf("%s calls the domain scan from %s; answering any question but 'is there anything wrong with this host' from a threat score is how 'nothing looked wrong' came to mean 'the operator allowed this'",+ site, site.Func)+ }+ }+}diff --git a/internal/idpi/guard_shield.go b/internal/idpi/guard_shield.goindex dc4438f5..d83ba84b 100644--- a/internal/idpi/guard_shield.go+++ b/internal/idpi/guard_shield.go@@ -101,9 +101,20 @@ func (g *ShieldGuard) CheckDomain(rawURL string) CheckResult {}}+// DomainAllowed delegates to the free function so ONE implementation answers this+// question. It used to answer `shield.CheckDomain(rawURL).Score == 0` — "the shield+// found nothing suspicious" — where every caller asks "did the operator explicitly+// allow this host". An empty allowlist makes the first true for every URL, so absence+// of suspicion was read as presence of permission: both consumers feed this straight+// into navguard's allowExplicitInternal, which overrides the private-IP block, and+// enabling IDPI with an empty allowlist therefore REMOVED a protection that is present+// with IDPI off.+//+// The interface this satisfies already documents the right answer ("returns false when+// the allowlist is empty"), and noopGuard and the free function both give it. This was+// the outlier.func (g *ShieldGuard) DomainAllowed(rawURL string) bool {- result := g.shield.CheckDomain(rawURL)- return result.Score == 0+ return DomainAllowed(rawURL, g.cfg, g.allowedDomains)}func (g *ShieldGuard) WrapContent(text, pageURL string) string {