Skip to content

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

fix: a misspelled or miscased /action query parameter is still silently dropped, so ?modifers=8 dispatches a plain click and answers 200 (PIN-263)

Luigi Agosti6e936529ffc7
diff --git a/docs/endpoints.md b/docs/endpoints.md
index a872429c..b7d2e099 100644
--- a/docs/endpoints.md
+++ b/docs/endpoints.md
@@ -163,7 +163,7 @@ POST /tabs/{id}/evaluate
`/evaluate` is intentionally separate from selector frame scope. `GET/POST /frame` only affects selector-based `/snapshot` and `/action` calls, not arbitrary JavaScript evaluation.
-`GET /action` decodes a subset of the action fields and refuses, with `400` naming the field, any parameter it cannot express rather than silently dropping it — so a modifier chord, a drag, `waitNav` or `humanize` must be sent as `POST /action` with a JSON body.
+`GET /action` decodes a subset of the action fields and refuses, with `400` naming the field, any parameter it cannot express rather than silently dropping it — so a modifier chord, a drag, `waitNav` or `humanize` must be sent as `POST /action` with a JSON body. A parameter the action request does not declare at all is refused the same way, with a `did you mean` hint for a near miss, so `?modifers=8` or `?Modifiers=8` no longer dispatches a plain click and answers `200`. The accepted set is exactly the action request's own fields: cache-busters and stray parameters must be dropped from the URL.
`GET /visible` (and `pinchtab visible <ref>`) answers CSS rendered-ness — `display`, `visibility`, `opacity`, and a laid-out box with non-zero size. Scroll position is not an input: an element far below the fold, or scrolled past, still reports `visible: true`. On-screen-ness is the response's `onScreen` field, which shares the capture snapshot's viewport-intersection predicate (see [reference/capture.md](reference/capture.md)); `onScreen` is omitted when the element could not be measured — absent means unknown, never "no".
diff --git a/internal/handlers/actions.go b/internal/handlers/actions.go
index 09d7b6e3..dc2acd53 100644
--- a/internal/handlers/actions.go
+++ b/internal/handlers/actions.go
@@ -7,6 +7,7 @@ import (
"fmt"
"net/http"
"net/url"
+ "reflect"
"sort"
"strconv"
"strings"
@@ -225,6 +226,91 @@ func unsupportedQueryFields(q url.Values) []string {
return offenders
}
+// actionQueryKeys is the complete set of meaningful /action query parameters, derived from
+// the request type rather than listed by hand: a field added to bridge.ActionRequest is
+// accepted with no edit here, and anything else is a typo or a stray parameter the GET form
+// would drop without a word.
+var actionQueryKeys = actionRequestJSONKeys()
+
+func actionRequestJSONKeys() map[string]struct{} {
+ keys := make(map[string]struct{})
+ for _, field := range reflect.VisibleFields(reflect.TypeOf(bridge.ActionRequest{})) {
+ name, _, _ := strings.Cut(field.Tag.Get("json"), ",")
+ if name != "" && name != "-" {
+ keys[name] = struct{}{}
+ }
+ }
+ return keys
+}
+
+// unknownQueryFields names every supplied parameter the request type does not declare, sorted
+// so the refusal reads the same on every run. Presence follows the decoder's own rule — a
+// non-empty value — so ?_= is absent rather than an unknown request.
+func unknownQueryFields(q url.Values) []string {
+ var unknown []string
+ for key := range q {
+ if _, known := actionQueryKeys[key]; known {
+ continue
+ }
+ if strings.TrimSpace(q.Get(key)) == "" {
+ continue
+ }
+ unknown = append(unknown, key)
+ }
+ sort.Strings(unknown)
+ return unknown
+}
+
+func unknownQueryFieldsError(unknown []string) error {
+ named := make([]string, 0, len(unknown))
+ for _, key := range unknown {
+ if near := nearestActionQueryKey(key); near != "" {
+ named = append(named, fmt.Sprintf("%s (did you mean %s?)", key, near))
+ continue
+ }
+ named = append(named, key)
+ }
+ return fmt.Errorf("%s: not a parameter of /action and would be silently dropped; check the spelling or send the request as POST /action with a JSON body", strings.Join(named, ", "))
+}
+
+func nearestActionQueryKey(key string) string {
+ if len(key) < 4 {
+ return ""
+ }
+ best := ""
+ bestDistance := 0
+ for candidate := range actionQueryKeys {
+ distance := editDistance(strings.ToLower(key), strings.ToLower(candidate))
+ if best == "" || distance < bestDistance || (distance == bestDistance && candidate < best) {
+ best, bestDistance = candidate, distance
+ }
+ }
+ if bestDistance > 2 {
+ return ""
+ }
+ return best
+}
+
+func editDistance(a, b string) int {
+ previous := make([]int, len(b)+1)
+ current := make([]int, len(b)+1)
+ for j := range previous {
+ previous[j] = j
+ }
+ for i := 1; i <= len(a); i++ {
+ current[0] = i
+ for j := 1; j <= len(b); j++ {
+ cost := 1
+ if a[i-1] == b[j-1] {
+ cost = 0
+ }
+ current[j] = min(previous[j]+1, min(current[j-1]+1, previous[j-1]+cost))
+ }
+ previous, current = current, previous
+ }
+ return previous[len(b)]
+}
+
func decodeActionRequest(w http.ResponseWriter, r *http.Request) (bridge.ActionRequest, bool) {
var req bridge.ActionRequest
if r.Method == http.MethodGet {
@@ -233,6 +319,10 @@ func decodeActionRequest(w http.ResponseWriter, r *http.Request) (bridge.ActionR
httpx.Error(w, 400, fmt.Errorf("%s cannot be sent as query parameters and would be silently dropped; send this as POST /action with a JSON body", strings.Join(offenders, ", ")))
return bridge.ActionRequest{}, false
}
+ if unknown := unknownQueryFields(q); len(unknown) > 0 {
+ httpx.Error(w, 400, unknownQueryFieldsError(unknown))
+ return bridge.ActionRequest{}, false
+ }
d := newQueryDecoder(q)
req.Kind = bridge.CanonicalActionKind(q.Get("kind"))
req.TabID = q.Get("tabId")
diff --git a/internal/handlers/actions_test.go b/internal/handlers/actions_test.go
index cd6b9f5e..c54fc4e0 100644
--- a/internal/handlers/actions_test.go
+++ b/internal/handlers/actions_test.go
@@ -7,6 +7,7 @@ import (
"fmt"
"net/http"
"net/http/httptest"
+ "net/url"
"reflect"
"strings"
"testing"
@@ -919,6 +920,118 @@ func TestActionQueryRefusalNamesEveryOffenderInAStableOrder(t *testing.T) {
}
}
+// MEASURED: the undecoded-field refusal is a deny-list, so it closed the class for a
+// correctly spelled parameter and left it open one typo over — ?modifers=8 and ?Modifiers=8
+// both answered 200 and dispatched a plain click. Same harm, same 200.
+func TestActionQueryRefusesAMisspelledOrMiscasedParameter(t *testing.T) {
+ for _, tc := range []struct {
+ name string
+ key string
+ wantHint string
+ }{
+ {name: "a dropped letter", key: "modifers", wantHint: "modifiers"},
+ {name: "the wrong case", key: "Modifiers", wantHint: "modifiers"},
+ {name: "the wrong case on a decoded field", key: "TabId", wantHint: "tabId"},
+ {name: "a parameter of no endpoint", key: "cachebuster"},
+ } {
+ t.Run(tc.name, func(t *testing.T) {
+ rec := httptest.NewRecorder()
+ _, ok := decodeActionRequest(rec, httptest.NewRequest(http.MethodGet, "/action?kind=click&"+tc.key+"=8", nil))
+
+ if ok {
+ t.Fatalf("the query form accepted %q, which it reads nowhere — the caller's parameter is dropped and the wrong action is reported as success", tc.key)
+ }
+ if rec.Code != http.StatusBadRequest {
+ t.Errorf("status = %d, want %d", rec.Code, http.StatusBadRequest)
+ }
+ body := rec.Body.String()
+ if !strings.Contains(body, tc.key) {
+ t.Errorf("the refusal does not name the parameter the caller must fix: %s", body)
+ }
+ if tc.wantHint == "" {
+ if strings.Contains(body, "did you mean") {
+ t.Errorf("%q resembles no parameter, so a hint is a guess: %s", tc.key, body)
+ }
+ return
+ }
+ if !strings.Contains(body, "did you mean "+tc.wantHint+"?") {
+ t.Errorf("the refusal does not point at %q, so the caller has to find the spelling itself: %s", tc.wantHint, body)
+ }
+ })
+ }
+}
+
+// The allow-list is DERIVED from the request type, not a second list beside the decoder: every
+// key ActionRequest declares is meaningful, so a new field is accepted with no edit to the
+// refusal. Recorded-undecodable keys keep their own refusal, which says where they do work.
+func TestActionQueryAcceptsEveryFieldTheRequestTypeDeclares(t *testing.T) {
+ checked := 0
+ for _, field := range reflect.VisibleFields(reflect.TypeOf(bridge.ActionRequest{})) {
+ key, _, _ := strings.Cut(field.Tag.Get("json"), ",")
+ if key == "" || key == "-" {
+ continue
+ }
+ if unknown := unknownQueryFields(url.Values{key: []string{"1"}}); len(unknown) > 0 {
+ t.Errorf("%q is declared by ActionRequest and the GET form calls it unknown; the allow-list is not derived from the type", key)
+ }
+ checked++
+ }
+ if checked == 0 {
+ t.Fatal("no field was checked; the guard is not reading the request type")
+ }
+ if unknown := unknownQueryFields(url.Values{"modifers": []string{"8"}}); len(unknown) != 1 {
+ t.Fatalf("a key the type does not declare was not called unknown: %v — the allow-list accepts everything", unknown)
+ }
+}
+
+// A correctly spelled undecodable field keeps the refusal that tells the caller to POST it.
+// The unknown-key refusal must not swallow that message, or the fix a caller is told to make
+// changes from "send this as POST" to "check the spelling".
+func TestARecordedFieldStillRefusesWithThePostRemedy(t *testing.T) {
+ rec := httptest.NewRecorder()
+ if _, ok := decodeActionRequest(rec, httptest.NewRequest(http.MethodGet, "/action?kind=click&modifiers=8", nil)); ok {
+ t.Fatal("modifiers=8 was accepted")
+ }
+ body := rec.Body.String()
+ if !strings.Contains(body, "cannot be sent as query parameters") {
+ t.Errorf("a recorded field got the unknown-key refusal instead of its own: %s", body)
+ }
+ if strings.Contains(body, "did you mean") {
+ t.Errorf("the field is spelled correctly, so a spelling hint misdirects the caller: %s", body)
+ }
+}
+
+// An empty value is absent, the rule every other presence check here follows, so a bare
+// ?_= does not refuse a request that supplied nothing.
+func TestActionQueryAcceptsAnEmptyUnknownParameter(t *testing.T) {
+ rec := httptest.NewRecorder()
+ if _, ok := decodeActionRequest(rec, httptest.NewRequest(http.MethodGet, "/action?kind=click&_=", nil)); !ok {
+ t.Fatalf("an empty unknown parameter refused, but no value was supplied to drop: %s", rec.Body.String())
+ }
+}
+
+func TestUnknownActionQueryRefusalNamesEveryOffenderInAStableOrder(t *testing.T) {
+ const query = "/action?kind=click&zebra=1&modifers=8&alpha=2"
+
+ first := ""
+ for range 20 {
+ rec := httptest.NewRecorder()
+ if _, ok := decodeActionRequest(rec, httptest.NewRequest(http.MethodGet, query, nil)); ok {
+ t.Fatal("three unknown parameters were accepted")
+ }
+ body := rec.Body.String()
+ if first == "" {
+ first = body
+ }
+ if body != first {
+ t.Fatalf("the refusal differs between runs; map iteration order is deciding the message:\n %s\n %s", first, body)
+ }
+ }
+ if !strings.Contains(first, "alpha, modifers (did you mean modifiers?), zebra") {
+ t.Errorf("the offenders are not named in a sorted order, so a caller fixes one and is refused again: %s", first)
+ }
+}
+
// The refusal is DERIVED from the record rather than parallel to it: a field added to the
// record refuses with no edit to the GET branch. Driven by adding one, since a reader cannot
// tell a derived rule from a coincidental one by looking at either.