High-performance browser automation bridge and multi-instance orchestrator with advanced stealth injection and real-time dashboard.
fix: capability refusal metadata has a second owner in the shorthand front, which is the mechanism that made one route answer two disabled codes, and its fallback invents config keys (PIN-237)
Luigi Agostid6e1a14c30ac
diff --git a/internal/strategy/capability_meta_owner_test.go b/internal/strategy/capability_meta_owner_test.gonew file mode 100644index 00000000..670f9da3--- /dev/null+++ b/internal/strategy/capability_meta_owner_test.go@@ -0,0 +1,51 @@+package strategy++import (+ "strings"+ "testing"++ "github.com/pinchtab/pinchtab/internal/routes"+)++// The same route answering two different disabled codes depending on which front a client+// reached is what a second copy of this table produced. Both fronts gate from+// CapabilityEndpoints, so every capability it yields must resolve here to exactly what+// routes.Meta says — no restated labels, no synthesised settings.+func TestEveryGatedCapabilityResolvesToTheOneOwner(t *testing.T) {+ gated := routes.CapabilityEndpoints()+ if len(gated) == 0 {+ t.Fatal("no capability-gated endpoints found; this census would pass vacuously")+ }++ for cap := range gated {+ meta, ok := routes.Meta(cap)+ if !ok {+ t.Errorf("capability %q gates routes but routes.Meta does not describe it, so this front has nothing to answer with", cap)+ continue+ }++ feature, setting, code := capabilitySetting(cap)+ if feature != meta.Label || setting != meta.Setting || code != meta.DisabledCode {+ t.Errorf("capability %q resolves to (%q, %q, %q) but routes.Meta says (%q, %q, %q); a front that disagrees makes one capability answer two ways",+ cap, feature, setting, code, meta.Label, meta.Setting, meta.DisabledCode)+ }+ }+}++// The old fallback synthesised "security.allow"+cap and cap+"_disabled". That is wrong for+// any camelCase capability — which is why every one of them carried an explicit case — so a+// capability added to the catalogue and NOT to routes.Meta must fail loudly rather than be+// gated with a plausible-looking setting no config file has.+func TestAnUndescribedCapabilityDoesNotGetASynthesisedSetting(t *testing.T) {+ feature, setting, code := capabilitySetting(routes.Capability("stateExport-but-undescribed"))++ if setting != "" || code != "" {+ t.Errorf("an undescribed capability produced setting %q and code %q; a synthesised value reads as configuration that exists", setting, code)+ }+ if feature == "" {+ t.Error("the label should still name the capability, so a refusal is not anonymous")+ }+ if strings.Contains(setting, "security.allow") {+ t.Errorf("setting %q looks like a real config path but was invented here", setting)+ }+}diff --git a/internal/strategy/routes.go b/internal/strategy/routes.goindex 6e8d1074..5d1240ca 100644--- a/internal/strategy/routes.go+++ b/internal/strategy/routes.go@@ -7,28 +7,20 @@ import ("github.com/pinchtab/pinchtab/internal/routes")-// capabilitySetting returns the config key and disabled code for a capability.+// capabilitySetting returns the label, config key and disabled code a refused route+// answers with, from routes.Meta — the one owner. This front previously restated the whole+// table, which is how the same route came to answer two different codes depending on which+// front a client reached; the handler layer reads Meta, so this must too.+//+// The fallback only covers a capability the catalogue gates without describing, which+// CapabilityEndpoints cannot currently produce. It is deliberately not the old synthesis:+// that derived "security.allow"+cap and cap+"_disabled", which is wrong for every+// camelCase capability — the reason each one needed an explicit case in the first place.func capabilitySetting(cap routes.Capability) (feature, setting, code string) {- switch cap {- case routes.CapEvaluate:- return "evaluate", "security.allowEvaluate", "evaluate_disabled"- case routes.CapMacro:- return "macro", "security.allowMacro", "macro_disabled"- case routes.CapScreencast:- return "screencast", "security.allowScreencast", "screencast_disabled"- case routes.CapDownload:- return "download", "security.allowDownload", "download_disabled"- case routes.CapCookies:- return "cookies", "security.allowCookies", "cookies_disabled"- case routes.CapUpload:- return "upload", "security.allowUpload", "upload_disabled"- case routes.CapStateExport:- return "stateExport", "security.allowStateExport", "state_export_disabled"- case routes.CapNetworkIntercept:- return "networkIntercept", "security.allowNetworkIntercept", "network_intercept_disabled"- default:- return string(cap), "security.allow" + string(cap), string(cap) + "_disabled"+ if meta, ok := routes.Meta(cap); ok {+ return meta.Label, meta.Setting, meta.DisabledCode}+ return string(cap), "", ""}// RegisterShorthandRoutes registers all shorthand proxy routes on the mux,