Skip to content

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

feat: redact password fields in snapshots and deduplicate CDP auth listeners

Mario7dd7b7d31520
diff --git a/internal/bridge/observe/snapshot.go b/internal/bridge/observe/snapshot.go
index 0faa42a7..b8c9ff61 100644
--- a/internal/bridge/observe/snapshot.go
+++ b/internal/bridge/observe/snapshot.go
@@ -402,6 +402,12 @@ func BuildSnapshot(nodes []RawAXNode, filter string, maxDepth int) ([]A11yNode,
if prop.Name == "focused" && prop.Value.String() == "true" {
entry.Focused = true
}
+ if prop.Name == "autocomplete" {
+ v := strings.ToLower(prop.Value.String())
+ if v == "current-password" || v == "new-password" {
+ entry.Value = "••••••••"
+ }
+ }
}
// Tag nodes that are visually hidden but still present in the a11y tree
diff --git a/internal/bridge/snapshot_test.go b/internal/bridge/snapshot_test.go
index 2a570fac..1ffd6662 100644
--- a/internal/bridge/snapshot_test.go
+++ b/internal/bridge/snapshot_test.go
@@ -568,3 +568,68 @@ func TestBuildSnapshotInteractiveIncludesIframeOwnerAndChildActions(t *testing.T
t.Fatalf("unexpected interactive descendants: %+v", flat)
}
}
+
+func TestBuildSnapshotRedactsPasswordByAutocomplete(t *testing.T) {
+ nodes := []RawAXNode{
+ {
+ NodeID: "root",
+ Role: &RawAXValue{Value: json.RawMessage(`"WebArea"`)},
+ Name: &RawAXValue{Value: json.RawMessage(`"Login"`)},
+ ChildIDs: []string{"user", "pass"},
+ },
+ {
+ NodeID: "user",
+ Role: &RawAXValue{Value: json.RawMessage(`"textbox"`)},
+ Name: &RawAXValue{Value: json.RawMessage(`"Username"`)},
+ Value: &RawAXValue{Value: json.RawMessage(`"mario"`)},
+ BackendDOMNodeID: 10,
+ },
+ {
+ NodeID: "pass",
+ Role: &RawAXValue{Value: json.RawMessage(`"textbox"`)},
+ Name: &RawAXValue{Value: json.RawMessage(`"Password"`)},
+ Value: &RawAXValue{Value: json.RawMessage(`"supersecret"`)},
+ BackendDOMNodeID: 11,
+ Properties: []RawAXProp{
+ {Name: "autocomplete", Value: &RawAXValue{Value: json.RawMessage(`"current-password"`)}},
+ },
+ },
+ }
+
+ flat, _ := BuildSnapshot(nodes, "", -1)
+ if len(flat) != 3 {
+ t.Fatalf("expected 3 nodes, got %d", len(flat))
+ }
+ if flat[1].Value != "mario" {
+ t.Errorf("username value = %q, want mario", flat[1].Value)
+ }
+ if flat[2].Value != "••••••••" {
+ t.Errorf("password value = %q, want redacted", flat[2].Value)
+ }
+}
+
+func TestBuildSnapshotRedactsNewPassword(t *testing.T) {
+ nodes := []RawAXNode{
+ {
+ NodeID: "root",
+ Role: &RawAXValue{Value: json.RawMessage(`"WebArea"`)},
+ Name: &RawAXValue{Value: json.RawMessage(`"Signup"`)},
+ ChildIDs: []string{"pass"},
+ },
+ {
+ NodeID: "pass",
+ Role: &RawAXValue{Value: json.RawMessage(`"textbox"`)},
+ Name: &RawAXValue{Value: json.RawMessage(`"New password"`)},
+ Value: &RawAXValue{Value: json.RawMessage(`"hunter2"`)},
+ BackendDOMNodeID: 20,
+ Properties: []RawAXProp{
+ {Name: "autocomplete", Value: &RawAXValue{Value: json.RawMessage(`"new-password"`)}},
+ },
+ },
+ }
+
+ flat, _ := BuildSnapshot(nodes, "", -1)
+ if flat[1].Value != "••••••••" {
+ t.Errorf("new-password value = %q, want redacted", flat[1].Value)
+ }
+}
diff --git a/internal/handlers/credentials.go b/internal/handlers/credentials.go
index f7d824e3..b63c0afe 100644
--- a/internal/handlers/credentials.go
+++ b/internal/handlers/credentials.go
@@ -20,15 +20,19 @@ type credentialPair struct {
Password string
}
-// credentialStore provides thread-safe per-tab credential storage.
+// credentialStore provides thread-safe per-tab credential storage and tracks
+// which tabs already have a CDP event listener installed to avoid stacking
+// duplicate listeners on repeated calls.
type credentialStore struct {
mu sync.RWMutex
credentials map[string]*credentialPair
+ listeners map[string]bool
}
func newCredentialStore() *credentialStore {
return &credentialStore{
credentials: make(map[string]*credentialPair),
+ listeners: make(map[string]bool),
}
}
@@ -49,6 +53,19 @@ func (cs *credentialStore) Delete(tabID string) {
cs.mu.Lock()
defer cs.mu.Unlock()
delete(cs.credentials, tabID)
+ delete(cs.listeners, tabID)
+}
+
+func (cs *credentialStore) HasListener(tabID string) bool {
+ cs.mu.RLock()
+ defer cs.mu.RUnlock()
+ return cs.listeners[tabID]
+}
+
+func (cs *credentialStore) MarkListener(tabID string) {
+ cs.mu.Lock()
+ defer cs.mu.Unlock()
+ cs.listeners[tabID] = true
}
type credentialsRequest struct {
@@ -153,32 +170,35 @@ func (h *Handlers) setCredentials(w http.ResponseWriter, r *http.Request, req cr
return
}
- // Install event listener for auth challenges and paused requests.
- // Use the non-timeout tab context so the listener persists beyond this request.
- chromedp.ListenTarget(ctx, func(ev interface{}) {
- switch e := ev.(type) {
- case *fetch.EventAuthRequired:
- go func() {
- cred, ok := h.credentialStore.Get(resolvedTabID)
- if !ok {
- return
- }
- _ = chromedp.Run(ctx, chromedp.ActionFunc(func(innerCtx context.Context) error {
- return fetch.ContinueWithAuth(e.RequestID, &fetch.AuthChallengeResponse{
- Response: fetch.AuthChallengeResponseResponseProvideCredentials,
- Username: cred.Username,
- Password: cred.Password,
- }).Do(innerCtx)
- }))
- }()
- case *fetch.EventRequestPaused:
- go func() {
- _ = chromedp.Run(ctx, chromedp.ActionFunc(func(innerCtx context.Context) error {
- return fetch.ContinueRequest(e.RequestID).Do(innerCtx)
- }))
- }()
- }
- })
+ // Install event listener only once per tab. The listener reads credentials
+ // from the store dynamically, so updating creds doesn't need a new listener.
+ if !h.credentialStore.HasListener(resolvedTabID) {
+ h.credentialStore.MarkListener(resolvedTabID)
+ chromedp.ListenTarget(ctx, func(ev interface{}) {
+ switch e := ev.(type) {
+ case *fetch.EventAuthRequired:
+ go func() {
+ cred, ok := h.credentialStore.Get(resolvedTabID)
+ if !ok {
+ return
+ }
+ _ = chromedp.Run(ctx, chromedp.ActionFunc(func(innerCtx context.Context) error {
+ return fetch.ContinueWithAuth(e.RequestID, &fetch.AuthChallengeResponse{
+ Response: fetch.AuthChallengeResponseResponseProvideCredentials,
+ Username: cred.Username,
+ Password: cred.Password,
+ }).Do(innerCtx)
+ }))
+ }()
+ case *fetch.EventRequestPaused:
+ go func() {
+ _ = chromedp.Run(ctx, chromedp.ActionFunc(func(innerCtx context.Context) error {
+ return fetch.ContinueRequest(e.RequestID).Do(innerCtx)
+ }))
+ }()
+ }
+ })
+ }
h.recordActivity(r, activity.Update{Action: "emulation.credentials", TabID: resolvedTabID})
diff --git a/internal/handlers/credentials_test.go b/internal/handlers/credentials_test.go
index b3aa620d..dbeadaae 100644
--- a/internal/handlers/credentials_test.go
+++ b/internal/handlers/credentials_test.go
@@ -115,6 +115,36 @@ func TestHandleTabSetCredentials_NoTab(t *testing.T) {
}
}
+func TestCredentialStoreListenerDedup(t *testing.T) {
+ cs := newCredentialStore()
+
+ if cs.HasListener("tab1") {
+ t.Fatal("fresh store should have no listeners")
+ }
+
+ cs.MarkListener("tab1")
+ if !cs.HasListener("tab1") {
+ t.Fatal("expected listener after MarkListener")
+ }
+
+ // Mark again — should be idempotent.
+ cs.MarkListener("tab1")
+ if !cs.HasListener("tab1") {
+ t.Fatal("expected listener to persist after second MarkListener")
+ }
+
+ // Delete clears both credentials and listener tracking.
+ cs.Set("tab1", &credentialPair{Username: "u", Password: "p"})
+ cs.Delete("tab1")
+
+ if cs.HasListener("tab1") {
+ t.Fatal("Delete should clear listener tracking")
+ }
+ if _, ok := cs.Get("tab1"); ok {
+ t.Fatal("Delete should clear credentials")
+ }
+}
+
func TestHandleSetCredentials_EmptyPassword(t *testing.T) {
h := New(&mockBridge{}, &config.RuntimeConfig{}, nil, nil, nil)
diff --git a/skills/pinchtab-todo/SKILL.md b/skills/pinchtab-todo/SKILL.md
deleted file mode 100644
index 40fb3f18..00000000
--- a/skills/pinchtab-todo/SKILL.md
+++ /dev/null
@@ -1,142 +0,0 @@
----
-name: pinchtab-todo
-description: "Process the next task from the todo pipeline. Prepares or executes one task per cycle using todo.md (backlog) and todo-next.md (current task). Use when asked to 'run todo', 'process todo', 'next task', or 'work on the next todo'."
----
-
-# PinchTab Todo Runner
-
-Two-phase pipeline: **prepare** a task (research + write up), then **execute** it next cycle. One action per invocation.
-
-## Path Resolution
-
-```bash
-PROJECT_ROOT=$(git rev-parse --show-toplevel)
-TODO_FILE="$PROJECT_ROOT/todo.md"
-TODO_NEXT="$PROJECT_ROOT/todo-next.md"
-```
-
-## Execution
-
-### 0. Ensure recurring schedule exists
-
-Before doing any work, check whether a schedule (routine) is already active for this skill:
-
-1. Use `CronList` to list existing routines.
-2. Look for one whose name or prompt references `pinchtab-todo`.
-3. **If a matching schedule exists** — continue to step 1.
-4. **If no matching schedule exists** — create one using `CronCreate` that runs every 30 minutes with the prompt `/pinchtab-todo`. Then continue to step 1.
-
-### 1. Check for `todo-next.md`
-
-- **If `todo-next.md` does NOT exist** → go to **Phase A** (prepare).
-- **If `todo-next.md` EXISTS** → go to **Phase B** (execute).
-
----
-
-## Phase A — Prepare the next task
-
-Goal: pick the first incomplete task from `todo.md`, research it, and write a detailed `todo-next.md`. Do NOT implement anything.
-
-### A1. Read `todo.md`
-
-If the file does not exist, is empty, or every task is marked `[x]`, report that the backlog is clear and stop.
-
-### A2. Pick the first `- [ ]` task
-
-Take the first incomplete item from the list.
-
-### A3. Research the task
-
-Investigate the current codebase to understand:
-- What files/packages are involved
-- How similar features are implemented
-- What the right approach is
-- Any edge cases or risks
-
-### A4. Write `todo-next.md`
-
-Create `todo-next.md` with this structure:
-
-```markdown
-# <task title>
-
-> **Source:** `todo.md` line N
-> **Status:** ready
-
-## User Story
-
-As an [agent/user/developer], I want [what] so that [why].
-
-## TLDR
-
-One paragraph summary of what needs to happen and the approach.
-
-## Details
-
-- Files to change: ...
-- Approach: ...
-- Edge cases: ...
-- Tests needed: ...
-
-## Acceptance Criteria
-
-- [ ] Criterion 1
-- [ ] Criterion 2
-- [ ] `./dev all` passes
-```
-
-### A5. Stop
-
-Report that the next task has been prepared. Do not start implementation — that happens in Phase B on the next cycle.
-
----
-
-## Phase B — Execute the current task
-
-Goal: implement the task described in `todo-next.md`, verify the build, then prepare the next one.
-
-### B1. Read `todo-next.md`
-
-Understand the task, user story, approach, and acceptance criteria.
-
-### B2. Implement the task
-
-Spawn a subagent to perform the work. Replace `{PROJECT_ROOT}` and `{TASK_DETAILS}` with actual values:
-
-```
-You are working on the PinchTab project at {PROJECT_ROOT}.
-
-Your task is described below:
-{TASK_DETAILS}
-
-Start by reading the development skill for context:
-1. Read `{PROJECT_ROOT}/skills/pinchtab-dev/SKILL.md` — dev commands, architecture, and workflow.
-2. Read `{PROJECT_ROOT}/skills/pinchtab/SKILL.md` — PinchTab command reference (if needed).
-
-Then implement the task following the approach and acceptance criteria.
-When done, report what you changed.
-```
-
-Wait for the subagent to complete and review its output.
-
-### B3. Verify the build
-
-```bash
-cd "$PROJECT_ROOT" && ./dev all
-```
-
-- **If `./dev all` passes**: continue to B4.
-- **If `./dev all` fails**: read the failure, fix the issues, re-run. Up to 3 attempts. If still failing after 3 attempts, report the failure and stop — leave `todo-next.md` in place for the next cycle.
-
-### B4. Mark done and clean up
-
-1. Mark the corresponding task as `[x]` in `todo.md`.
-2. Delete `todo-next.md`.
-
-### B5. Prepare the next task
-
-Now run **Phase A** (steps A1–A5) to prepare the next `todo-next.md` from the backlog. This way the next cycle can jump straight into execution.
-
-### B6. Stop
-
-Report what was completed and what was prepared for next cycle.
diff --git a/tests/e2e/scenarios/api/inspect-basic.sh b/tests/e2e/scenarios/api/inspect-basic.sh
index fe3d272b..2c326675 100755
--- a/tests/e2e/scenarios/api/inspect-basic.sh
+++ b/tests/e2e/scenarios/api/inspect-basic.sh
@@ -131,6 +131,42 @@ assert_http_status "400" "missing ref returns 400"
end_test
+# ─────────────────────────────────────────────────────────────────
+start_test "inspect: password field values redacted in snapshot"
+
+# Type a value into the password field so there's something to redact.
+PASS_REF=$(find_ref_by_role_and_name "textbox" "Password:" "$RESULT")
+if [ -z "$PASS_REF" ] || [ "$PASS_REF" = "null" ]; then
+ PASS_REF=$(echo "$RESULT" | jq -r '[.nodes[] | select(.name | test("password";"i")) | .ref] | first // empty')
+fi
+
+if [ -n "$PASS_REF" ] && [ "$PASS_REF" != "null" ]; then
+ pt_post /action "{\"kind\":\"type\",\"ref\":\"${PASS_REF}\",\"text\":\"supersecret\"}"
+
+ # Take a fresh snapshot and check the password field value.
+ pt_get /snapshot
+ assert_ok "snapshot after typing password"
+
+ PASS_VALUE=$(echo "$RESULT" | jq -r "[.nodes[] | select(.ref == \"$PASS_REF\")] | first | .value // empty")
+ if [ "$PASS_VALUE" = "supersecret" ]; then
+ echo -e " ${RED}✗${NC} password value leaked: $PASS_VALUE"
+ ((ASSERTIONS_FAILED++)) || true
+ elif [ -n "$PASS_VALUE" ] && echo "$PASS_VALUE" | grep -qF "••••••••"; then
+ echo -e " ${GREEN}✓${NC} password value redacted"
+ ((ASSERTIONS_PASSED++)) || true
+ elif [ -z "$PASS_VALUE" ]; then
+ echo -e " ${GREEN}✓${NC} password value empty (redacted)"
+ ((ASSERTIONS_PASSED++)) || true
+ else
+ echo -e " ${RED}✗${NC} unexpected password value: $PASS_VALUE"
+ ((ASSERTIONS_FAILED++)) || true
+ fi
+else
+ echo -e " ${YELLOW}⚠${NC} skipped: could not find password field ref"
+fi
+
+end_test
+
# ─────────────────────────────────────────────────────────────────
start_test "inspect: DELETE /cookies clears cookies"