@akasecurity/ai-tc-claude-code 0.9.12 → 0.9.13
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/.claude-plugin/plugin.json +1 -1
- package/package.json +2 -2
- package/scripts/apply-suppressions.js +331 -22
- package/scripts/backfill.js +464 -124
- package/scripts/content-retention.js +334 -22
- package/scripts/filescan.js +464 -124
- package/scripts/firstrun.js +464 -124
- package/scripts/history-sync.js +379 -42
- package/scripts/intro.js +209 -17
- package/scripts/message-display.js +331 -22
- package/scripts/onboard.js +331 -22
- package/scripts/post-model-switch.js +212 -17
- package/scripts/post-tool-use.js +464 -124
- package/scripts/pre-model-switch.js +488 -127
- package/scripts/pre-tool-use.js +488 -127
- package/scripts/query.js +575 -125
- package/scripts/reconcile.js +464 -124
- package/scripts/remediate.js +464 -124
- package/scripts/scan-worker.js +209 -17
- package/scripts/session-start.js +464 -124
- package/scripts/start-light.js +209 -17
- package/scripts/statusline.js +464 -124
- package/scripts/stop.js +212 -17
- package/scripts/sync.js +464 -124
- package/scripts/user-prompt-submit.js +488 -127
package/scripts/session-start.js
CHANGED
|
@@ -20481,7 +20481,17 @@ var UNPRICEABLE_PROVIDERS = Object.freeze([
|
|
|
20481
20481
|
"gateway",
|
|
20482
20482
|
"unknown",
|
|
20483
20483
|
"cli",
|
|
20484
|
-
"api"
|
|
20484
|
+
"api",
|
|
20485
|
+
// The browser extension's native host records these as `llm_call.provider`
|
|
20486
|
+
// for a web-chat turn — the web tool id, deliberately never the vendor id
|
|
20487
|
+
// (`openai`/`anthropic`) the session root carries. Subscription traffic
|
|
20488
|
+
// burns rate-limit budget, not dollar credits, and listing them here is
|
|
20489
|
+
// what keeps that true structurally: a later maintainer who wants to price
|
|
20490
|
+
// web-chat traffic at API rates has to delete this entry first, and meet
|
|
20491
|
+
// the reason on the way, rather than quietly adding one to
|
|
20492
|
+
// PROVIDER_PLATFORM.
|
|
20493
|
+
"chatgpt",
|
|
20494
|
+
"claude-ai"
|
|
20485
20495
|
]);
|
|
20486
20496
|
function platformForProvider(provider) {
|
|
20487
20497
|
return PROVIDER_PLATFORM.get(provider.trim().toLowerCase()) ?? null;
|
|
@@ -20624,7 +20634,12 @@ var HARNESS = {
|
|
|
20624
20634
|
ClaudeDesktop: "claudedesktop",
|
|
20625
20635
|
ChatGpt: "chatgpt",
|
|
20626
20636
|
ClaudeAi: "claudeai",
|
|
20627
|
-
Api: "api"
|
|
20637
|
+
Api: "api",
|
|
20638
|
+
// Not a coding assistant a person drives — an in-process SDK embedded in an
|
|
20639
|
+
// application, so it has no IDE/CLI/desktop/web surface of its own. Carries
|
|
20640
|
+
// the same id as its SOURCE_TOOL counterpart, unlike every capture-side tool
|
|
20641
|
+
// whose wire spelling differs from its display spelling.
|
|
20642
|
+
AiTcSdk: "ai-tc-sdk"
|
|
20628
20643
|
};
|
|
20629
20644
|
var Harness = external_exports.enum(HARNESS).meta({ id: "Harness" });
|
|
20630
20645
|
var SOURCE_TOOL = {
|
|
@@ -20640,9 +20655,15 @@ var SOURCE_TOOL = {
|
|
|
20640
20655
|
// whose tool could not be identified both render through the read side's
|
|
20641
20656
|
// miss path rather than as a harness of their own.
|
|
20642
20657
|
Cli: "cli",
|
|
20643
|
-
Unknown: "unknown"
|
|
20658
|
+
Unknown: "unknown",
|
|
20659
|
+
// The wire id an in-process, request-path SDK stamps on its own structural
|
|
20660
|
+
// rows (`request_decision`) — never a capture of prompt/response/tool text,
|
|
20661
|
+
// since the SDK sits in front of a model call rather than inside a coding
|
|
20662
|
+
// assistant's own hook contract.
|
|
20663
|
+
AiTcSdk: "ai-tc-sdk"
|
|
20644
20664
|
};
|
|
20645
20665
|
var SourceTool = external_exports.enum(SOURCE_TOOL).meta({ id: "SourceTool" });
|
|
20666
|
+
var WebSourceTool = SourceTool.extract(["ChatGpt", "ClaudeAi"]);
|
|
20646
20667
|
var TOOL_TO_HARNESS = {
|
|
20647
20668
|
[SOURCE_TOOL.ClaudeCode]: HARNESS.ClaudeCode,
|
|
20648
20669
|
[SOURCE_TOOL.ClaudeDesktop]: HARNESS.ClaudeDesktop,
|
|
@@ -20651,7 +20672,12 @@ var TOOL_TO_HARNESS = {
|
|
|
20651
20672
|
[SOURCE_TOOL.ChatGpt]: HARNESS.ChatGpt,
|
|
20652
20673
|
[SOURCE_TOOL.Codex]: HARNESS.Codex,
|
|
20653
20674
|
[SOURCE_TOOL.Antigravity]: HARNESS.Antigravity,
|
|
20654
|
-
[SOURCE_TOOL.ClaudeAi]: HARNESS.ClaudeAi
|
|
20675
|
+
[SOURCE_TOOL.ClaudeAi]: HARNESS.ClaudeAi,
|
|
20676
|
+
// Wire and display id are the same string here, but the row still belongs:
|
|
20677
|
+
// both vocabularies carry the `AiTcSdk` member, and the join is exactly
|
|
20678
|
+
// their intersection — leaving a shared member out would read as an
|
|
20679
|
+
// uninstrumented tool on both surfaces, which this one is not.
|
|
20680
|
+
[SOURCE_TOOL.AiTcSdk]: HARNESS.AiTcSdk
|
|
20655
20681
|
};
|
|
20656
20682
|
function harnessFromTool(tool) {
|
|
20657
20683
|
return (Object.hasOwn(TOOL_TO_HARNESS, tool) ? TOOL_TO_HARNESS[tool] : void 0) ?? tool;
|
|
@@ -20688,7 +20714,8 @@ var FindingProvider = Harness.extract([
|
|
|
20688
20714
|
"ClaudeAi",
|
|
20689
20715
|
"Codex",
|
|
20690
20716
|
"Antigravity",
|
|
20691
|
-
"Api"
|
|
20717
|
+
"Api",
|
|
20718
|
+
"AiTcSdk"
|
|
20692
20719
|
]).meta({ id: "FindingProvider" });
|
|
20693
20720
|
var FindingCategory = external_exports.enum([
|
|
20694
20721
|
"secret",
|
|
@@ -21065,18 +21092,41 @@ var AuditEventType = external_exports.enum([
|
|
|
21065
21092
|
// 'tool_call' is the reconciler's structural row for every call, while
|
|
21066
21093
|
// 'tool_use' exists only where a hook enforced against the arguments.
|
|
21067
21094
|
"tool_use",
|
|
21068
|
-
// One row per model REFUSAL
|
|
21069
|
-
//
|
|
21070
|
-
//
|
|
21071
|
-
//
|
|
21072
|
-
//
|
|
21073
|
-
//
|
|
21095
|
+
// One row per model REFUSAL, across all four seams a prohibited model can be
|
|
21096
|
+
// stopped at: a switch onto it, a turn already running on it, a subagent
|
|
21097
|
+
// spawn asking for it, or a request-path refusal an embedded request-path
|
|
21098
|
+
// SDK makes in-process before the call leaves the application. Which seam
|
|
21099
|
+
// rides `attributes.refusal_seam`, never this member name. A structural row
|
|
21100
|
+
// like the ones above rather than a capture — it carries the model that was
|
|
21101
|
+
// refused and nothing the user typed, because what is worth recording about
|
|
21102
|
+
// a governance decision is the decision, and prompt text is the thing this
|
|
21103
|
+
// product exists to keep from travelling.
|
|
21074
21104
|
"model_refusal",
|
|
21105
|
+
// One row per request-path DECISION: a policy check an embedded request-path
|
|
21106
|
+
// SDK performs in-process before a model call leaves the application, or
|
|
21107
|
+
// against that call's non-streamed response. A structural row like
|
|
21108
|
+
// 'model_refusal' rather than a capture — content-free in the same way:
|
|
21109
|
+
// which side, which seam, what action and which field are decided rides
|
|
21110
|
+
// `attributes`, never this member name, and the matched text itself never
|
|
21111
|
+
// travels.
|
|
21112
|
+
//
|
|
21113
|
+
// A prohibited-model refusal on the request path is deliberately NOT this
|
|
21114
|
+
// member: it stays 'model_refusal' with `refusal_seam: 'request'`, so it
|
|
21115
|
+
// shares one bucket with the plugin's switch/turn/spawn refusals rather
|
|
21116
|
+
// than splitting one governance concept across two event types. This
|
|
21117
|
+
// member carries every OTHER request-path decision.
|
|
21118
|
+
"request_decision",
|
|
21075
21119
|
// One row per config-inventory scan, hung off the session root. It is the
|
|
21076
21120
|
// fact the posture inspection findings reference (findings require an
|
|
21077
21121
|
// audit_event_id), and its started_at is the "scanned Nm ago" the read
|
|
21078
21122
|
// surface renders.
|
|
21079
|
-
"config_scan"
|
|
21123
|
+
"config_scan",
|
|
21124
|
+
// One row per reported browser-extension capture status, hung off the web
|
|
21125
|
+
// session root. The durable home of what one tab's network interception
|
|
21126
|
+
// is doing — a write-through of the native host's in-memory tracker, so a
|
|
21127
|
+
// second process (aka extension status) and a restarted host both have
|
|
21128
|
+
// somewhere to read it back from.
|
|
21129
|
+
"capture_status"
|
|
21080
21130
|
]).meta({ id: "AuditEventType" });
|
|
21081
21131
|
var AttributeBag = external_exports.record(external_exports.string(), external_exports.unknown());
|
|
21082
21132
|
var HostAttributes = external_exports.object({
|
|
@@ -21236,6 +21286,20 @@ var CaptureAttributes = external_exports.object({
|
|
|
21236
21286
|
// repeated rather than referenced because a store reader opens this file.
|
|
21237
21287
|
redact_degraded_to: ActionTaken.optional()
|
|
21238
21288
|
}).catchall(external_exports.unknown());
|
|
21289
|
+
var CaptureStatusAttributes = external_exports.object({
|
|
21290
|
+
source_tool: external_exports.string().optional(),
|
|
21291
|
+
patched: external_exports.boolean().optional(),
|
|
21292
|
+
live: external_exports.boolean().optional(),
|
|
21293
|
+
blind: external_exports.boolean().optional(),
|
|
21294
|
+
sends_seen_dom: external_exports.number().int().nonnegative().optional(),
|
|
21295
|
+
exchanges_seen_net: external_exports.number().int().nonnegative().optional(),
|
|
21296
|
+
parse_failures: external_exports.number().int().nonnegative().optional(),
|
|
21297
|
+
unparsed_bodies: external_exports.number().int().nonnegative().optional(),
|
|
21298
|
+
shape_misses: external_exports.array(external_exports.string()).optional(),
|
|
21299
|
+
conversation_endpoints: external_exports.number().int().nonnegative().optional(),
|
|
21300
|
+
closed: external_exports.boolean().optional(),
|
|
21301
|
+
enforcement: external_exports.string().optional()
|
|
21302
|
+
}).catchall(external_exports.unknown());
|
|
21239
21303
|
var ToolCallInspection = external_exports.object({
|
|
21240
21304
|
ruleId: external_exports.string().min(1),
|
|
21241
21305
|
ruleName: external_exports.string(),
|
|
@@ -22209,6 +22273,30 @@ var AttachedCredential = external_exports.object({
|
|
|
22209
22273
|
keyPrefix: external_exports.string().min(1).max(16).optional(),
|
|
22210
22274
|
mintedAt: external_exports.iso.datetime().optional()
|
|
22211
22275
|
});
|
|
22276
|
+
var LOOPBACK_HOSTS = /* @__PURE__ */ new Set(["localhost", "127.0.0.1", "::1", "[::1]"]);
|
|
22277
|
+
function unsafeEndpointReason(endpoint) {
|
|
22278
|
+
let parsed2;
|
|
22279
|
+
try {
|
|
22280
|
+
parsed2 = new URL(endpoint);
|
|
22281
|
+
} catch {
|
|
22282
|
+
return "unparseable";
|
|
22283
|
+
}
|
|
22284
|
+
if (parsed2.username !== "" || parsed2.password !== "") return "userinfo";
|
|
22285
|
+
if (parsed2.search !== "" || parsed2.hash !== "") return "query-or-fragment";
|
|
22286
|
+
if (parsed2.protocol === "https:") return null;
|
|
22287
|
+
return parsed2.protocol === "http:" && LOOPBACK_HOSTS.has(parsed2.hostname) ? null : "insecure";
|
|
22288
|
+
}
|
|
22289
|
+
function isSafeEndpoint(endpoint) {
|
|
22290
|
+
return unsafeEndpointReason(endpoint) === null;
|
|
22291
|
+
}
|
|
22292
|
+
function originOnly(endpoint) {
|
|
22293
|
+
try {
|
|
22294
|
+
const parsed2 = new URL(endpoint);
|
|
22295
|
+
return `${parsed2.protocol}//${parsed2.host}`;
|
|
22296
|
+
} catch {
|
|
22297
|
+
return "(unparseable endpoint)";
|
|
22298
|
+
}
|
|
22299
|
+
}
|
|
22212
22300
|
var MAX_DATE_MS = 253402300799999;
|
|
22213
22301
|
var MAX_INT4 = 2147483647;
|
|
22214
22302
|
var StorePosturePack = external_exports.object({
|
|
@@ -22363,6 +22451,11 @@ var RemoteFailureKind = external_exports.enum([
|
|
|
22363
22451
|
"rejected",
|
|
22364
22452
|
"unreachable"
|
|
22365
22453
|
]);
|
|
22454
|
+
var ControlPlaneFailure = RemoteFailureKind.extract([
|
|
22455
|
+
"unauthorized",
|
|
22456
|
+
"forbidden",
|
|
22457
|
+
"unreachable"
|
|
22458
|
+
]);
|
|
22366
22459
|
var AttachDeviceRequest = external_exports.object({
|
|
22367
22460
|
// This machine's own continuity id, so re-attaching ROTATES the credential
|
|
22368
22461
|
// on one machine record instead of producing a second one. Client-minted
|
|
@@ -22902,7 +22995,12 @@ var EventMetadata = external_exports.object({
|
|
|
22902
22995
|
// in — set by the browser extension's network capture so a stored `response`
|
|
22903
22996
|
// row can be joined to the `llm_call` leaf describing the same turn. Absent
|
|
22904
22997
|
// on every other capture path, which has no such id.
|
|
22905
|
-
|
|
22998
|
+
//
|
|
22999
|
+
// Non-empty for the reason WebExchange.messageId is: it is the join key, and
|
|
23000
|
+
// a blank one matches no `llm_call` leaf. That refusal reaches only the
|
|
23001
|
+
// places an event is PARSED; the local write path types the event and parses
|
|
23002
|
+
// nothing, which is why `toCaptureAttributes` omits a blank one separately.
|
|
23003
|
+
messageId: external_exports.string().min(1).optional(),
|
|
22906
23004
|
conversationId: external_exports.string().optional(),
|
|
22907
23005
|
// How long THIS capture's inspection blocked its caller, in whole
|
|
22908
23006
|
// milliseconds — the plugin's own added latency, NOT the LLM call it sat in
|
|
@@ -23744,6 +23842,85 @@ function policyIdIsReversible(policyId) {
|
|
|
23744
23842
|
var DEFAULT_ACTIONS = Object.fromEntries(
|
|
23745
23843
|
DetectionCategory.options.map((c) => [c, builtinPolicyToAction(severityFloorPolicy(c))])
|
|
23746
23844
|
);
|
|
23845
|
+
function ruleCategoryMap(wireRules, localRules, compiledRules) {
|
|
23846
|
+
const map2 = /* @__PURE__ */ new Map();
|
|
23847
|
+
for (const rule of wireRules ?? []) map2.set(rule.id, rule.category);
|
|
23848
|
+
for (const rule of localRules ?? []) map2.set(rule.id, rule.category);
|
|
23849
|
+
for (const rule of compiledRules) map2.set(rule.id, rule.category);
|
|
23850
|
+
return map2;
|
|
23851
|
+
}
|
|
23852
|
+
function policyKey(policy) {
|
|
23853
|
+
return "ruleId" in policy.target ? `rule:${policy.target.ruleId}` : `category:${policy.target.category}`;
|
|
23854
|
+
}
|
|
23855
|
+
function floorFor(policy, categoryByRuleId) {
|
|
23856
|
+
const category = "category" in policy.target ? policy.target.category : categoryByRuleId.get(policy.target.ruleId);
|
|
23857
|
+
return category === void 0 ? null : DEFAULT_ACTIONS[category];
|
|
23858
|
+
}
|
|
23859
|
+
function strongerOf(a, b) {
|
|
23860
|
+
if (a === null) return b;
|
|
23861
|
+
if (b === null) return a;
|
|
23862
|
+
return strongerAction(a, b);
|
|
23863
|
+
}
|
|
23864
|
+
function mergeRaiseOnly(localPolicies, remotePolicies, categoryByRuleId) {
|
|
23865
|
+
const merged = /* @__PURE__ */ new Map();
|
|
23866
|
+
const disabled = [];
|
|
23867
|
+
const remoteCategoryAction = /* @__PURE__ */ new Map();
|
|
23868
|
+
for (const policy of remotePolicies) {
|
|
23869
|
+
if (!policy.enabled) continue;
|
|
23870
|
+
if (!("category" in policy.target)) continue;
|
|
23871
|
+
if (remoteCategoryAction.has(policy.target.category)) continue;
|
|
23872
|
+
const floor = floorFor(policy, categoryByRuleId);
|
|
23873
|
+
remoteCategoryAction.set(
|
|
23874
|
+
policy.target.category,
|
|
23875
|
+
floor !== null && !isActionAtLeast(policy.action, floor) ? floor : policy.action
|
|
23876
|
+
);
|
|
23877
|
+
}
|
|
23878
|
+
for (const policy of localPolicies) {
|
|
23879
|
+
if (!policy.enabled) {
|
|
23880
|
+
disabled.push(policy);
|
|
23881
|
+
continue;
|
|
23882
|
+
}
|
|
23883
|
+
const key = policyKey(policy);
|
|
23884
|
+
if (merged.has(key)) continue;
|
|
23885
|
+
let remoteFloor = null;
|
|
23886
|
+
if ("ruleId" in policy.target) {
|
|
23887
|
+
const category = categoryByRuleId.get(policy.target.ruleId);
|
|
23888
|
+
if (category !== void 0) remoteFloor = remoteCategoryAction.get(category) ?? null;
|
|
23889
|
+
}
|
|
23890
|
+
merged.set(
|
|
23891
|
+
key,
|
|
23892
|
+
remoteFloor !== null && !isActionAtLeast(policy.action, remoteFloor) ? { ...policy, action: remoteFloor } : policy
|
|
23893
|
+
);
|
|
23894
|
+
}
|
|
23895
|
+
const localCategoryAction = /* @__PURE__ */ new Map();
|
|
23896
|
+
for (const policy of merged.values()) {
|
|
23897
|
+
if ("category" in policy.target) localCategoryAction.set(policy.target.category, policy.action);
|
|
23898
|
+
}
|
|
23899
|
+
for (const policy of remotePolicies) {
|
|
23900
|
+
if (!policy.enabled) {
|
|
23901
|
+
disabled.push(policy);
|
|
23902
|
+
continue;
|
|
23903
|
+
}
|
|
23904
|
+
const key = policyKey(policy);
|
|
23905
|
+
const floor = floorFor(policy, categoryByRuleId);
|
|
23906
|
+
let localFloor = null;
|
|
23907
|
+
if ("ruleId" in policy.target) {
|
|
23908
|
+
const category = categoryByRuleId.get(policy.target.ruleId);
|
|
23909
|
+
if (category !== void 0) localFloor = localCategoryAction.get(category) ?? null;
|
|
23910
|
+
}
|
|
23911
|
+
const effectiveFloor = strongerOf(floor, localFloor);
|
|
23912
|
+
const clamped = effectiveFloor !== null && !isActionAtLeast(policy.action, effectiveFloor) ? { ...policy, action: effectiveFloor } : policy;
|
|
23913
|
+
const existing = merged.get(key);
|
|
23914
|
+
if (existing === void 0) {
|
|
23915
|
+
merged.set(key, clamped);
|
|
23916
|
+
continue;
|
|
23917
|
+
}
|
|
23918
|
+
if (actionRank(clamped.action) > actionRank(existing.action)) {
|
|
23919
|
+
merged.set(key, clamped);
|
|
23920
|
+
}
|
|
23921
|
+
}
|
|
23922
|
+
return [...merged.values(), ...disabled];
|
|
23923
|
+
}
|
|
23747
23924
|
var BUILTIN_POLICIES = Object.fromEntries(
|
|
23748
23925
|
KNOWN_BUILTIN_IDS.map((id) => [id, { id, ...BUILTIN_POLICY_SPECS[id] }])
|
|
23749
23926
|
);
|
|
@@ -23977,6 +24154,18 @@ function isHistorySyncConsentValid(consent, endpoint) {
|
|
|
23977
24154
|
if (consent === void 0 || endpoint === void 0) return false;
|
|
23978
24155
|
return consent.payloadVersion === HISTORY_SYNC_PAYLOAD_VERSION && consent.endpoint === endpoint;
|
|
23979
24156
|
}
|
|
24157
|
+
var WebChatCaptureConsent = external_exports.object({
|
|
24158
|
+
acknowledgedAt: external_exports.iso.datetime(),
|
|
24159
|
+
version: external_exports.number().int().positive()
|
|
24160
|
+
});
|
|
24161
|
+
var WebChatResponseCapture = external_exports.enum(["with-findings", "always", "never"]);
|
|
24162
|
+
var WebChatCapture = external_exports.object({
|
|
24163
|
+
responses: WebChatResponseCapture.default("with-findings"),
|
|
24164
|
+
account: external_exports.boolean().default(false),
|
|
24165
|
+
// Absent until granted. Presence alone does not authorize anything — see
|
|
24166
|
+
// isWebChatCaptureConsentValid.
|
|
24167
|
+
consent: WebChatCaptureConsent.optional()
|
|
24168
|
+
});
|
|
23980
24169
|
var BODY_RETENTION_DEFAULT_DAYS = 30;
|
|
23981
24170
|
var BodyRetention = external_exports.object({
|
|
23982
24171
|
enabled: external_exports.boolean().default(false),
|
|
@@ -24035,6 +24224,16 @@ var WorkspaceSettings = external_exports.object({
|
|
|
24035
24224
|
// both widenings. Absent until granted, and a grant for a different endpoint
|
|
24036
24225
|
// or an older payload no longer counts.
|
|
24037
24226
|
historySyncConsent: HistorySyncConsent.optional(),
|
|
24227
|
+
// What the browser extension may record from a web chat, and the grant that
|
|
24228
|
+
// authorizes it. Absent until the user answers: recording something that was
|
|
24229
|
+
// never recorded before is never an assumed grant on upgrade, so the whole
|
|
24230
|
+
// block is optional rather than defaulted in. What an absent block means is
|
|
24231
|
+
// webChatCaptureOf's answer, in one place.
|
|
24232
|
+
//
|
|
24233
|
+
// Enforcement is NOT gated on this. A machine that has never answered still
|
|
24234
|
+
// blocks, redacts and warns on what a user sends; the grant covers what is
|
|
24235
|
+
// written down.
|
|
24236
|
+
webChatCapture: WebChatCapture.optional(),
|
|
24038
24237
|
// Local body expiry (see BodyRetention). Off until switched on; expiring a
|
|
24039
24238
|
// body never removes the row or its findings.
|
|
24040
24239
|
bodyRetention: BodyRetention.default({
|
|
@@ -24142,7 +24341,10 @@ function toCaptureAttributes(event) {
|
|
|
24142
24341
|
// `.catchall(z.unknown())` carries the long tail.
|
|
24143
24342
|
...metadata?.model !== void 0 ? { model: metadata.model } : {},
|
|
24144
24343
|
...metadata?.turnIndex !== void 0 ? { turn_index: metadata.turnIndex } : {},
|
|
24145
|
-
|
|
24344
|
+
// A blank id is omitted rather than stored: it is a join key and `''` joins
|
|
24345
|
+
// nothing. This runs on the local write path, which types the event but
|
|
24346
|
+
// never parses it, so EventMetadata's own `.min(1)` does not reach here.
|
|
24347
|
+
...metadata?.messageId !== void 0 && metadata.messageId !== "" ? { message_id: metadata.messageId } : {},
|
|
24146
24348
|
...metadata?.conversationId !== void 0 ? { conversation_id: metadata.conversationId } : {}
|
|
24147
24349
|
};
|
|
24148
24350
|
}
|
|
@@ -24516,12 +24718,14 @@ var RecommendedActionIdParam = external_exports.object({ id: external_exports.st
|
|
|
24516
24718
|
// ../../packages/schema/src/zod/settings-action.ts
|
|
24517
24719
|
var HistorySyncConsentChoice = external_exports.enum(["granted", "revoked", "unchanged"]).meta({ id: "HistorySyncConsentChoice" });
|
|
24518
24720
|
var ModelJudgeConsentChoice = external_exports.enum(["granted", "revoked", "unchanged"]).meta({ id: "ModelJudgeConsentChoice" });
|
|
24721
|
+
var WebChatCaptureConsentChoice = external_exports.enum(["granted", "revoked", "unchanged"]).meta({ id: "WebChatCaptureConsentChoice" });
|
|
24519
24722
|
var SaveSettingsInput = external_exports.object({
|
|
24520
24723
|
historicalAccess: external_exports.string(),
|
|
24521
24724
|
modelJudgeConsent: ModelJudgeConsentChoice,
|
|
24522
24725
|
historySyncConsent: HistorySyncConsentChoice,
|
|
24523
24726
|
vaultConsent: external_exports.string(),
|
|
24524
24727
|
vaultInlineReveal: external_exports.string(),
|
|
24728
|
+
webChatCaptureConsent: WebChatCaptureConsentChoice,
|
|
24525
24729
|
// Widened to `string` like its neighbours rather than typed as
|
|
24526
24730
|
// `RedactFallback`, on this module's own layering rule: shape here, VALUE at
|
|
24527
24731
|
// the call site, so the domain check receives the type it was written for.
|
|
@@ -24736,11 +24940,24 @@ var WebExchange = external_exports.object({
|
|
|
24736
24940
|
turnIndex: external_exports.number().int().nonnegative().optional(),
|
|
24737
24941
|
toolCalls: external_exports.array(WebToolCall).default([]),
|
|
24738
24942
|
// Absent when the adapter recovered no text. Capped by the caller at
|
|
24739
|
-
// RESPONSE_TEXT_MAX_BYTES
|
|
24740
|
-
//
|
|
24943
|
+
// RESPONSE_TEXT_MAX_BYTES, so a short capture is never mistaken for a short
|
|
24944
|
+
// reply.
|
|
24741
24945
|
responseText: external_exports.string().optional(),
|
|
24946
|
+
// The stored text is short of the reply. It does NOT say which of the two
|
|
24947
|
+
// ceilings on this path cut it: the caller applies its own cap on the raw
|
|
24948
|
+
// bytes it reads off the wire, which can be reached by a stream whose
|
|
24949
|
+
// recovered text stays well under RESPONSE_TEXT_MAX_BYTES, and applies that
|
|
24950
|
+
// one to the text. A reader cannot tell them apart, and nothing downstream
|
|
24951
|
+
// should branch as though it could.
|
|
24742
24952
|
truncated: external_exports.boolean().default(false)
|
|
24743
24953
|
});
|
|
24954
|
+
var WebEnforcementState = external_exports.enum([
|
|
24955
|
+
"watching",
|
|
24956
|
+
"composer-only",
|
|
24957
|
+
"button-only",
|
|
24958
|
+
"unattached",
|
|
24959
|
+
"unknown"
|
|
24960
|
+
]);
|
|
24744
24961
|
var RESPONSE_TEXT_MAX_BYTES = 2 * 1024 * 1024;
|
|
24745
24962
|
var WebCaptureStatus = external_exports.object({
|
|
24746
24963
|
patched: external_exports.boolean(),
|
|
@@ -24752,8 +24969,66 @@ var WebCaptureStatus = external_exports.object({
|
|
|
24752
24969
|
unparsedBodies: external_exports.number().int().nonnegative(),
|
|
24753
24970
|
// The adapter-declared JSON key paths that were absent from a real payload —
|
|
24754
24971
|
// the earliest signal that a site's contract moved.
|
|
24755
|
-
shapeMisses: external_exports.array(external_exports.string()).default([])
|
|
24756
|
-
|
|
24972
|
+
shapeMisses: external_exports.array(external_exports.string()).default([]),
|
|
24973
|
+
// How many `kind: 'conversation'` endpoints the reporting tab's adapter
|
|
24974
|
+
// compiled. Zero means this build declares none for the site, so observing
|
|
24975
|
+
// nothing is the design rather than a fault — the one fact that separates a
|
|
24976
|
+
// site nobody has surveyed yet from one whose contract moved. Defaulted so a
|
|
24977
|
+
// build predating the field is read as declaring nothing rather than refused.
|
|
24978
|
+
conversationEndpoints: external_exports.number().int().nonnegative().default(0),
|
|
24979
|
+
// The document that sent this report is going away. The bridge sets it on
|
|
24980
|
+
// its `pagehide` report and nowhere else.
|
|
24981
|
+
//
|
|
24982
|
+
// A property of the REPORT rather than of capture health, which is why
|
|
24983
|
+
// nothing in `deriveWebCaptureState` reads it and why it stays out of the
|
|
24984
|
+
// bridge's own report signature — a closing tab's last word must not be
|
|
24985
|
+
// suppressed for carrying the same health as the report before it. What
|
|
24986
|
+
// reads it is the per-site fold: a document that said it was unloading stops
|
|
24987
|
+
// voting on the site's state, so the reload the `blind` remediation asks for
|
|
24988
|
+
// can actually clear the verdict it was shown. A document that dies without
|
|
24989
|
+
// sending one is covered by CAPTURE_STATUS_DOCUMENT_QUIET_MS instead.
|
|
24990
|
+
//
|
|
24991
|
+
// Defaulted so a build predating the field reads as a document that never
|
|
24992
|
+
// said it was closing — which keeps it voting, the same as every report that
|
|
24993
|
+
// is not a final one.
|
|
24994
|
+
closed: external_exports.boolean().default(false),
|
|
24995
|
+
// What the DOM enforcement path is doing, which none of the counters above
|
|
24996
|
+
// can say: `sendsSeenDom` rises only once a send has COMPLETED, so a tab
|
|
24997
|
+
// whose watcher never bound reports zero exactly like a tab nobody typed in.
|
|
24998
|
+
// Defaulted to 'unknown' rather than 'watching' so a status from a build
|
|
24999
|
+
// predating the field is not read as reporting a healthy one.
|
|
25000
|
+
enforcement: WebEnforcementState.default("unknown")
|
|
25001
|
+
});
|
|
25002
|
+
function webCaptureStatusObservedTurnPath(status) {
|
|
25003
|
+
if (!status.patched) return true;
|
|
25004
|
+
if (status.conversationEndpoints === 0) return true;
|
|
25005
|
+
return status.blind || status.shapeMisses.length > 0 || status.parseFailures > 0 || status.unparsedBodies > 0 || status.exchangesSeenNet > 0;
|
|
25006
|
+
}
|
|
25007
|
+
function pickReportedCaptureStatus(candidates) {
|
|
25008
|
+
return candidates.find((c) => webCaptureStatusObservedTurnPath(c.status)) ?? candidates[0];
|
|
25009
|
+
}
|
|
25010
|
+
var CAPTURE_STATUS_RECENCY_MS = 30 * 24 * 60 * 60 * 1e3;
|
|
25011
|
+
var CAPTURE_STATUS_RECENCY_DAYS = CAPTURE_STATUS_RECENCY_MS / (24 * 60 * 60 * 1e3);
|
|
25012
|
+
var CAPTURE_STATUS_DOCUMENT_QUIET_MS = 12 * 60 * 60 * 1e3;
|
|
25013
|
+
function fromCaptureStatusAttributes(bag) {
|
|
25014
|
+
const parsedBag = CaptureStatusAttributes.safeParse(bag);
|
|
25015
|
+
if (!parsedBag.success) return null;
|
|
25016
|
+
const b = parsedBag.data;
|
|
25017
|
+
const parsedStatus = WebCaptureStatus.safeParse({
|
|
25018
|
+
patched: b.patched,
|
|
25019
|
+
live: b.live,
|
|
25020
|
+
blind: b.blind,
|
|
25021
|
+
sendsSeenDom: b.sends_seen_dom,
|
|
25022
|
+
exchangesSeenNet: b.exchanges_seen_net,
|
|
25023
|
+
parseFailures: b.parse_failures,
|
|
25024
|
+
unparsedBodies: b.unparsed_bodies,
|
|
25025
|
+
shapeMisses: b.shape_misses,
|
|
25026
|
+
conversationEndpoints: b.conversation_endpoints,
|
|
25027
|
+
closed: b.closed,
|
|
25028
|
+
enforcement: b.enforcement
|
|
25029
|
+
});
|
|
25030
|
+
return parsedStatus.success ? parsedStatus.data : null;
|
|
25031
|
+
}
|
|
24757
25032
|
|
|
24758
25033
|
// ../../packages/persistence/src/paths.ts
|
|
24759
25034
|
import {
|
|
@@ -24864,17 +25139,6 @@ function publishByLink(tmp, file2, data) {
|
|
|
24864
25139
|
function controlPlaneCredentialPath(settingsDir2) {
|
|
24865
25140
|
return join2(settingsDir2, ATTACHED_CREDENTIAL_FILENAME);
|
|
24866
25141
|
}
|
|
24867
|
-
var LOOPBACK_HOSTS = /* @__PURE__ */ new Set(["localhost", "127.0.0.1", "::1", "[::1]"]);
|
|
24868
|
-
function isSafeEndpoint(endpoint) {
|
|
24869
|
-
let parsed2;
|
|
24870
|
-
try {
|
|
24871
|
-
parsed2 = new URL(endpoint);
|
|
24872
|
-
} catch {
|
|
24873
|
-
return false;
|
|
24874
|
-
}
|
|
24875
|
-
if (parsed2.protocol === "https:") return true;
|
|
24876
|
-
return parsed2.protocol === "http:" && LOOPBACK_HOSTS.has(parsed2.hostname);
|
|
24877
|
-
}
|
|
24878
25142
|
function repairOrRefuseMode(file2) {
|
|
24879
25143
|
const link = lstatSync2(file2, { throwIfNoEntry: false });
|
|
24880
25144
|
if (link === void 0) return "absent";
|
|
@@ -26661,7 +26925,7 @@ var SESSION_ROOT = `event_type = 'session'`;
|
|
|
26661
26925
|
var HAS_ACTIVITY = `EXISTS (
|
|
26662
26926
|
SELECT 1 FROM audit_events c
|
|
26663
26927
|
WHERE c.root_session_id = audit_events.id
|
|
26664
|
-
AND c.event_type NOT IN ('hook', 'config_scan'))`;
|
|
26928
|
+
AND c.event_type NOT IN ('hook', 'config_scan', 'capture_status'))`;
|
|
26665
26929
|
var SqliteActivityRepository = class {
|
|
26666
26930
|
constructor(db, now = () => Date.now()) {
|
|
26667
26931
|
this.db = db;
|
|
@@ -26688,10 +26952,10 @@ var SqliteActivityRepository = class {
|
|
|
26688
26952
|
SELECT id FROM audit_events WHERE event_type = 'session' AND started_at >= ?
|
|
26689
26953
|
UNION
|
|
26690
26954
|
SELECT root_session_id FROM audit_events INDEXED BY idx_audit_started_at
|
|
26691
|
-
WHERE started_at >= ?
|
|
26955
|
+
WHERE started_at >= ? AND event_type <> 'capture_status'
|
|
26692
26956
|
UNION
|
|
26693
26957
|
SELECT root_session_id FROM audit_events INDEXED BY idx_audit_ended_at
|
|
26694
|
-
WHERE ended_at >= ?)`,
|
|
26958
|
+
WHERE ended_at >= ? AND event_type <> 'capture_status')`,
|
|
26695
26959
|
[liveThreshold, liveThreshold, liveThreshold]
|
|
26696
26960
|
);
|
|
26697
26961
|
const toolCallsToday = countScalar(
|
|
@@ -27098,7 +27362,10 @@ var SqliteAuditEventsRepository = class {
|
|
|
27098
27362
|
attributes = excluded.attributes,
|
|
27099
27363
|
ended_at = excluded.ended_at
|
|
27100
27364
|
WHERE COALESCE(json_extract(excluded.attributes, '$.output_tokens'), 0)
|
|
27101
|
-
> COALESCE(json_extract(audit_events.attributes, '$.output_tokens'), 0)
|
|
27365
|
+
> COALESCE(json_extract(audit_events.attributes, '$.output_tokens'), 0)
|
|
27366
|
+
OR (json_extract(excluded.attributes, '$.usage_source') IS NOT NULL
|
|
27367
|
+
AND json_extract(excluded.attributes, '$.output_tokens') IS NULL
|
|
27368
|
+
AND excluded.attributes <> audit_events.attributes)`
|
|
27102
27369
|
);
|
|
27103
27370
|
this.upsertSessionRootStmt = db.prepare(
|
|
27104
27371
|
`INSERT OR IGNORE INTO audit_events
|
|
@@ -27366,6 +27633,87 @@ var SqliteBodyRetentionRepository = class {
|
|
|
27366
27633
|
}
|
|
27367
27634
|
};
|
|
27368
27635
|
|
|
27636
|
+
// ../../packages/persistence/src/repositories/capture-status.ts
|
|
27637
|
+
var STATUS_LOOKBACK_ROWS = 128;
|
|
27638
|
+
var SqliteCaptureStatusRepository = class {
|
|
27639
|
+
constructor(db) {
|
|
27640
|
+
this.db = db;
|
|
27641
|
+
this.recentStmt = db.prepare(
|
|
27642
|
+
`SELECT a.started_at AS startedAt,
|
|
27643
|
+
a.attributes AS attributes,
|
|
27644
|
+
a.root_session_id AS rootSessionId
|
|
27645
|
+
FROM audit_events a
|
|
27646
|
+
WHERE a.event_type = 'capture_status'
|
|
27647
|
+
AND a.source_tool = ?
|
|
27648
|
+
AND a.started_at >= ?
|
|
27649
|
+
ORDER BY a.started_at DESC, a.id DESC
|
|
27650
|
+
LIMIT ?`
|
|
27651
|
+
);
|
|
27652
|
+
}
|
|
27653
|
+
db;
|
|
27654
|
+
recentStmt;
|
|
27655
|
+
/**
|
|
27656
|
+
* Every document that reported for a site, in registry order by site, from
|
|
27657
|
+
* the last `CAPTURE_STATUS_RECENCY_MS`.
|
|
27658
|
+
*
|
|
27659
|
+
* SEVERAL per site, not one: a browser is many documents and each reports
|
|
27660
|
+
* for itself, so one row per site is a choice about which of them a user
|
|
27661
|
+
* sees — and the newest is the wrong one, since a healthy tab writing a
|
|
27662
|
+
* fresh report would hide a drifting tab's verdict, which is the whole
|
|
27663
|
+
* reason these rows exist. The pick WITHIN a document is made here (the
|
|
27664
|
+
* unchanged `pickReportedCaptureStatus`, over that document's own rows);
|
|
27665
|
+
* choosing between documents belongs where the state semantics live, and
|
|
27666
|
+
* that is `reportedCaptureDocumentForSite` in `@akasecurity/detections` —
|
|
27667
|
+
* this package may not import it.
|
|
27668
|
+
*
|
|
27669
|
+
* `now` is a required argument rather than a `Date.now()` read, so a caller
|
|
27670
|
+
* that already holds a render instant passes THAT one and a test can drive
|
|
27671
|
+
* the window without moving the wall clock.
|
|
27672
|
+
*
|
|
27673
|
+
* A site whose reports have all aged out contributes nothing, so it derives
|
|
27674
|
+
* to `unreported`. That is the point: nothing but the browser extension ever
|
|
27675
|
+
* writes these rows, so an uninstalled extension's last verdict would
|
|
27676
|
+
* otherwise stand as a live claim for ever with no later report able to
|
|
27677
|
+
* clear it.
|
|
27678
|
+
*/
|
|
27679
|
+
latest(now) {
|
|
27680
|
+
const since = now - CAPTURE_STATUS_RECENCY_MS;
|
|
27681
|
+
const documents = [];
|
|
27682
|
+
for (const tool of WebSourceTool.options) {
|
|
27683
|
+
const rows = /* @__PURE__ */ new Map();
|
|
27684
|
+
const lastWord = /* @__PURE__ */ new Map();
|
|
27685
|
+
for (const row of allRows(this.recentStmt, [
|
|
27686
|
+
tool,
|
|
27687
|
+
since,
|
|
27688
|
+
STATUS_LOOKBACK_ROWS
|
|
27689
|
+
])) {
|
|
27690
|
+
const status = fromCaptureStatusAttributes(parseJsonObject(row.attributes));
|
|
27691
|
+
if (status === null) continue;
|
|
27692
|
+
const record2 = { tool, observedAt: epochMillisToIso(row.startedAt), status };
|
|
27693
|
+
const group = rows.get(row.rootSessionId);
|
|
27694
|
+
if (group === void 0) {
|
|
27695
|
+
rows.set(row.rootSessionId, [record2]);
|
|
27696
|
+
lastWord.set(row.rootSessionId, { at: record2.observedAt, closed: status.closed });
|
|
27697
|
+
} else {
|
|
27698
|
+
group.push(record2);
|
|
27699
|
+
}
|
|
27700
|
+
}
|
|
27701
|
+
for (const [root, candidates] of rows) {
|
|
27702
|
+
const picked = pickReportedCaptureStatus(candidates);
|
|
27703
|
+
const last = lastWord.get(root);
|
|
27704
|
+
if (picked === void 0 || last === void 0) continue;
|
|
27705
|
+
documents.push({
|
|
27706
|
+
...picked,
|
|
27707
|
+
...root === null ? {} : { rootSessionId: root },
|
|
27708
|
+
lastReportAt: last.at,
|
|
27709
|
+
closed: last.closed
|
|
27710
|
+
});
|
|
27711
|
+
}
|
|
27712
|
+
}
|
|
27713
|
+
return documents;
|
|
27714
|
+
}
|
|
27715
|
+
};
|
|
27716
|
+
|
|
27369
27717
|
// ../../packages/persistence/src/repositories/classified-data.ts
|
|
27370
27718
|
var SqliteClassifiedDataRepository = class {
|
|
27371
27719
|
constructor(db) {
|
|
@@ -32946,6 +33294,7 @@ function openAndInitialize(file2, base, skipTags) {
|
|
|
32946
33294
|
activity: new SqliteActivityRepository(db),
|
|
32947
33295
|
sourceProject: new SqliteSourceProjectRepository(db),
|
|
32948
33296
|
auditEvents: new SqliteAuditEventsRepository(db),
|
|
33297
|
+
captureStatus: new SqliteCaptureStatusRepository(db),
|
|
32949
33298
|
classifiedData: new SqliteClassifiedDataRepository(db),
|
|
32950
33299
|
inspectionDefinitions: new SqliteInspectionDefinitionsRepository(db),
|
|
32951
33300
|
inspectionFindings: new SqliteInspectionFindingsRepository(db),
|
|
@@ -32986,6 +33335,7 @@ function openLocalDatabase(dir, options = {}) {
|
|
|
32986
33335
|
activity,
|
|
32987
33336
|
sourceProject,
|
|
32988
33337
|
auditEvents,
|
|
33338
|
+
captureStatus,
|
|
32989
33339
|
classifiedData,
|
|
32990
33340
|
inspectionDefinitions,
|
|
32991
33341
|
inspectionFindings,
|
|
@@ -33203,6 +33553,7 @@ function openLocalDatabase(dir, options = {}) {
|
|
|
33203
33553
|
activity,
|
|
33204
33554
|
sourceProject,
|
|
33205
33555
|
auditEvents,
|
|
33556
|
+
captureStatus,
|
|
33206
33557
|
classifiedData,
|
|
33207
33558
|
inspectionDefinitions,
|
|
33208
33559
|
inspectionFindings,
|
|
@@ -33337,11 +33688,6 @@ function readFingerprintKey(dataDir2) {
|
|
|
33337
33688
|
// ../../packages/persistence/src/forward-health.ts
|
|
33338
33689
|
import { readFileSync as readFileSync7 } from "fs";
|
|
33339
33690
|
import { join as join9 } from "path";
|
|
33340
|
-
var FAILURES = /* @__PURE__ */ new Set([
|
|
33341
|
-
"unauthorized",
|
|
33342
|
-
"forbidden",
|
|
33343
|
-
"unreachable"
|
|
33344
|
-
]);
|
|
33345
33691
|
var BREAKER_COOLDOWN_MS = 3e4;
|
|
33346
33692
|
function parseForwardHealth(raw, nowMs) {
|
|
33347
33693
|
try {
|
|
@@ -33350,7 +33696,8 @@ function parseForwardHealth(raw, nowMs) {
|
|
|
33350
33696
|
const record2 = parsed2;
|
|
33351
33697
|
const failures = typeof record2.consecutiveFailures === "number" && record2.consecutiveFailures >= 0 ? record2.consecutiveFailures : 0;
|
|
33352
33698
|
const openedAtMs = typeof record2.openedAtMs === "number" && Number.isFinite(record2.openedAtMs) && record2.openedAtMs <= nowMs ? record2.openedAtMs : null;
|
|
33353
|
-
const
|
|
33699
|
+
const parsedFailure = ControlPlaneFailure.safeParse(record2.lastFailure);
|
|
33700
|
+
const lastFailure = parsedFailure.success ? parsedFailure.data : null;
|
|
33354
33701
|
return { consecutiveFailures: failures, openedAtMs, lastFailure };
|
|
33355
33702
|
} catch {
|
|
33356
33703
|
return null;
|
|
@@ -33487,6 +33834,12 @@ var RemoteRequestInvalid = class extends Error {
|
|
|
33487
33834
|
}
|
|
33488
33835
|
cause;
|
|
33489
33836
|
};
|
|
33837
|
+
var RemoteEndpointRefused = class extends Error {
|
|
33838
|
+
constructor(endpoint) {
|
|
33839
|
+
super(`refusing to talk to an unsafe control-plane endpoint: ${originOnly(endpoint)}`);
|
|
33840
|
+
this.name = "RemoteEndpointRefused";
|
|
33841
|
+
}
|
|
33842
|
+
};
|
|
33490
33843
|
var RemoteResponseInvalid = class extends Error {
|
|
33491
33844
|
constructor(route, detail) {
|
|
33492
33845
|
super(`control plane answered ${route} with ${detail}`);
|
|
@@ -33639,14 +33992,15 @@ function parsed(schema, body, route) {
|
|
|
33639
33992
|
}
|
|
33640
33993
|
return result.data;
|
|
33641
33994
|
}
|
|
33642
|
-
function
|
|
33995
|
+
function resolveBaseUrl(endpoint) {
|
|
33996
|
+
if (!isSafeEndpoint(endpoint)) throw new RemoteEndpointRefused(endpoint);
|
|
33643
33997
|
let end = endpoint.length;
|
|
33644
33998
|
while (end > 0 && endpoint.charCodeAt(end - 1) === SLASH2) end -= 1;
|
|
33645
33999
|
return endpoint.slice(0, end);
|
|
33646
34000
|
}
|
|
33647
34001
|
var SLASH2 = "/".charCodeAt(0);
|
|
33648
34002
|
function createRemoteClient(options) {
|
|
33649
|
-
const base =
|
|
34003
|
+
const base = resolveBaseUrl(options.endpoint);
|
|
33650
34004
|
const url2 = (route) => `${base}${route}`;
|
|
33651
34005
|
const common = { apiKey: options.apiKey, timeoutMs: options.timeoutMs };
|
|
33652
34006
|
const sendOne = async (event) => {
|
|
@@ -33776,6 +34130,7 @@ function classifyRemoteFailure(err) {
|
|
|
33776
34130
|
case "RemoteRouteAbsent":
|
|
33777
34131
|
return "route-absent";
|
|
33778
34132
|
case "RemoteRequestInvalid":
|
|
34133
|
+
case "RemoteEndpointRefused":
|
|
33779
34134
|
return "invalid-request";
|
|
33780
34135
|
case "RemoteResponseInvalid":
|
|
33781
34136
|
return "rejected";
|
|
@@ -34974,6 +35329,56 @@ function whole(command) {
|
|
|
34974
35329
|
return { start: 0, end: command.length };
|
|
34975
35330
|
}
|
|
34976
35331
|
|
|
35332
|
+
// ../../packages/detections/src/posture/web-capture-posture.ts
|
|
35333
|
+
var RULE_VERSION2 = "1";
|
|
35334
|
+
var DRIFT_MIN_PARSE_FAILURES = 2;
|
|
35335
|
+
var WEB_CAPTURE_DRIFT_STATES = /* @__PURE__ */ new Set([
|
|
35336
|
+
"blind",
|
|
35337
|
+
"degraded"
|
|
35338
|
+
]);
|
|
35339
|
+
var WEB_CAPTURE_DRIFT_RULE = {
|
|
35340
|
+
ruleId: "web-capture-drift",
|
|
35341
|
+
version: RULE_VERSION2,
|
|
35342
|
+
name: "Web chat capture is not reading the site",
|
|
35343
|
+
category: "config",
|
|
35344
|
+
severity: "medium",
|
|
35345
|
+
definition: JSON.stringify({
|
|
35346
|
+
kind: "web-capture-drift",
|
|
35347
|
+
states: [...WEB_CAPTURE_DRIFT_STATES],
|
|
35348
|
+
minParseFailures: DRIFT_MIN_PARSE_FAILURES
|
|
35349
|
+
})
|
|
35350
|
+
};
|
|
35351
|
+
var STATIC_COPY = {
|
|
35352
|
+
active: { headline: "turns are being observed on this site" },
|
|
35353
|
+
unreported: {
|
|
35354
|
+
// Says "recently" rather than "yet": the store read is bounded to
|
|
35355
|
+
// CAPTURE_STATUS_RECENCY_MS, so this state covers a site nothing has ever
|
|
35356
|
+
// reported for AND one whose last report has aged out. The two are the
|
|
35357
|
+
// same fact to a reader — nobody has confirmed anything lately — and the
|
|
35358
|
+
// copy may not claim the stronger of them.
|
|
35359
|
+
headline: `no report in the last ${String(CAPTURE_STATUS_RECENCY_DAYS)} days \u2014 open the site in Chrome with the extension loaded`
|
|
35360
|
+
},
|
|
35361
|
+
standby: {
|
|
35362
|
+
headline: "this build declares no endpoints for the site, so nothing is observed yet"
|
|
35363
|
+
},
|
|
35364
|
+
unpatched: {
|
|
35365
|
+
// Says what the flags say and no more. `patched` is false both for a tap
|
|
35366
|
+
// that installed and hooked neither transport and for one that never ran
|
|
35367
|
+
// at all — a page reports the same status either way, so the copy may not
|
|
35368
|
+
// assert one of them.
|
|
35369
|
+
headline: "the page tap captured neither fetch nor XHR \u2014 it may not have installed; reload the extension at chrome://extensions"
|
|
35370
|
+
},
|
|
35371
|
+
idle: { headline: "watching; no turn has been observed yet" },
|
|
35372
|
+
blind: {
|
|
35373
|
+
headline: "messages were sent in the page that the network capture never saw",
|
|
35374
|
+
remediation: "reload the tab. If it persists after `aka update` and reloading the extension at chrome://extensions, the site's send path has changed and needs a new extension build."
|
|
35375
|
+
},
|
|
35376
|
+
degraded: {
|
|
35377
|
+
headline: "the site's payloads no longer carry the fields the extension reads",
|
|
35378
|
+
remediation: "run `aka update`, then reload the extension at chrome://extensions. If it stays degraded after an update, the site's contract has changed and needs a new extension build."
|
|
35379
|
+
}
|
|
35380
|
+
};
|
|
35381
|
+
|
|
34977
35382
|
// ../../packages/detections/src/security/redos-probe.ts
|
|
34978
35383
|
var BUDGET_MS = 100;
|
|
34979
35384
|
var EXPONENTIAL_UNITS = [
|
|
@@ -38151,86 +38556,10 @@ function createForwardPolicy(deps) {
|
|
|
38151
38556
|
}
|
|
38152
38557
|
|
|
38153
38558
|
// ../../packages/plugin-runtime/src/attached/gateway.ts
|
|
38154
|
-
|
|
38155
|
-
|
|
38156
|
-
|
|
38157
|
-
return
|
|
38158
|
-
}
|
|
38159
|
-
function ruleCategoryMap(wireRules, localRules) {
|
|
38160
|
-
const map2 = /* @__PURE__ */ new Map();
|
|
38161
|
-
for (const rule of wireRules ?? []) map2.set(rule.id, rule.category);
|
|
38162
|
-
for (const rule of localRules ?? []) map2.set(rule.id, rule.category);
|
|
38163
|
-
for (const pack of bundledDetections()) {
|
|
38164
|
-
for (const rule of pack.rules) map2.set(rule.id, rule.category);
|
|
38165
|
-
}
|
|
38166
|
-
return map2;
|
|
38167
|
-
}
|
|
38168
|
-
function policyKey(policy) {
|
|
38169
|
-
return "ruleId" in policy.target ? `rule:${policy.target.ruleId}` : `category:${policy.target.category}`;
|
|
38170
|
-
}
|
|
38171
|
-
function floorFor(policy, categoryByRuleId) {
|
|
38172
|
-
const category = "category" in policy.target ? policy.target.category : categoryByRuleId.get(policy.target.ruleId);
|
|
38173
|
-
return category === void 0 ? null : DEFAULT_ACTIONS[category];
|
|
38174
|
-
}
|
|
38175
|
-
function mergeRaiseOnly(localPolicies, remotePolicies, categoryByRuleId) {
|
|
38176
|
-
const merged = /* @__PURE__ */ new Map();
|
|
38177
|
-
const disabled = [];
|
|
38178
|
-
const remoteCategoryAction = /* @__PURE__ */ new Map();
|
|
38179
|
-
for (const policy of remotePolicies) {
|
|
38180
|
-
if (!policy.enabled) continue;
|
|
38181
|
-
if (!("category" in policy.target)) continue;
|
|
38182
|
-
if (remoteCategoryAction.has(policy.target.category)) continue;
|
|
38183
|
-
const floor = floorFor(policy, categoryByRuleId);
|
|
38184
|
-
remoteCategoryAction.set(
|
|
38185
|
-
policy.target.category,
|
|
38186
|
-
floor !== null && !isActionAtLeast(policy.action, floor) ? floor : policy.action
|
|
38187
|
-
);
|
|
38188
|
-
}
|
|
38189
|
-
for (const policy of localPolicies) {
|
|
38190
|
-
if (!policy.enabled) {
|
|
38191
|
-
disabled.push(policy);
|
|
38192
|
-
continue;
|
|
38193
|
-
}
|
|
38194
|
-
const key = policyKey(policy);
|
|
38195
|
-
if (merged.has(key)) continue;
|
|
38196
|
-
let remoteFloor = null;
|
|
38197
|
-
if ("ruleId" in policy.target) {
|
|
38198
|
-
const category = categoryByRuleId.get(policy.target.ruleId);
|
|
38199
|
-
if (category !== void 0) remoteFloor = remoteCategoryAction.get(category) ?? null;
|
|
38200
|
-
}
|
|
38201
|
-
merged.set(
|
|
38202
|
-
key,
|
|
38203
|
-
remoteFloor !== null && !isActionAtLeast(policy.action, remoteFloor) ? { ...policy, action: remoteFloor } : policy
|
|
38204
|
-
);
|
|
38205
|
-
}
|
|
38206
|
-
const localCategoryAction = /* @__PURE__ */ new Map();
|
|
38207
|
-
for (const policy of merged.values()) {
|
|
38208
|
-
if ("category" in policy.target) localCategoryAction.set(policy.target.category, policy.action);
|
|
38209
|
-
}
|
|
38210
|
-
for (const policy of remotePolicies) {
|
|
38211
|
-
if (!policy.enabled) {
|
|
38212
|
-
disabled.push(policy);
|
|
38213
|
-
continue;
|
|
38214
|
-
}
|
|
38215
|
-
const key = policyKey(policy);
|
|
38216
|
-
const floor = floorFor(policy, categoryByRuleId);
|
|
38217
|
-
let localFloor = null;
|
|
38218
|
-
if ("ruleId" in policy.target) {
|
|
38219
|
-
const category = categoryByRuleId.get(policy.target.ruleId);
|
|
38220
|
-
if (category !== void 0) localFloor = localCategoryAction.get(category) ?? null;
|
|
38221
|
-
}
|
|
38222
|
-
const effectiveFloor = strongerOf(floor, localFloor);
|
|
38223
|
-
const clamped = effectiveFloor !== null && !isActionAtLeast(policy.action, effectiveFloor) ? { ...policy, action: effectiveFloor } : policy;
|
|
38224
|
-
const existing = merged.get(key);
|
|
38225
|
-
if (existing === void 0) {
|
|
38226
|
-
merged.set(key, clamped);
|
|
38227
|
-
continue;
|
|
38228
|
-
}
|
|
38229
|
-
if (actionRank(clamped.action) > actionRank(existing.action)) {
|
|
38230
|
-
merged.set(key, clamped);
|
|
38231
|
-
}
|
|
38232
|
-
}
|
|
38233
|
-
return [...merged.values(), ...disabled];
|
|
38559
|
+
var bundledRulesFlatCache;
|
|
38560
|
+
function bundledRulesFlat() {
|
|
38561
|
+
bundledRulesFlatCache ??= bundledDetections().flatMap((pack) => pack.rules);
|
|
38562
|
+
return bundledRulesFlatCache;
|
|
38234
38563
|
}
|
|
38235
38564
|
var AttachedDataGateway = class {
|
|
38236
38565
|
constructor(deps) {
|
|
@@ -38550,6 +38879,9 @@ var AttachedDataGateway = class {
|
|
|
38550
38879
|
async readSessionProvider(sessionId) {
|
|
38551
38880
|
return this.deps.local.readSessionProvider(sessionId);
|
|
38552
38881
|
}
|
|
38882
|
+
async readCaptureStatuses() {
|
|
38883
|
+
return this.deps.local.readCaptureStatuses();
|
|
38884
|
+
}
|
|
38553
38885
|
async facets() {
|
|
38554
38886
|
return this.deps.local.facets();
|
|
38555
38887
|
}
|
|
@@ -38632,7 +38964,7 @@ var AttachedDataGateway = class {
|
|
|
38632
38964
|
policies: mergeRaiseOnly(
|
|
38633
38965
|
local.policies,
|
|
38634
38966
|
cached2.policies,
|
|
38635
|
-
ruleCategoryMap(cached2.rules, local.rules)
|
|
38967
|
+
ruleCategoryMap(cached2.rules, local.rules, bundledRulesFlat())
|
|
38636
38968
|
),
|
|
38637
38969
|
customKeywords: [...local.customKeywords, ...cached2.customKeywords],
|
|
38638
38970
|
// TAKEN FROM THE CACHE, unlike the two fields below — and the asymmetry
|
|
@@ -38872,10 +39204,15 @@ import { join as join27 } from "path";
|
|
|
38872
39204
|
// ../../packages/plugin-runtime/src/attached/atomic-publish.ts
|
|
38873
39205
|
import { rename as rename2 } from "fs/promises";
|
|
38874
39206
|
var RETRYABLE = /* @__PURE__ */ new Set(["EPERM", "EACCES", "EBUSY"]);
|
|
38875
|
-
var
|
|
39207
|
+
var IMMEDIATE_RETRIES = 8;
|
|
39208
|
+
var TIMED_RETRIES = 4;
|
|
39209
|
+
var ATTEMPTS = 1 + IMMEDIATE_RETRIES + TIMED_RETRIES;
|
|
38876
39210
|
var delay = (ms) => new Promise((resolve2) => {
|
|
38877
39211
|
setTimeout(resolve2, ms);
|
|
38878
39212
|
});
|
|
39213
|
+
var yieldToLoop = () => new Promise((resolve2) => {
|
|
39214
|
+
setImmediate(resolve2);
|
|
39215
|
+
});
|
|
38879
39216
|
async function publishByRename(tmp, file2, move = rename2) {
|
|
38880
39217
|
for (let attempt = 1; ; attempt += 1) {
|
|
38881
39218
|
try {
|
|
@@ -38884,7 +39221,7 @@ async function publishByRename(tmp, file2, move = rename2) {
|
|
|
38884
39221
|
} catch (err) {
|
|
38885
39222
|
const code = err.code;
|
|
38886
39223
|
if (attempt >= ATTEMPTS || code === void 0 || !RETRYABLE.has(code)) throw err;
|
|
38887
|
-
await delay(attempt * 10);
|
|
39224
|
+
await (attempt <= IMMEDIATE_RETRIES ? yieldToLoop() : delay((attempt - IMMEDIATE_RETRIES) * 10));
|
|
38888
39225
|
}
|
|
38889
39226
|
}
|
|
38890
39227
|
}
|
|
@@ -39392,6 +39729,9 @@ var StandaloneDataGateway = class {
|
|
|
39392
39729
|
readSessionProvider(sessionId) {
|
|
39393
39730
|
return Promise.resolve(this.db.auditEvents.sessionProvider(sessionId));
|
|
39394
39731
|
}
|
|
39732
|
+
readCaptureStatuses() {
|
|
39733
|
+
return Promise.resolve(this.db.captureStatus.latest(Date.now()));
|
|
39734
|
+
}
|
|
39395
39735
|
facets() {
|
|
39396
39736
|
return Promise.resolve(this.db.facets());
|
|
39397
39737
|
}
|