@lobu/runtime-device 24.1.1 → 24.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/component.json +1 -1
- package/dist/dependencies.bun.lock +46 -134
- package/npm-shrinkwrap.json +229 -730
- package/package.json +1 -1
- package/vendor/cli/dist/bundled-skills/lobu/SKILL.md +20 -5
- package/vendor/cli/dist/chrome-extension/accessibility-tree.js +834 -0
- package/vendor/cli/dist/chrome-extension/ambient-context.js +53 -0
- package/vendor/cli/dist/chrome-extension/auth-refresh.js +167 -0
- package/vendor/cli/dist/chrome-extension/automation-run.js +13 -0
- package/vendor/cli/dist/chrome-extension/background.js +1155 -0
- package/vendor/cli/dist/chrome-extension/bridge.js +140 -0
- package/vendor/cli/dist/chrome-extension/browser-origin-policy.js +62 -0
- package/vendor/cli/dist/chrome-extension/browser-recovery.js +260 -0
- package/vendor/cli/dist/chrome-extension/browser-url-sanitizer.js +284 -0
- package/vendor/cli/dist/chrome-extension/completion-response.js +12 -0
- package/vendor/cli/dist/chrome-extension/config.js +144 -0
- package/vendor/cli/dist/chrome-extension/connector-manifests/chrome.json +1516 -0
- package/vendor/cli/dist/chrome-extension/connector-manifests/chrome_bookmarks.json +84 -0
- package/vendor/cli/dist/chrome-extension/connector-manifests/chrome_downloads.json +86 -0
- package/vendor/cli/dist/chrome-extension/connector-manifests/chrome_history.json +78 -0
- package/vendor/cli/dist/chrome-extension/connector-manifests.js +1767 -0
- package/vendor/cli/dist/chrome-extension/console-capture.js +627 -0
- package/vendor/cli/dist/chrome-extension/control-activity.js +70 -0
- package/vendor/cli/dist/chrome-extension/debugger-lease.js +439 -0
- package/vendor/cli/dist/chrome-extension/feed-listener.js +488 -0
- package/vendor/cli/dist/chrome-extension/feed-transaction.js +48 -0
- package/vendor/cli/dist/chrome-extension/feeds.js +632 -0
- package/vendor/cli/dist/chrome-extension/focus-tab.js +25 -0
- package/vendor/cli/dist/chrome-extension/fonts/dm-mono-latin-500-normal.woff2 +0 -0
- package/vendor/cli/dist/chrome-extension/fonts/dm-sans-latin-400-normal.woff2 +0 -0
- package/vendor/cli/dist/chrome-extension/fonts/dm-sans-latin-600-normal.woff2 +0 -0
- package/vendor/cli/dist/chrome-extension/heartbeat.js +140 -0
- package/vendor/cli/dist/chrome-extension/icons/icon-128-rec.png +0 -0
- package/vendor/cli/dist/chrome-extension/icons/icon-128.png +0 -0
- package/vendor/cli/dist/chrome-extension/icons/icon-16-rec.png +0 -0
- package/vendor/cli/dist/chrome-extension/icons/icon-16.png +0 -0
- package/vendor/cli/dist/chrome-extension/icons/icon-32-rec.png +0 -0
- package/vendor/cli/dist/chrome-extension/icons/icon-32.png +0 -0
- package/vendor/cli/dist/chrome-extension/icons/icon-48-rec.png +0 -0
- package/vendor/cli/dist/chrome-extension/icons/icon-48.png +0 -0
- package/vendor/cli/dist/chrome-extension/lens-page.js +135 -0
- package/vendor/cli/dist/chrome-extension/lens-target.js +20 -0
- package/vendor/cli/dist/chrome-extension/manifest.json +76 -0
- package/vendor/cli/dist/chrome-extension/network-intercept.js +657 -0
- package/vendor/cli/dist/chrome-extension/page-activation.js +120 -0
- package/vendor/cli/dist/chrome-extension/page-dialogs.js +125 -0
- package/vendor/cli/dist/chrome-extension/page-url.js +11 -0
- package/vendor/cli/dist/chrome-extension/panel-session.js +184 -0
- package/vendor/cli/dist/chrome-extension/poll-auth.js +85 -0
- package/vendor/cli/dist/chrome-extension/poll-backoff.js +22 -0
- package/vendor/cli/dist/chrome-extension/run-fence.js +117 -0
- package/vendor/cli/dist/chrome-extension/setup-status.js +71 -0
- package/vendor/cli/dist/chrome-extension/side-panel-action-click.js +65 -0
- package/vendor/cli/dist/chrome-extension/sidepanel-context.js +50 -0
- package/vendor/cli/dist/chrome-extension/sidepanel.html +680 -0
- package/vendor/cli/dist/chrome-extension/sidepanel.js +1643 -0
- package/vendor/cli/dist/chrome-extension/tab-labels.js +233 -0
- package/vendor/cli/dist/chrome-extension/tools.js +3354 -0
- package/vendor/cli/dist/chrome-extension/watch-observer.js +354 -0
- package/vendor/cli/dist/chrome-extension/watch-redact.js +96 -0
- package/vendor/cli/dist/chrome-extension/watch.js +348 -0
- package/vendor/cli/dist/commands/_lib/apply/desired-state.d.ts +6 -4
- package/vendor/cli/dist/commands/_lib/apply/desired-state.js +5 -3
- package/vendor/cli/dist/commands/_lib/apply/diff.js +4 -3
- package/vendor/cli/dist/commands/_lib/chrome-for-testing.d.ts +13 -0
- package/vendor/cli/dist/commands/_lib/chrome-for-testing.js +226 -0
- package/vendor/cli/dist/commands/_lib/device-credential.d.ts +34 -0
- package/vendor/cli/dist/commands/_lib/device-credential.js +157 -0
- package/vendor/cli/dist/commands/_lib/device-wizard.d.ts +17 -0
- package/vendor/cli/dist/commands/_lib/device-wizard.js +11 -2
- package/vendor/cli/dist/commands/_lib/native-messaging.d.ts +7 -0
- package/vendor/cli/dist/commands/_lib/native-messaging.js +40 -0
- package/vendor/cli/dist/commands/browser.d.ts +23 -0
- package/vendor/cli/dist/commands/browser.js +492 -0
- package/vendor/cli/dist/commands/call.d.ts +12 -0
- package/vendor/cli/dist/commands/call.js +48 -26
- package/vendor/cli/dist/commands/chat.d.ts +0 -12
- package/vendor/cli/dist/commands/chat.js +1 -1
- package/vendor/cli/dist/commands/context.d.ts +3 -1
- package/vendor/cli/dist/commands/context.js +13 -2
- package/vendor/cli/dist/commands/daemon.js +38 -171
- package/vendor/cli/dist/commands/doctor.d.ts +0 -6
- package/vendor/cli/dist/commands/doctor.js +1 -1
- package/vendor/cli/dist/commands/memory/_lib/errors.d.ts +4 -1
- package/vendor/cli/dist/commands/memory/_lib/errors.js +9 -1
- package/vendor/cli/dist/commands/memory/_lib/mcp.d.ts +0 -9
- package/vendor/cli/dist/commands/memory/_lib/mcp.js +1 -23
- package/vendor/cli/dist/commands/memory/_lib/memory-auth.d.ts +20 -4
- package/vendor/cli/dist/commands/memory/_lib/memory-auth.js +21 -17
- package/vendor/cli/dist/commands/memory/_lib/seed-cmd.d.ts +0 -8
- package/vendor/cli/dist/commands/memory/_lib/seed-cmd.js +7 -18
- package/vendor/cli/dist/commands/memory/run.js +4 -25
- package/vendor/cli/dist/config/define.d.ts +1 -1
- package/vendor/cli/dist/connectors/gchat.ts +31 -1
- package/vendor/cli/dist/connectors/google_gmail.ts +70 -41
- package/vendor/cli/dist/connectors/google_gmail_references.ts +406 -0
- package/vendor/cli/dist/connectors/linkedin-inbox-adapter.js +107 -36
- package/vendor/cli/dist/connectors/linkedin-inbox.ts +13 -0
- package/vendor/cli/dist/connectors/linkedin.ts +1 -1
- package/vendor/cli/dist/connectors/postgres.ts +14 -8
- package/vendor/cli/dist/connectors/reddit.ts +171 -5
- package/vendor/cli/dist/connectors/whatsapp-web-adapter.js +147 -61
- package/vendor/cli/dist/connectors/whatsapp-web-helpers.ts +6 -2
- package/vendor/cli/dist/connectors/whatsapp_web.ts +48 -17
- package/vendor/cli/dist/connectors/x-dm-adapter.js +252 -35
- package/vendor/cli/dist/connectors/x.ts +189 -13
- package/vendor/cli/dist/index.js +46 -6
- package/vendor/cli/dist/internal/cli-update-check.d.ts +33 -0
- package/vendor/cli/dist/internal/cli-update-check.js +98 -0
- package/vendor/cli/dist/internal/credentials.js +10 -36
- package/vendor/cli/dist/internal/device-state.d.ts +2 -0
- package/vendor/cli/dist/internal/device-state.js +4 -0
- package/vendor/cli/dist/internal/gateway-url.d.ts +0 -8
- package/vendor/cli/dist/internal/gateway-url.js +1 -1
- package/vendor/cli/dist/runtime-components.json +4 -4
- package/vendor/cli/dist/templates/AGENTS.md.tmpl +3 -1
- package/vendor/cli/dist/templates/TESTING.md.tmpl +8 -8
- package/vendor/cli/package.json +1 -1
- package/vendor/connector-sdk/dist/browser-requirement.js +1 -1
- package/vendor/connector-sdk/dist/connector-types.d.ts +34 -1
- package/vendor/connector-sdk/dist/index.d.ts +3 -1
- package/vendor/connector-sdk/dist/index.js +4 -0
- package/vendor/connector-sdk/dist/redact.d.ts +10 -0
- package/vendor/{connector-worker/dist/executor → connector-sdk/dist}/redact.js +0 -49
- package/vendor/connector-sdk/dist/types.d.ts +2 -1
- package/vendor/connector-sdk/package.json +6 -1
- package/vendor/connector-worker/dist/agent-turn/gateway-tools.d.ts +9 -0
- package/vendor/connector-worker/dist/agent-turn/gateway-tools.js +23 -2
- package/vendor/connector-worker/dist/agent-turn/guest-entry.js +14 -6
- package/vendor/connector-worker/dist/agent-turn/guest.bundle.js +62 -25
- package/vendor/connector-worker/dist/agent-turn/media-tools.d.ts +1 -0
- package/vendor/connector-worker/dist/agent-turn/media-tools.js +5 -2
- package/vendor/connector-worker/dist/bin.js +2 -0
- package/vendor/connector-worker/dist/daemon/acp-adapters/THIRD_PARTY_LICENSES.txt +1 -1
- package/vendor/connector-worker/dist/daemon/acp-adapters/claude.js +7339 -2136
- package/vendor/connector-worker/dist/daemon/agent-turn.js +52 -17
- package/vendor/connector-worker/dist/daemon/automation.js +3 -13
- package/vendor/connector-worker/dist/daemon/client.d.ts +23 -3
- package/vendor/connector-worker/dist/daemon/client.js +59 -5
- package/vendor/connector-worker/dist/daemon/executor.d.ts +0 -28
- package/vendor/connector-worker/dist/daemon/executor.js +27 -12
- package/vendor/connector-worker/dist/daemon/index.d.ts +1 -1
- package/vendor/connector-worker/dist/daemon/index.js +1 -1
- package/vendor/connector-worker/dist/daemon/interactive-session.js +29 -6
- package/vendor/connector-worker/dist/daemon/poll-loop.js +29 -2
- package/vendor/connector-worker/dist/daemon/start.d.ts +0 -1
- package/vendor/connector-worker/dist/daemon/start.js +1 -1
- package/vendor/connector-worker/dist/daemon/terminal-delivery.d.ts +6 -10
- package/vendor/connector-worker/dist/daemon/terminal-delivery.js +59 -23
- package/vendor/connector-worker/dist/daemon/terminal-failure.js +2 -2
- package/vendor/connector-worker/dist/executor/isolate.js +4 -1
- package/vendor/connector-worker/dist/isolate/bridge.d.ts +6 -2
- package/vendor/connector-worker/dist/isolate/bridge.js +14 -8
- package/vendor/connector-worker/package.json +2 -2
- package/vendor/core/dist/agent-tooling.d.ts +8 -0
- package/vendor/core/dist/agent-tooling.js +9 -1
- package/vendor/core/dist/capabilities.d.ts +1 -1
- package/vendor/core/dist/capabilities.js +5 -0
- package/vendor/core/dist/connector-query-errors.d.ts +6 -0
- package/vendor/core/dist/connector-query-errors.js +4 -0
- package/vendor/core/dist/contracts/entity-reference.d.ts +3 -0
- package/vendor/core/dist/contracts/entity-reference.js +31 -0
- package/vendor/core/dist/contracts/tools/manage-automations.d.ts +3 -0
- package/vendor/core/dist/contracts/tools/manage-automations.js +4 -1
- package/vendor/core/dist/contracts/tools/manage-connections.js +1 -1
- package/vendor/core/dist/contracts/tools/manage-entity-schema.js +2 -2
- package/vendor/core/dist/contracts/tools/manage-entity.d.ts +117 -34
- package/vendor/core/dist/contracts/tools/manage-entity.js +47 -14
- package/vendor/core/dist/contracts/tools/manage-operations.d.ts +13 -4
- package/vendor/core/dist/contracts/tools/manage-operations.js +19 -7
- package/vendor/core/dist/contracts/tools/read-knowledge.d.ts +6 -1
- package/vendor/core/dist/contracts/tools/read-knowledge.js +20 -1
- package/vendor/core/dist/contracts/tools/view-attach.d.ts +1 -1
- package/vendor/core/dist/contracts/tools/view-runtime.d.ts +2 -0
- package/vendor/core/dist/contracts/tools/view-runtime.js +3 -1
- package/vendor/core/dist/contracts/worker/device-automation.d.ts +4 -9
- package/vendor/core/dist/contracts/worker/device-automation.js +10 -15
- package/vendor/core/dist/contracts/worker/protocol.d.ts +20 -0
- package/vendor/core/dist/contracts/worker/protocol.js +20 -0
- package/vendor/core/dist/errors.d.ts +0 -20
- package/vendor/core/dist/errors.js +1 -25
- package/vendor/core/dist/otel.js +38 -10
- package/vendor/core/dist/reserved.d.ts +6 -3
- package/vendor/core/dist/reserved.js +6 -3
- package/vendor/core/dist/utils/ajv.js +3 -1
- package/vendor/core/dist/worker/auth.d.ts +3 -2
- package/vendor/core/package.json +31 -5
- package/vendor/postgres/cf/src/query.js +3 -1
- package/vendor/postgres/cjs/src/query.js +3 -1
- package/vendor/postgres/src/query.js +3 -1
- package/vendor/connector-worker/dist/executor/http-status.d.ts +0 -16
- package/vendor/connector-worker/dist/executor/http-status.js +0 -21
- package/vendor/connector-worker/dist/executor/redact.d.ts +0 -29
- /package/vendor/postgres/{.bun-tag-2f292c6554a8475e → .bun-tag-22d644c2873790db} +0 -0
|
@@ -0,0 +1,354 @@
|
|
|
1
|
+
// Watch-observer content script.
|
|
2
|
+
//
|
|
3
|
+
// Injected into the active tab by background.js when the user enables
|
|
4
|
+
// "Live input context" in the sidepanel. Captures trusted (isTrusted)
|
|
5
|
+
// form input + submit events — with the same sensitive-field redaction
|
|
6
|
+
// as accessibility-tree.js — and streams them to the service worker via
|
|
7
|
+
// chrome.runtime.sendMessage. The SW buffers them as live context for
|
|
8
|
+
// the agent. Storage is ephemeral by default; the agent decides what (if
|
|
9
|
+
// anything) to persist.
|
|
10
|
+
//
|
|
11
|
+
// There is deliberately NO in-page UI here. The live-state indicator is
|
|
12
|
+
// the red recording dot the SW paints on the Owletto toolbar icon (see
|
|
13
|
+
// watch.js), so this script never injects any display DOM into the page.
|
|
14
|
+
//
|
|
15
|
+
// Tear-down: background.js sends { op: "watch-stop" } via
|
|
16
|
+
// chrome.tabs.sendMessage when the user toggles the setting off. The
|
|
17
|
+
// script removes its listeners and returns. Re-injecting is idempotent.
|
|
18
|
+
|
|
19
|
+
(() => {
|
|
20
|
+
// Slot sentinel: skips re-injecting when this document already has a
|
|
21
|
+
// live observer (chrome.scripting.executeScript re-runs this file on
|
|
22
|
+
// every tab activation, and we must not stack duplicate listeners).
|
|
23
|
+
// Defined non-writable + non-configurable so a page can't forge the
|
|
24
|
+
// sentinel, but .active is mutable so a cleanup can hand the slot back
|
|
25
|
+
// and allow a clean re-install later.
|
|
26
|
+
const INSTALL_KEY = "__lobu_watch_observer";
|
|
27
|
+
const existing = window[INSTALL_KEY];
|
|
28
|
+
if (existing && existing.active) {
|
|
29
|
+
// Already observing in this document; idempotent re-injection.
|
|
30
|
+
return;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
// ── redaction (same set as accessibility-tree.js) ──────────────────
|
|
34
|
+
function isSensitive(el) {
|
|
35
|
+
const tag = (el.tagName || "").toLowerCase();
|
|
36
|
+
if (tag !== "input" && tag !== "textarea") return false;
|
|
37
|
+
const type = (el.getAttribute("type") || "").toLowerCase();
|
|
38
|
+
if (type === "password" || type === "hidden") return true;
|
|
39
|
+
const ac = (el.getAttribute("autocomplete") || "").toLowerCase();
|
|
40
|
+
const danger = [
|
|
41
|
+
"current-password",
|
|
42
|
+
"new-password",
|
|
43
|
+
"one-time-code",
|
|
44
|
+
"cc-number",
|
|
45
|
+
"cc-csc",
|
|
46
|
+
"cc-exp",
|
|
47
|
+
"cc-exp-month",
|
|
48
|
+
"cc-exp-year",
|
|
49
|
+
];
|
|
50
|
+
for (const term of danger) if (ac.indexOf(term) !== -1) return true;
|
|
51
|
+
return false;
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
// ── credential redaction (inline copy of watch-redact.js; keep in sync) ──
|
|
55
|
+
const REDACTED_VALUE = "[value redacted]";
|
|
56
|
+
const SENSITIVE_LABEL_RE =
|
|
57
|
+
/\bpass(?:word|phrase|code)?\b|\bpwd\b|\bsecret(?!ary)|token|api[\s_-]*key|private[\s_-]*key|access[\s_-]*key|code#state|\b(?:otp|2fa|mfa|totp|cvv|cvc|ssn|pin)\b|(?:verification|security|auth(?:orization|orisation)?|oauth|one[\s_-]*time|recovery|backup|confirmation)[\s_-]*code|credit[\s_-]*card|card[\s_-]*number/i;
|
|
58
|
+
const OAUTH_PAIR_RE = /^[A-Za-z0-9_-]{16,}#[A-Za-z0-9_-]{16,}$/;
|
|
59
|
+
const KNOWN_TOKEN_RE =
|
|
60
|
+
/\b(?:(?:sk|pk|rk)[-_](?:live|test|ant|proj|or)?[-_]?[A-Za-z0-9_-]{16,}|gh[pousr]_[A-Za-z0-9]{20,}|github_pat_[A-Za-z0-9_]{20,}|xox[abprs]-[A-Za-z0-9-]{10,}|AKIA[0-9A-Z]{16}|AIza[A-Za-z0-9_-]{30,}|eyJ[A-Za-z0-9_-]{8,}\.[A-Za-z0-9_-]{8,}\.[A-Za-z0-9_-]{8,}|Bearer\s+[A-Za-z0-9._~+/=-]{16,})/g;
|
|
61
|
+
function isOpaqueToken(run) {
|
|
62
|
+
if (/\.[A-Za-z][A-Za-z0-9]{0,14}$/.test(run)) return false; // file names
|
|
63
|
+
if (/[\\@]/.test(run)) return false; // emails, Windows paths
|
|
64
|
+
if (run.includes("://")) return false;
|
|
65
|
+
// Hyphen/underscore/dot separated words (slugs, file names) are not tokens.
|
|
66
|
+
if ((run.match(/[-_.]/g) || []).length >= 3) return false;
|
|
67
|
+
const classes =
|
|
68
|
+
Number(/[a-z]/.test(run)) + Number(/[A-Z]/.test(run)) + Number(/\d/.test(run));
|
|
69
|
+
return classes >= 2;
|
|
70
|
+
}
|
|
71
|
+
function isWholeOpaqueToken(v) {
|
|
72
|
+
if (v.includes("/")) return false; // paths: slash values are only credentials via known prefixes or labels
|
|
73
|
+
if (v.includes("://") || v.startsWith("/")) return false;
|
|
74
|
+
return isOpaqueToken(v);
|
|
75
|
+
}
|
|
76
|
+
function isEmbeddedOpaqueWord(word) {
|
|
77
|
+
if (word.length < 32 || /\s/.test(word)) return false;
|
|
78
|
+
if (word.includes("/") || word.includes("://")) return false;
|
|
79
|
+
return isOpaqueToken(word);
|
|
80
|
+
}
|
|
81
|
+
function normLabel(l) {
|
|
82
|
+
return String(l || "").replace(/([a-z])([A-Z])/g, "$1 $2").replace(/[_.]/g, " ");
|
|
83
|
+
}
|
|
84
|
+
function looksLikeCredential(value) {
|
|
85
|
+
const v = String(value).trim();
|
|
86
|
+
if (!v) return false;
|
|
87
|
+
if (OAUTH_PAIR_RE.test(v)) return true;
|
|
88
|
+
KNOWN_TOKEN_RE.lastIndex = 0;
|
|
89
|
+
if (KNOWN_TOKEN_RE.test(v)) return true;
|
|
90
|
+
return !/\s/.test(v) && v.length >= 32 && isWholeOpaqueToken(v);
|
|
91
|
+
}
|
|
92
|
+
function redactTypedValue(label, value) {
|
|
93
|
+
if (typeof value !== "string" || value === "") return value;
|
|
94
|
+
if (SENSITIVE_LABEL_RE.test(normLabel(label)) || looksLikeCredential(value)) {
|
|
95
|
+
return REDACTED_VALUE;
|
|
96
|
+
}
|
|
97
|
+
const out = value.replace(KNOWN_TOKEN_RE, REDACTED_VALUE);
|
|
98
|
+
return out
|
|
99
|
+
.split(/(\s+)/)
|
|
100
|
+
.map((word) => (isEmbeddedOpaqueWord(word) ? REDACTED_VALUE : word))
|
|
101
|
+
.join("");
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
function fieldLabel(el) {
|
|
105
|
+
return (
|
|
106
|
+
el.getAttribute("aria-label") ||
|
|
107
|
+
el.getAttribute("placeholder") ||
|
|
108
|
+
el.getAttribute("name") ||
|
|
109
|
+
el.getAttribute("id") ||
|
|
110
|
+
""
|
|
111
|
+
);
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
// ── input sessions ──────────────────────────────────────────────────
|
|
115
|
+
// One observation per settled input, not one per keystroke burst. A typing
|
|
116
|
+
// session is a chain of trusted edits to one field where each edit starts
|
|
117
|
+
// from the value the previous one left. Every snapshot of a session carries
|
|
118
|
+
// the same `session_started_at`, which the service worker folds into the
|
|
119
|
+
// observation's origin id, so a later snapshot SUPERSEDES the earlier one on
|
|
120
|
+
// ingest instead of landing as a near-duplicate event.
|
|
121
|
+
//
|
|
122
|
+
// A session ends when the field is emptied behind it (a chat app clearing
|
|
123
|
+
// the composer after send fires no trusted input event), when its content
|
|
124
|
+
// changed while the user was away from it (a draft swap), when the user
|
|
125
|
+
// empties the field, when its form is submitted, or when the URL changes.
|
|
126
|
+
//
|
|
127
|
+
// Snapshots flush after an idle gap (the settled value), at most every
|
|
128
|
+
// MAX_WAIT_MS during continuous typing, and immediately on blur, submit,
|
|
129
|
+
// page hide, and watch stop, so the final typed value is never lost.
|
|
130
|
+
const SETTLE_MS = 2000;
|
|
131
|
+
const MAX_WAIT_MS = 15000;
|
|
132
|
+
const sessions = new Map(); // el → session
|
|
133
|
+
|
|
134
|
+
function readValue(el) {
|
|
135
|
+
const tag = (el.tagName || "").toLowerCase();
|
|
136
|
+
return tag === "input" || tag === "textarea" ? (el.value ?? "") : (el.textContent ?? "");
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
function isObservedField(el) {
|
|
140
|
+
if (!el || !el.tagName) return false;
|
|
141
|
+
const tag = el.tagName.toLowerCase();
|
|
142
|
+
return tag === "input" || tag === "textarea" || el.getAttribute("contenteditable") === "true";
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
function flushSession(el, session) {
|
|
146
|
+
if (session.timer != null) {
|
|
147
|
+
clearTimeout(session.timer);
|
|
148
|
+
session.timer = null;
|
|
149
|
+
}
|
|
150
|
+
if (!session.pending) return;
|
|
151
|
+
session.pending = false;
|
|
152
|
+
session.firstPendingAt = null;
|
|
153
|
+
const value = session.value;
|
|
154
|
+
try {
|
|
155
|
+
chrome.runtime.sendMessage({
|
|
156
|
+
op: "watch-input",
|
|
157
|
+
url: session.url,
|
|
158
|
+
field_label: session.label,
|
|
159
|
+
// The value is REDACTED if the field is sensitive — even on the
|
|
160
|
+
// client side, we never let the value into the runtime memory we
|
|
161
|
+
// pass to the SW.
|
|
162
|
+
value: isSensitive(el) ? "[value redacted]" : redactTypedValue(session.label, value),
|
|
163
|
+
length: value.length,
|
|
164
|
+
tag: (el.tagName || "").toLowerCase(),
|
|
165
|
+
type: el.getAttribute("type") || undefined,
|
|
166
|
+
ts: session.ts,
|
|
167
|
+
session_started_at: session.startedAt,
|
|
168
|
+
});
|
|
169
|
+
} catch {}
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
function endSession(el) {
|
|
173
|
+
const session = sessions.get(el);
|
|
174
|
+
if (!session) return;
|
|
175
|
+
flushSession(el, session);
|
|
176
|
+
sessions.delete(el);
|
|
177
|
+
}
|
|
178
|
+
|
|
179
|
+
function flushAll() {
|
|
180
|
+
for (const [el, session] of sessions) flushSession(el, session);
|
|
181
|
+
}
|
|
182
|
+
|
|
183
|
+
function scheduleFlush(el, session) {
|
|
184
|
+
if (session.timer != null) clearTimeout(session.timer);
|
|
185
|
+
const now = Date.now();
|
|
186
|
+
if (session.firstPendingAt == null) session.firstPendingAt = now;
|
|
187
|
+
const wait = Math.max(0, Math.min(SETTLE_MS, session.firstPendingAt + MAX_WAIT_MS - now));
|
|
188
|
+
session.timer = setTimeout(() => {
|
|
189
|
+
session.timer = null;
|
|
190
|
+
flushSession(el, session);
|
|
191
|
+
}, wait);
|
|
192
|
+
}
|
|
193
|
+
|
|
194
|
+
function onBeforeInput(ev) {
|
|
195
|
+
if (ev.isTrusted === false) return;
|
|
196
|
+
const el = ev.target;
|
|
197
|
+
const session = sessions.get(el);
|
|
198
|
+
if (!session) return;
|
|
199
|
+
if (location.href !== session.url) {
|
|
200
|
+
endSession(el);
|
|
201
|
+
return;
|
|
202
|
+
}
|
|
203
|
+
// The edit about to land does not start from the value this session last
|
|
204
|
+
// saw, so the field changed without a trusted input event. When it was
|
|
205
|
+
// emptied (a chat app clearing the composer after send) or the user left
|
|
206
|
+
// the field in between (a draft swap), what the session holds was already
|
|
207
|
+
// sent or belongs elsewhere: close it. A mid-burst difference with focus
|
|
208
|
+
// never lost is a rich editor normalizing its own DOM, not a new input,
|
|
209
|
+
// and must not split the session into per-keystroke observations.
|
|
210
|
+
const before = readValue(el);
|
|
211
|
+
if (before !== session.value && (before === "" || session.blurred)) endSession(el);
|
|
212
|
+
}
|
|
213
|
+
|
|
214
|
+
function onInput(ev) {
|
|
215
|
+
// Synthetic events fired by page JS have isTrusted=false. Only
|
|
216
|
+
// accept user-typed input to prevent a malicious page from poisoning
|
|
217
|
+
// the observation stream.
|
|
218
|
+
if (ev.isTrusted === false) return;
|
|
219
|
+
const el = ev.target;
|
|
220
|
+
if (!isObservedField(el)) return;
|
|
221
|
+
const value = readValue(el);
|
|
222
|
+
if (value === "") {
|
|
223
|
+
// Emptied: report the last typed value and start fresh next keystroke.
|
|
224
|
+
endSession(el);
|
|
225
|
+
return;
|
|
226
|
+
}
|
|
227
|
+
let session = sessions.get(el);
|
|
228
|
+
if (session && location.href !== session.url) {
|
|
229
|
+
endSession(el);
|
|
230
|
+
session = undefined;
|
|
231
|
+
}
|
|
232
|
+
const now = Date.now();
|
|
233
|
+
if (!session) {
|
|
234
|
+
// A field the page has since removed gets no more input; drop its
|
|
235
|
+
// session so the map only ever holds live fields (an SPA re-creates its
|
|
236
|
+
// composer on every route change).
|
|
237
|
+
for (const other of [...sessions.keys()]) {
|
|
238
|
+
if (!other.isConnected) endSession(other);
|
|
239
|
+
}
|
|
240
|
+
session = {
|
|
241
|
+
url: location.href,
|
|
242
|
+
label: fieldLabel(el),
|
|
243
|
+
startedAt: new Date(now).toISOString(),
|
|
244
|
+
value: "",
|
|
245
|
+
blurred: false,
|
|
246
|
+
ts: null,
|
|
247
|
+
pending: false,
|
|
248
|
+
firstPendingAt: null,
|
|
249
|
+
timer: null,
|
|
250
|
+
};
|
|
251
|
+
sessions.set(el, session);
|
|
252
|
+
}
|
|
253
|
+
session.value = value;
|
|
254
|
+
session.blurred = false;
|
|
255
|
+
session.ts = new Date(now).toISOString();
|
|
256
|
+
session.pending = true;
|
|
257
|
+
scheduleFlush(el, session);
|
|
258
|
+
}
|
|
259
|
+
|
|
260
|
+
function onFocusOut(ev) {
|
|
261
|
+
const session = sessions.get(ev.target);
|
|
262
|
+
if (!session) return;
|
|
263
|
+
session.blurred = true;
|
|
264
|
+
flushSession(ev.target, session);
|
|
265
|
+
}
|
|
266
|
+
|
|
267
|
+
function onPageHide() {
|
|
268
|
+
flushAll();
|
|
269
|
+
}
|
|
270
|
+
|
|
271
|
+
function onVisibilityChange() {
|
|
272
|
+
if (document.visibilityState === "hidden") flushAll();
|
|
273
|
+
}
|
|
274
|
+
|
|
275
|
+
function onSubmit(ev) {
|
|
276
|
+
if (ev.isTrusted === false) return;
|
|
277
|
+
const form = ev.target;
|
|
278
|
+
if (!form || form.tagName?.toLowerCase() !== "form") return;
|
|
279
|
+
for (const el of [...sessions.keys()]) {
|
|
280
|
+
if (form.contains(el)) endSession(el);
|
|
281
|
+
}
|
|
282
|
+
const fields = [];
|
|
283
|
+
for (const el of form.querySelectorAll("input, textarea, select")) {
|
|
284
|
+
const lbl = fieldLabel(el);
|
|
285
|
+
if (!lbl) continue;
|
|
286
|
+
fields.push({
|
|
287
|
+
label: lbl,
|
|
288
|
+
value: isSensitive(el)
|
|
289
|
+
? "[value redacted]"
|
|
290
|
+
: redactTypedValue(lbl, el.value ?? ""),
|
|
291
|
+
length: (el.value ?? "").length,
|
|
292
|
+
});
|
|
293
|
+
}
|
|
294
|
+
try {
|
|
295
|
+
chrome.runtime.sendMessage({
|
|
296
|
+
op: "watch-submit",
|
|
297
|
+
url: location.href,
|
|
298
|
+
form_action: form.getAttribute("action") || undefined,
|
|
299
|
+
fields,
|
|
300
|
+
ts: new Date().toISOString(),
|
|
301
|
+
});
|
|
302
|
+
} catch {}
|
|
303
|
+
}
|
|
304
|
+
|
|
305
|
+
// ── install ─────────────────────────────────────────────────────────
|
|
306
|
+
document.addEventListener("beforeinput", onBeforeInput, { capture: true, passive: true });
|
|
307
|
+
document.addEventListener("input", onInput, { capture: true, passive: true });
|
|
308
|
+
document.addEventListener("focusout", onFocusOut, { capture: true, passive: true });
|
|
309
|
+
document.addEventListener("submit", onSubmit, { capture: true });
|
|
310
|
+
document.addEventListener("visibilitychange", onVisibilityChange, { capture: true });
|
|
311
|
+
window.addEventListener("pagehide", onPageHide, { capture: true });
|
|
312
|
+
|
|
313
|
+
function onRuntimeMessage(msg) {
|
|
314
|
+
if (msg?.op === "watch-stop") cleanup();
|
|
315
|
+
}
|
|
316
|
+
chrome.runtime.onMessage.addListener(onRuntimeMessage);
|
|
317
|
+
|
|
318
|
+
let cleanedUp = false;
|
|
319
|
+
function cleanup() {
|
|
320
|
+
if (cleanedUp) return;
|
|
321
|
+
cleanedUp = true;
|
|
322
|
+
// Report what was typed before the observer goes away.
|
|
323
|
+
for (const el of [...sessions.keys()]) endSession(el);
|
|
324
|
+
document.removeEventListener("beforeinput", onBeforeInput, { capture: true });
|
|
325
|
+
document.removeEventListener("input", onInput, { capture: true });
|
|
326
|
+
document.removeEventListener("focusout", onFocusOut, { capture: true });
|
|
327
|
+
document.removeEventListener("submit", onSubmit, { capture: true });
|
|
328
|
+
document.removeEventListener("visibilitychange", onVisibilityChange, { capture: true });
|
|
329
|
+
window.removeEventListener("pagehide", onPageHide, { capture: true });
|
|
330
|
+
try {
|
|
331
|
+
chrome.runtime.onMessage.removeListener(onRuntimeMessage);
|
|
332
|
+
} catch {}
|
|
333
|
+
// Flip the slot's active flag in place so a future re-injection (after
|
|
334
|
+
// a stop-then-start) re-installs cleanly.
|
|
335
|
+
slot.active = false;
|
|
336
|
+
}
|
|
337
|
+
|
|
338
|
+
// Reuse the existing slot if present (was cleaned up); otherwise create a
|
|
339
|
+
// non-writable + non-configurable slot for first install.
|
|
340
|
+
let slot;
|
|
341
|
+
if (existing && !existing.active) {
|
|
342
|
+
slot = existing;
|
|
343
|
+
slot.active = true;
|
|
344
|
+
slot.uninstall = cleanup;
|
|
345
|
+
} else {
|
|
346
|
+
slot = { active: true, uninstall: cleanup };
|
|
347
|
+
Object.defineProperty(window, INSTALL_KEY, {
|
|
348
|
+
value: slot,
|
|
349
|
+
writable: false,
|
|
350
|
+
configurable: false,
|
|
351
|
+
enumerable: false,
|
|
352
|
+
});
|
|
353
|
+
}
|
|
354
|
+
})();
|
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
// Credential redaction for the watch (live input) capture.
|
|
2
|
+
//
|
|
3
|
+
// The capture sees what the user types. Attribute checks alone (type=password,
|
|
4
|
+
// autocomplete hints) miss credentials pasted into ordinary text fields, such
|
|
5
|
+
// as an OAuth "code#state" on a connect page. This module redacts by field
|
|
6
|
+
// label and by value shape so a credential never lands in the live buffer or
|
|
7
|
+
// the feed. watch-observer.js carries an inline copy of the same rules for the
|
|
8
|
+
// content script (it cannot import); keep the two in sync, the tests check both.
|
|
9
|
+
|
|
10
|
+
const REDACTED_VALUE = "[value redacted]";
|
|
11
|
+
|
|
12
|
+
const SENSITIVE_LABEL_RE =
|
|
13
|
+
/\bpass(?:word|phrase|code)?\b|\bpwd\b|\bsecret(?!ary)|token|api[\s_-]*key|private[\s_-]*key|access[\s_-]*key|code#state|\b(?:otp|2fa|mfa|totp|cvv|cvc|ssn|pin)\b|(?:verification|security|auth(?:orization|orisation)?|oauth|one[\s_-]*time|recovery|backup|confirmation)[\s_-]*code|credit[\s_-]*card|card[\s_-]*number/i;
|
|
14
|
+
|
|
15
|
+
// OAuth redirect "code#state" pair: two long url-safe segments joined by "#".
|
|
16
|
+
const OAUTH_PAIR_RE = /^[A-Za-z0-9_-]{16,}#[A-Za-z0-9_-]{16,}$/;
|
|
17
|
+
// Well-known credential prefixes, anywhere in a string.
|
|
18
|
+
const KNOWN_TOKEN_RE =
|
|
19
|
+
/\b(?:(?:sk|pk|rk)[-_](?:live|test|ant|proj|or)?[-_]?[A-Za-z0-9_-]{16,}|gh[pousr]_[A-Za-z0-9]{20,}|github_pat_[A-Za-z0-9_]{20,}|xox[abprs]-[A-Za-z0-9-]{10,}|AKIA[0-9A-Z]{16}|AIza[A-Za-z0-9_-]{30,}|eyJ[A-Za-z0-9_-]{8,}\.[A-Za-z0-9_-]{8,}\.[A-Za-z0-9_-]{8,}|Bearer\s+[A-Za-z0-9._~+/=-]{16,})/g;
|
|
20
|
+
|
|
21
|
+
|
|
22
|
+
function isOpaqueToken(run) {
|
|
23
|
+
if (/\.[A-Za-z][A-Za-z0-9]{0,14}$/.test(run)) return false; // file names
|
|
24
|
+
if (/[\\@]/.test(run)) return false; // emails, Windows paths
|
|
25
|
+
if (run.includes("://")) return false;
|
|
26
|
+
// Hyphen/underscore/dot separated words (slugs, file names) are not tokens.
|
|
27
|
+
if ((run.match(/[-_.]/g) || []).length >= 3) return false;
|
|
28
|
+
const classes =
|
|
29
|
+
Number(/[a-z]/.test(run)) + Number(/[A-Z]/.test(run)) + Number(/\d/.test(run));
|
|
30
|
+
return classes >= 2;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
// A whole value that is one opaque token. Values containing "/" (URLs, paths) are
|
|
34
|
+
// never generic tokens; they are caught only by label or known prefix.
|
|
35
|
+
function isWholeOpaqueToken(v) {
|
|
36
|
+
if (v.includes("/")) return false; // paths: slash values are only credentials via known prefixes or labels
|
|
37
|
+
if (v.includes("://") || v.startsWith("/")) return false;
|
|
38
|
+
return isOpaqueToken(v);
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
// A whitespace-delimited word inside longer text that is one opaque token.
|
|
42
|
+
// URLs and paths (anything with "/" or "://") are left alone.
|
|
43
|
+
function isEmbeddedOpaqueWord(word) {
|
|
44
|
+
if (word.length < 32 || /\s/.test(word)) return false;
|
|
45
|
+
if (word.includes("/") || word.includes("://")) return false;
|
|
46
|
+
return isOpaqueToken(word);
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
function normLabel(l) {
|
|
50
|
+
return String(l || "").replace(/([a-z])([A-Z])/g, "$1 $2").replace(/[_.]/g, " ");
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
function isSensitiveLabel(label) {
|
|
54
|
+
return typeof label === "string" && SENSITIVE_LABEL_RE.test(normLabel(label));
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
function looksLikeCredential(value) {
|
|
58
|
+
if (typeof value !== "string") return false;
|
|
59
|
+
const v = value.trim();
|
|
60
|
+
if (!v) return false;
|
|
61
|
+
if (OAUTH_PAIR_RE.test(v)) return true;
|
|
62
|
+
KNOWN_TOKEN_RE.lastIndex = 0;
|
|
63
|
+
if (KNOWN_TOKEN_RE.test(v)) return true;
|
|
64
|
+
return !/\s/.test(v) && v.length >= 32 && isWholeOpaqueToken(v);
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
// Redact a typed value: whole value for a sensitive label or a credential-shaped
|
|
68
|
+
// value, otherwise only credential-shaped runs embedded in longer text.
|
|
69
|
+
export function redactTypedValue(label, value) {
|
|
70
|
+
if (typeof value !== "string" || value === "") return value;
|
|
71
|
+
if (isSensitiveLabel(label) || looksLikeCredential(value)) return REDACTED_VALUE;
|
|
72
|
+
const out = value.replace(KNOWN_TOKEN_RE, REDACTED_VALUE);
|
|
73
|
+
return out
|
|
74
|
+
.split(/(\s+)/)
|
|
75
|
+
.map((word) => (isEmbeddedOpaqueWord(word) ? REDACTED_VALUE : word))
|
|
76
|
+
.join("");
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
// Redact the value-bearing fields of a watch-input / watch-submit event.
|
|
80
|
+
export function redactWatchEvent(event) {
|
|
81
|
+
if (!event || typeof event !== "object") return event;
|
|
82
|
+
if (event.op === "watch-input") {
|
|
83
|
+
return { ...event, value: redactTypedValue(event.field_label, event.value) };
|
|
84
|
+
}
|
|
85
|
+
if (event.op === "watch-submit" && Array.isArray(event.fields)) {
|
|
86
|
+
return {
|
|
87
|
+
...event,
|
|
88
|
+
fields: event.fields.map((f) =>
|
|
89
|
+
f && typeof f === "object"
|
|
90
|
+
? { ...f, value: redactTypedValue(f.label, f.value) }
|
|
91
|
+
: f,
|
|
92
|
+
),
|
|
93
|
+
};
|
|
94
|
+
}
|
|
95
|
+
return event;
|
|
96
|
+
}
|