@cclabsnz/sf-audit 1.3.0 → 1.6.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.
Files changed (102) hide show
  1. package/README.md +193 -12
  2. package/lib/api/MetadataClient.d.ts +4 -0
  3. package/lib/api/MetadataClient.js +2 -0
  4. package/lib/api/MetadataClientImpl.d.ts +8 -0
  5. package/lib/api/MetadataClientImpl.js +22 -0
  6. package/lib/api/RestClient.d.ts +2 -0
  7. package/lib/api/RestClientImpl.d.ts +2 -0
  8. package/lib/api/RestClientImpl.js +33 -0
  9. package/lib/apps/analyzeApps.d.ts +8 -0
  10. package/lib/apps/analyzeApps.js +19 -0
  11. package/lib/apps/appResolver.d.ts +4 -0
  12. package/lib/apps/appResolver.js +50 -0
  13. package/lib/apps/grantedAccess.d.ts +4 -0
  14. package/lib/apps/grantedAccess.js +36 -0
  15. package/lib/apps/leastPrivilege.d.ts +6 -0
  16. package/lib/apps/leastPrivilege.js +47 -0
  17. package/lib/apps/renderApps.d.ts +5 -0
  18. package/lib/apps/renderApps.js +23 -0
  19. package/lib/apps/standardAppCatalog.d.ts +11 -0
  20. package/lib/apps/standardAppCatalog.js +14 -0
  21. package/lib/apps/types.d.ts +64 -0
  22. package/lib/apps/types.js +2 -0
  23. package/lib/apps/usageCollector.d.ts +9 -0
  24. package/lib/apps/usageCollector.js +104 -0
  25. package/lib/chains/CapabilityRegistry.js +19 -0
  26. package/lib/chains/namedChains.js +67 -0
  27. package/lib/checks/eventLogAccess.d.ts +14 -0
  28. package/lib/checks/eventLogAccess.js +33 -0
  29. package/lib/checks/impl/AgentActionSurfaceCheck.d.ts +13 -0
  30. package/lib/checks/impl/AgentActionSurfaceCheck.js +125 -0
  31. package/lib/checks/impl/AgentChannelExposureCheck.d.ts +15 -0
  32. package/lib/checks/impl/AgentChannelExposureCheck.js +223 -0
  33. package/lib/checks/impl/AgentInventoryCheck.d.ts +15 -0
  34. package/lib/checks/impl/AgentInventoryCheck.js +228 -0
  35. package/lib/checks/impl/AgentMonitoringCoverageCheck.d.ts +12 -0
  36. package/lib/checks/impl/AgentMonitoringCoverageCheck.js +97 -0
  37. package/lib/checks/impl/AgentUserPrivilegeCheck.d.ts +13 -0
  38. package/lib/checks/impl/AgentUserPrivilegeCheck.js +204 -0
  39. package/lib/checks/impl/AuthProvidersCheck.d.ts +17 -0
  40. package/lib/checks/impl/AuthProvidersCheck.js +88 -0
  41. package/lib/checks/impl/ClassicSitesCheck.d.ts +17 -0
  42. package/lib/checks/impl/ClassicSitesCheck.js +65 -0
  43. package/lib/checks/impl/CspTrustedSitesCheck.d.ts +1 -0
  44. package/lib/checks/impl/CspTrustedSitesCheck.js +10 -1
  45. package/lib/checks/impl/DataExportAccessCheck.d.ts +19 -0
  46. package/lib/checks/impl/DataExportAccessCheck.js +79 -0
  47. package/lib/checks/impl/EncryptionCoverageCheck.d.ts +19 -0
  48. package/lib/checks/impl/EncryptionCoverageCheck.js +108 -0
  49. package/lib/checks/impl/EventMonitoringCheck.js +8 -5
  50. package/lib/checks/impl/ExperienceCspCheck.d.ts +18 -0
  51. package/lib/checks/impl/ExperienceCspCheck.js +57 -0
  52. package/lib/checks/impl/ExternalCredentialsCheck.d.ts +17 -0
  53. package/lib/checks/impl/ExternalCredentialsCheck.js +74 -0
  54. package/lib/checks/impl/GuestApiAccessCheck.d.ts +19 -0
  55. package/lib/checks/impl/GuestApiAccessCheck.js +113 -0
  56. package/lib/checks/impl/GuestObjectExposureCheck.d.ts +44 -0
  57. package/lib/checks/impl/GuestObjectExposureCheck.js +241 -0
  58. package/lib/checks/impl/GuestRecordAccessPolicyCheck.d.ts +34 -0
  59. package/lib/checks/impl/GuestRecordAccessPolicyCheck.js +120 -0
  60. package/lib/checks/impl/GuestSiteOptionsCheck.d.ts +18 -0
  61. package/lib/checks/impl/GuestSiteOptionsCheck.js +92 -0
  62. package/lib/checks/impl/GuestTrafficAnomalyCheck.d.ts +23 -0
  63. package/lib/checks/impl/GuestTrafficAnomalyCheck.js +343 -0
  64. package/lib/checks/impl/LoginAccessPolicyCheck.d.ts +26 -0
  65. package/lib/checks/impl/LoginAccessPolicyCheck.js +117 -0
  66. package/lib/checks/impl/LoginAnomalyCheck.d.ts +17 -0
  67. package/lib/checks/impl/LoginAnomalyCheck.js +98 -0
  68. package/lib/checks/impl/SandboxDataMaskingCheck.d.ts +17 -0
  69. package/lib/checks/impl/SandboxDataMaskingCheck.js +85 -0
  70. package/lib/checks/impl/SessionHardeningCheck.d.ts +21 -0
  71. package/lib/checks/impl/SessionHardeningCheck.js +134 -0
  72. package/lib/checks/impl/ThreatDetectionCheck.d.ts +17 -0
  73. package/lib/checks/impl/ThreatDetectionCheck.js +91 -0
  74. package/lib/checks/impl/TrustedUrlHygieneCheck.d.ts +16 -0
  75. package/lib/checks/impl/TrustedUrlHygieneCheck.js +198 -0
  76. package/lib/checks/registry.js +52 -0
  77. package/lib/commands/audit/apps.d.ts +16 -0
  78. package/lib/commands/audit/apps.js +64 -0
  79. package/lib/commands/audit/diff.js +9 -5
  80. package/lib/commands/audit/events/pull.d.ts +17 -0
  81. package/lib/commands/audit/events/pull.js +88 -0
  82. package/lib/commands/audit/security.d.ts +5 -0
  83. package/lib/commands/audit/security.js +47 -17
  84. package/lib/compliance/catalogs/index.js +2 -0
  85. package/lib/compliance/catalogs/owaspLlm.d.ts +3 -0
  86. package/lib/compliance/catalogs/owaspLlm.js +34 -0
  87. package/lib/compliance/mapping.js +46 -7
  88. package/lib/compliance/resolve.js +4 -3
  89. package/lib/compliance/types.d.ts +1 -1
  90. package/lib/context/AuditCache.d.ts +31 -0
  91. package/lib/context/AuditContext.d.ts +6 -0
  92. package/lib/events/EventBaselineStore.d.ts +16 -0
  93. package/lib/events/EventBaselineStore.js +55 -0
  94. package/lib/events/eventLogQuery.d.ts +21 -0
  95. package/lib/events/eventLogQuery.js +34 -0
  96. package/lib/events/pullEventLogs.d.ts +51 -0
  97. package/lib/events/pullEventLogs.js +79 -0
  98. package/lib/findings/CheckMeta.js +22 -0
  99. package/lib/lib/wire.d.ts +4 -2
  100. package/lib/lib/wire.js +5 -1
  101. package/lib/renderers/ClientReportRenderer.js +1 -1
  102. package/package.json +16 -2
@@ -0,0 +1,11 @@
1
+ import type { AppCategory } from './types.js';
2
+ export interface StandardApp {
3
+ name: string;
4
+ category: AppCategory;
5
+ vendor: string;
6
+ purpose: string;
7
+ }
8
+ export declare const STANDARD_APPS: Record<string, StandardApp>;
9
+ /** Look up a connected-app id (15- or 18-char) in the bundled catalog. */
10
+ export declare function lookupStandardApp(appId: string): StandardApp | null;
11
+ //# sourceMappingURL=standardAppCatalog.d.ts.map
@@ -0,0 +1,14 @@
1
+ // Curated seed of common connected-app ids (15-char keys). Salesforce standard-app ids are
2
+ // stable across orgs; third-party ids are the ones observed in practice. Grow over time.
3
+ export const STANDARD_APPS = {
4
+ '0H44a00000000Ns': { name: 'Dataloader Bulk', category: 'Salesforce-standard', vendor: 'Salesforce', purpose: 'Bulk data import/export tool' },
5
+ '0H44a00000000Nt': { name: 'Dataloader Partner', category: 'Salesforce-standard', vendor: 'Salesforce', purpose: 'Data Loader (SOAP) tool' },
6
+ '0H44a00000000Nz': { name: 'Workbench', category: 'Salesforce-standard', vendor: 'Salesforce', purpose: 'Ad-hoc API/data tool' },
7
+ '0H44a00000000Nu': { name: 'Force.com IDE', category: 'Salesforce-standard', vendor: 'Salesforce', purpose: 'Developer tooling' },
8
+ };
9
+ /** Look up a connected-app id (15- or 18-char) in the bundled catalog. */
10
+ export function lookupStandardApp(appId) {
11
+ const key = appId.slice(0, 15);
12
+ return STANDARD_APPS[key] ?? null;
13
+ }
14
+ //# sourceMappingURL=standardAppCatalog.js.map
@@ -0,0 +1,64 @@
1
+ export type Verb = 'read' | 'write' | 'delete';
2
+ export type AppCategory = 'Salesforce-standard' | 'Org-custom' | 'Security-vendor' | 'Installed-package' | 'Third-party' | 'Unidentified';
3
+ export type ResolveConfidence = 'resolved' | 'inferred' | 'unidentified';
4
+ /** Observed usage for one connected app, derived from RestApi rows. */
5
+ export interface AppUsage {
6
+ appId: string;
7
+ objects: {
8
+ object: string;
9
+ verbs: Verb[];
10
+ }[];
11
+ requests: number;
12
+ rowsProcessed: number;
13
+ userIds: string[];
14
+ soapOnly: boolean;
15
+ }
16
+ export interface ResolvedApp {
17
+ appId: string;
18
+ name: string;
19
+ category: AppCategory;
20
+ vendor?: string;
21
+ purpose?: string;
22
+ confidence: ResolveConfidence;
23
+ }
24
+ export interface GrantedAccess {
25
+ appId: string;
26
+ scope: string | null;
27
+ objects: {
28
+ object: string;
29
+ verbs: Verb[];
30
+ }[];
31
+ runAsUsers: string[];
32
+ multiUserInteractive: boolean;
33
+ }
34
+ export interface AppFinding {
35
+ app: ResolvedApp;
36
+ window: {
37
+ since: number;
38
+ attributionRatePct: number;
39
+ };
40
+ used: AppUsage;
41
+ granted: GrantedAccess;
42
+ overGrant: {
43
+ unusedObjects: string[];
44
+ unusedVerbs: {
45
+ object: string;
46
+ verbs: Verb[];
47
+ }[];
48
+ scopeDowngrade: string | null;
49
+ dormant: boolean;
50
+ };
51
+ recommendation: {
52
+ permissionSet: {
53
+ objectPermissions: {
54
+ object: string;
55
+ read: boolean;
56
+ create: boolean;
57
+ edit: boolean;
58
+ delete: boolean;
59
+ }[];
60
+ };
61
+ };
62
+ notes: string[];
63
+ }
64
+ //# sourceMappingURL=types.d.ts.map
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=types.js.map
@@ -0,0 +1,9 @@
1
+ import type { AppUsage } from './types.js';
2
+ export interface UsageResult {
3
+ usage: AppUsage[];
4
+ totalRows: number;
5
+ attributedRows: number;
6
+ attributionRatePct: number;
7
+ }
8
+ export declare function collectUsage(restApiCsv: string, soapApiCsv?: string): UsageResult;
9
+ //# sourceMappingURL=usageCollector.d.ts.map
@@ -0,0 +1,104 @@
1
+ function parseCsv(text) {
2
+ const lines = text.split(/\r?\n/).filter((l) => l.length > 0);
3
+ if (lines.length === 0)
4
+ return [];
5
+ const header = splitCsvLine(lines[0]);
6
+ const headerToken = header[0]; // e.g. "EVENT_TYPE"
7
+ const rows = [];
8
+ for (const line of lines.slice(1)) {
9
+ // Skip embedded header rows (from multi-file concatenation) and blank lines.
10
+ const firstCell = splitCsvLine(line)[0];
11
+ if (firstCell === headerToken)
12
+ continue;
13
+ const cells = splitCsvLine(line);
14
+ const row = {};
15
+ header.forEach((h, i) => (row[h] = cells[i] ?? ''));
16
+ rows.push(row);
17
+ }
18
+ return rows;
19
+ }
20
+ // Minimal RFC-4180 line splitter (handles quoted cells; EventLogFile has no embedded newlines
21
+ // in these columns). Sufficient for API/RestApi logs.
22
+ function splitCsvLine(line) {
23
+ const out = [];
24
+ let cur = '';
25
+ let inq = false;
26
+ for (let i = 0; i < line.length; i++) {
27
+ const c = line[i];
28
+ if (inq) {
29
+ if (c === '"' && line[i + 1] === '"') {
30
+ cur += '"';
31
+ i++;
32
+ }
33
+ else if (c === '"')
34
+ inq = false;
35
+ else
36
+ cur += c;
37
+ }
38
+ else if (c === '"')
39
+ inq = true;
40
+ else if (c === ',') {
41
+ out.push(cur);
42
+ cur = '';
43
+ }
44
+ else
45
+ cur += c;
46
+ }
47
+ out.push(cur);
48
+ return out;
49
+ }
50
+ function verbOf(method) {
51
+ const m = method.toUpperCase();
52
+ if (m === 'DELETE')
53
+ return 'delete';
54
+ if (m === 'POST' || m === 'PATCH' || m === 'PUT')
55
+ return 'write';
56
+ return 'read';
57
+ }
58
+ export function collectUsage(restApiCsv, soapApiCsv) {
59
+ const rows = parseCsv(restApiCsv);
60
+ const byApp = new Map();
61
+ let attributed = 0;
62
+ for (const row of rows) {
63
+ const appId = row.CONNECTED_APP_ID ?? '';
64
+ if (!appId)
65
+ continue;
66
+ attributed++;
67
+ let a = byApp.get(appId);
68
+ if (!a) {
69
+ a = { objects: new Map(), requests: 0, rows: 0, users: new Set() };
70
+ byApp.set(appId, a);
71
+ }
72
+ a.requests++;
73
+ a.rows += Number(row.ROWS_PROCESSED) || 0;
74
+ if (row.USER_ID)
75
+ a.users.add(row.USER_ID);
76
+ const entity = row.ENTITY_NAME;
77
+ if (entity) {
78
+ const verbs = a.objects.get(entity) ?? new Set();
79
+ verbs.add(verbOf(row.METHOD ?? row.METHOD_NAME ?? 'GET'));
80
+ a.objects.set(entity, verbs);
81
+ }
82
+ }
83
+ const soapUsers = new Set();
84
+ if (soapApiCsv) {
85
+ for (const row of parseCsv(soapApiCsv))
86
+ if (row.USER_ID)
87
+ soapUsers.add(row.USER_ID);
88
+ }
89
+ const usage = [...byApp.entries()].map(([appId, a]) => ({
90
+ appId,
91
+ objects: [...a.objects.entries()].map(([object, verbs]) => ({ object, verbs: [...verbs].sort() })),
92
+ requests: a.requests,
93
+ rowsProcessed: a.rows,
94
+ userIds: [...a.users].sort(),
95
+ soapOnly: false,
96
+ }));
97
+ return {
98
+ usage: usage.sort((x, y) => y.requests - x.requests),
99
+ totalRows: rows.length,
100
+ attributedRows: attributed,
101
+ attributionRatePct: rows.length ? Math.round((100 * attributed) / rows.length) : 0,
102
+ };
103
+ }
104
+ //# sourceMappingURL=usageCollector.js.map
@@ -38,6 +38,25 @@ export const CAPABILITY_REGISTRY = {
38
38
  'cors-wildcard-origin': { grants: ['credential-theft'] },
39
39
  'cors-broad-origin': { grants: ['credential-theft'] },
40
40
  'escalation-perms-found': { grants: ['priv-esc'] },
41
+ // Guest bulk-read surface (UI-API reachable) — the confirmed exfiltration sink
42
+ 'guest-object-exposure-public-owd': { grants: ['unauth-foothold', 'data-read-bulk'] },
43
+ 'guest-object-exposure-guest-owned': { grants: ['unauth-foothold', 'data-read-bulk'] },
44
+ // Observed guest recon in EventLogFile — an active unauthenticated foothold
45
+ 'guest-traffic-anomaly-recon': { grants: ['unauth-foothold'] },
46
+ 'guest-traffic-anomaly-anonymizer': { grants: ['unauth-foothold'] },
47
+ // Guest API/Bulk access — programmatic unauthenticated bulk read / destruction
48
+ 'guest-api-access-enabled': { grants: ['unauth-foothold', 'data-read-bulk'] },
49
+ 'guest-api-hard-delete': { grants: ['unauth-foothold', 'data-write'] },
50
+ // Classic Visualforce sites — a second unauthenticated foothold surface
51
+ 'classic-sites-active': { grants: ['unauth-foothold'] },
52
+ // Mass data-export capability — a bulk-read sink for an authenticated actor
53
+ 'data-export-weekly-export': { grants: ['data-read-bulk'] },
54
+ 'data-export-bulk-api-viewall': { grants: ['data-read-bulk', 'data-write'] },
55
+ // Impersonation / delegated-admin escalation
56
+ 'login-access-policy-delegated-admins': { grants: ['priv-esc'] },
57
+ 'login-access-policy-login-as-enabled': { grants: ['priv-esc', 'data-read-bulk'] },
58
+ // External federation an attacker could ride in on
59
+ 'auth-providers-social': { grants: ['low-trust-authenticated'] },
41
60
  };
42
61
  /** Resolve the effective capabilities for a finding (inline overrides registry; passed/inconclusive yield nothing). */
43
62
  export function capabilitiesFor(finding) {
@@ -1,6 +1,9 @@
1
1
  const has = (s, ...caps) => caps.every((c) => s.has(c));
2
2
  const hasAny = (s, ...caps) => caps.some((c) => s.has(c));
3
3
  const byIds = (active, ids) => active.filter((f) => ids.includes(f.id));
4
+ // The AI & Agents findings carry dynamic id suffixes (userId, agent dev name, channel slug,
5
+ // domain), so their chain ingredients are matched by id prefix rather than exact id.
6
+ const byPrefixes = (active, prefixes) => active.filter((f) => prefixes.some((p) => f.id === p || f.id.startsWith(p)));
4
7
  export const NAMED_CHAINS = [
5
8
  {
6
9
  id: 'unauth-bulk-exfil',
@@ -18,12 +21,33 @@ export const NAMED_CHAINS = [
18
21
  const steps = byIds(active, [
19
22
  'guest-user-read-access', 'guest-user-write-access', 'guest-user-sharing-exposure', 'guest-user-baseline',
20
23
  'guest-executable-apex-unprotected', 'guest-executable-apex-exposed',
24
+ 'guest-object-exposure-public-owd', 'guest-object-exposure-guest-owned',
25
+ 'guest-api-access-enabled', 'guest-api-hard-delete', 'classic-sites-active',
21
26
  'portal-exposed-apex-without-sharing', 'sharing-model-external-read', 'sharing-model-external-write',
22
27
  'field-level-security-high', 'field-level-security-medium',
23
28
  ]);
24
29
  return steps.length >= 2 ? steps : null;
25
30
  },
26
31
  },
32
+ {
33
+ id: 'active-guest-exfil',
34
+ title: 'Active guest reconnaissance against an exposed data surface',
35
+ severity: 'CRITICAL',
36
+ narrative: 'Live EventLogFile evidence shows unauthenticated guests probing from anonymizer/hosting IPs or ' +
37
+ 'running GraphQL object-enumeration (totalCount) sweeps, AND the org exposes objects that are ' +
38
+ 'bulk-readable by those same guests. This is not a theoretical exposure — it is reconnaissance ' +
39
+ 'against a confirmed exfiltration surface, i.e. an incident likely already in progress.',
40
+ remediation: 'Treat as an active incident: block the source IPs at the WAF/CDN, close the guest bulk-read surface ' +
41
+ '(set external OWD to Private, strip guest object read, enforce "Secure guest user record access"), ' +
42
+ 'and preserve/forward the event logs before the short EventLogFile retention window closes.',
43
+ match(_present, active) {
44
+ const traffic = byIds(active, ['guest-traffic-anomaly-recon', 'guest-traffic-anomaly-anonymizer']);
45
+ const exposure = byIds(active, ['guest-object-exposure-public-owd', 'guest-object-exposure-guest-owned']);
46
+ if (traffic.length === 0 || exposure.length === 0)
47
+ return null;
48
+ return [...traffic, ...exposure];
49
+ },
50
+ },
27
51
  {
28
52
  id: 'standard-to-takeover',
29
53
  title: 'Standard user to org takeover',
@@ -39,6 +63,7 @@ export const NAMED_CHAINS = [
39
63
  const steps = byIds(active, [
40
64
  'sharing-model-external-read', 'sharing-model-external-write', 'guest-user-baseline',
41
65
  'escalation-perms-found', 'users-author-apex', 'users-super-admin-combo',
66
+ 'login-access-policy-delegated-admins', 'login-access-policy-login-as-enabled',
42
67
  ]);
43
68
  return steps.length >= 2 ? steps : null;
44
69
  },
@@ -80,6 +105,48 @@ export const NAMED_CHAINS = [
80
105
  return sink.length > 0 ? [...inj, ...sink] : null;
81
106
  },
82
107
  },
108
+ {
109
+ id: 'prompt-injection-blast-radius',
110
+ title: 'Prompt injection blast radius',
111
+ severity: 'CRITICAL',
112
+ narrative: 'A guest-reachable Agentforce channel lets an unauthenticated attacker send prompt-injection input to an ' +
113
+ 'agent that runs as an over-privileged user (Modify/View All Data or broad object write) and can drive ' +
114
+ 'write-capable actions. Public input, privileged identity, and state-changing actions are all present at ' +
115
+ 'once, so a single injected prompt can read, alter, or destroy data across the agent\'s reach.',
116
+ remediation: 'Break any one link: remove the guest/public binding, scope the agent run-as user to least privilege, ' +
117
+ 'or remove write-capable actions from the exposed agent (and add confirmation/guardrails where they must stay).',
118
+ match(_present, active) {
119
+ const channel = byPrefixes(active, ['agent-channel-exposure-guest-']);
120
+ const privilege = byPrefixes(active, [
121
+ 'agent-user-privilege-admin-', 'agent-user-privilege-broad-write-',
122
+ ]);
123
+ const actions = byIds(active, ['agent-action-surface-write']);
124
+ if (channel.length === 0 || privilege.length === 0 || actions.length === 0)
125
+ return null;
126
+ return [...channel, ...privilege, ...actions];
127
+ },
128
+ },
129
+ {
130
+ id: 'forcedleak-pattern',
131
+ title: 'ForcedLeak pattern',
132
+ severity: 'CRITICAL',
133
+ narrative: 'Active Agentforce agents run in an org that has a stale CSP-trusted domain (unresolvable or parked) on ' +
134
+ 'its allowlist and no Event Monitoring capture of agent activity. This is the exact ForcedLeak chain ' +
135
+ '(Noma Security, Sept 2025): an attacker registers the lapsed allowlisted domain, prompt-injects an agent ' +
136
+ 'into sending data to it, and nothing records or responds to the exfiltration.',
137
+ remediation: 'Remove or reclaim the stale trusted domain immediately, then enable Event Monitoring (and pull agent logs ' +
138
+ 'with `sf audit events pull`) plus a Transaction Security policy so agent-driven exfiltration is detected.',
139
+ match(_present, active) {
140
+ const agents = byIds(active, ['agent-inventory-summary']);
141
+ const staleUrl = byPrefixes(active, [
142
+ 'trusted-url-hygiene-unresolvable-', 'trusted-url-hygiene-parked-',
143
+ ]);
144
+ const noCapture = byIds(active, ['agent-monitoring-coverage-none']);
145
+ if (agents.length === 0 || staleUrl.length === 0 || noCapture.length === 0)
146
+ return null;
147
+ return [...agents, ...staleUrl, ...noCapture];
148
+ },
149
+ },
83
150
  {
84
151
  id: 'mfa-bypass-admin',
85
152
  title: 'MFA bypass to privileged compromise',
@@ -0,0 +1,14 @@
1
+ import type { EventLogAccess } from '../context/AuditCache.js';
2
+ /**
3
+ * Classifies why an `EventLogFile` query failed so callers can tell the two very
4
+ * different "no data" causes apart:
5
+ * - 'not-enabled' : Event Monitoring is not licensed/enabled (EventLogFile is
6
+ * an unknown/blocked sObject) — the org captures nothing.
7
+ * - 'no-permission' : the feature is on, but the running audit user lacks the
8
+ * "View Event Log Files" permission — logs exist, we can't read them.
9
+ * - 'unknown' : could not be attributed to either.
10
+ * Both are BLIND for guest-traffic analysis, but the remediation differs (license
11
+ * vs. grant a permission), so the distinction is worth surfacing.
12
+ */
13
+ export declare function classifyEventLogAccessError(err: unknown): EventLogAccess;
14
+ //# sourceMappingURL=eventLogAccess.d.ts.map
@@ -0,0 +1,33 @@
1
+ import { isApiError } from '../api/ApiError.js';
2
+ /**
3
+ * Classifies why an `EventLogFile` query failed so callers can tell the two very
4
+ * different "no data" causes apart:
5
+ * - 'not-enabled' : Event Monitoring is not licensed/enabled (EventLogFile is
6
+ * an unknown/blocked sObject) — the org captures nothing.
7
+ * - 'no-permission' : the feature is on, but the running audit user lacks the
8
+ * "View Event Log Files" permission — logs exist, we can't read them.
9
+ * - 'unknown' : could not be attributed to either.
10
+ * Both are BLIND for guest-traffic analysis, but the remediation differs (license
11
+ * vs. grant a permission), so the distinction is worth surfacing.
12
+ */
13
+ export function classifyEventLogAccessError(err) {
14
+ if (isApiError(err)) {
15
+ if (err.statusCode === 403 || /ACCESS|INSUFFICIENT/i.test(err.errorCode))
16
+ return 'no-permission';
17
+ if (/INVALID_TYPE|NOT_FOUND|MALFORMED_QUERY/i.test(err.errorCode) || err.statusCode === 404 || err.statusCode === 400) {
18
+ return 'not-enabled';
19
+ }
20
+ }
21
+ const msg = (err instanceof Error ? err.message : String(err)).toLowerCase();
22
+ if (msg.includes('insufficient') || msg.includes('permission') || msg.includes('view event log'))
23
+ return 'no-permission';
24
+ if (msg.includes('not supported') ||
25
+ msg.includes('invalid type') ||
26
+ msg.includes("sobject type 'eventlogfile'") ||
27
+ msg.includes('not enabled') ||
28
+ msg.includes('licens')) {
29
+ return 'not-enabled';
30
+ }
31
+ return 'unknown';
32
+ }
33
+ //# sourceMappingURL=eventLogAccess.js.map
@@ -0,0 +1,13 @@
1
+ import type { AuditContext } from '../../context/AuditContext.js';
2
+ import type { SecurityCheck, CheckResult } from '../SecurityCheck.js';
3
+ export declare class AgentActionSurfaceCheck implements SecurityCheck {
4
+ readonly id = "agent-action-surface";
5
+ readonly name = "Agent Action Surface";
6
+ readonly category = "AI & Agents";
7
+ readonly description = "Inventories Agentforce topics and actions (GenAiPlugin / GenAiFunction), flagging write-capable actions (Apex/Flow that create, update, or delete) and agents with an unusually large action surface. Write-capable actions on an exposed agent let a prompt injection take actions, not just read data.";
8
+ readonly dependsOnCache: readonly ["agentInventory", "agentAccess"];
9
+ run(ctx: AuditContext): Promise<CheckResult>;
10
+ private isWriteCapable;
11
+ private queryWithFallback;
12
+ }
13
+ //# sourceMappingURL=AgentActionSurfaceCheck.d.ts.map
@@ -0,0 +1,125 @@
1
+ import { isApiError } from '../../api/ApiError.js';
2
+ // An agent carrying more than this many actions has a large, hard-to-review surface. Info
3
+ // only — a big surface is not a vulnerability by itself, but it is worth surfacing.
4
+ const ACTION_COUNT_THRESHOLD = 15;
5
+ // Invocation target types that create/update/delete (or are ambiguous enough that we treat
6
+ // them as write-capable). Apex and Flow can both mutate data; where the type string is
7
+ // unknown/ambiguous we deliberately err toward flagging and say so in the finding.
8
+ const WRITE_CAPABLE_TYPE_HINTS = ['apex', 'flow'];
9
+ function isMissingObjectError(err) {
10
+ if (isApiError(err)) {
11
+ if (/INVALID_TYPE|NOT_FOUND|MALFORMED_QUERY/i.test(err.errorCode))
12
+ return true;
13
+ if (err.statusCode === 404)
14
+ return true;
15
+ }
16
+ const msg = (err instanceof Error ? err.message : String(err)).toLowerCase();
17
+ return (msg.includes('not supported') ||
18
+ msg.includes('invalid type') ||
19
+ msg.includes('sobject type'));
20
+ }
21
+ export class AgentActionSurfaceCheck {
22
+ id = 'agent-action-surface';
23
+ name = 'Agent Action Surface';
24
+ category = 'AI & Agents';
25
+ description = 'Inventories Agentforce topics and actions (GenAiPlugin / GenAiFunction), flagging write-capable actions (Apex/Flow that create, update, or delete) and agents with an unusually large action surface. Write-capable actions on an exposed agent let a prompt injection take actions, not just read data.';
26
+ dependsOnCache = ['agentInventory', 'agentAccess'];
27
+ async run(ctx) {
28
+ const findings = [];
29
+ // Gate: only run when AgentInventoryCheck confirmed the agent queries succeeded.
30
+ if (ctx.cache.agentAccess !== 'ok')
31
+ return { findings };
32
+ const inventory = ctx.cache.agentInventory ?? [];
33
+ const activeAgents = inventory.filter((a) => a.type === 'agent' && a.isActive);
34
+ if (activeAgents.length === 0)
35
+ return { findings };
36
+ // Query the org-wide action surface. GenAiFunction and its *Definition twin are queried
37
+ // defensively (INVALID_TYPE on one falls back to the other); if neither resolves, the
38
+ // feature does not expose actions in this org and we degrade silently.
39
+ const functions = await this.queryWithFallback(ctx, 'GenAiFunction', 'SELECT Id, DeveloperName, MasterLabel, InvocationTarget, InvocationTargetType');
40
+ if (functions === null)
41
+ return { findings };
42
+ // Topics (plugins) are supplementary context; a failure here is non-fatal.
43
+ const plugins = (await this.queryWithFallback(ctx, 'GenAiPlugin', 'SELECT Id, DeveloperName, MasterLabel')) ?? [];
44
+ const baseUrl = ctx.orgInfo.instanceUrl;
45
+ const setupUrl = `${baseUrl}/lightning/setup/EinsteinCopilot/home`;
46
+ // Write-capable actions across the org. We cannot resolve which specific agent owns each
47
+ // action from Tooling alone (no reliable agent join here); Phase 3 chains correlate this
48
+ // finding with agent-channel-exposure. We therefore report the write surface against the
49
+ // active-agent population and say so explicitly.
50
+ const writeActions = functions.filter((f) => this.isWriteCapable(f));
51
+ if (writeActions.length > 0) {
52
+ const agentLabels = activeAgents.map((a) => `${a.label} (${a.developerName})`);
53
+ findings.push({
54
+ id: 'agent-action-surface-write',
55
+ category: this.category,
56
+ riskLevel: 'HIGH',
57
+ title: `${writeActions.length} write-capable agent action(s) present across ${activeAgents.length} active agent(s)`,
58
+ detail: `${writeActions.length} Agentforce action(s) invoke Apex or Flow, which can create, update, or ` +
59
+ `delete records. (Apex and Flow invocations are treated as write-capable; where an action's ` +
60
+ `invocation type is ambiguous it is flagged conservatively.) On an externally exposed agent, a ` +
61
+ `successful prompt injection can drive these actions to take state-changing operations, not just ` +
62
+ `read data. Actions: ${writeActions
63
+ .slice(0, 20)
64
+ .map((f) => `${f.MasterLabel ?? f.DeveloperName} [${(f.InvocationTargetType ?? 'unknown').toLowerCase()}]`)
65
+ .join(', ')}${writeActions.length > 20 ? `, and ${writeActions.length - 20} more` : ''}.`,
66
+ remediation: 'Review each write-capable action: confirm the operation is intended, add guardrails/confirmation ' +
67
+ 'where it mutates sensitive data, and ensure the agent exposing it is not reachable by untrusted users. ' +
68
+ 'Correlate with channel exposure to size the real risk.',
69
+ affectedItems: writeActions.map((f) => ({
70
+ label: f.MasterLabel ?? f.DeveloperName,
71
+ note: `${(f.InvocationTargetType ?? 'unknown').toLowerCase()} invocation` +
72
+ (f.InvocationTarget ? ` → ${f.InvocationTarget}` : '') +
73
+ ` | exposed via active agent(s): ${agentLabels.slice(0, 3).join(', ')}${agentLabels.length > 3 ? ', …' : ''}`,
74
+ })),
75
+ });
76
+ }
77
+ // Large action surface: informational. Reported at the org level because Tooling does not
78
+ // give us a per-agent action join; total actions and topics both inform review effort.
79
+ if (functions.length > ACTION_COUNT_THRESHOLD) {
80
+ findings.push({
81
+ id: 'agent-action-surface-count',
82
+ category: this.category,
83
+ riskLevel: 'INFO',
84
+ title: `Large agent action surface: ${functions.length} actions across ${plugins.length} topic(s)`,
85
+ detail: `The org exposes ${functions.length} Agentforce action(s) (threshold ${ACTION_COUNT_THRESHOLD}) across ` +
86
+ `${plugins.length} topic(s) and ${activeAgents.length} active agent(s). A large action surface is ` +
87
+ `harder to review and increases the chance a risky action is reachable through an agent. This is ` +
88
+ `informational, not a vulnerability by itself.`,
89
+ remediation: 'Periodically review the full action catalogue. Retire unused actions and keep each agent scoped to ' +
90
+ 'the minimum set of topics and actions it needs.',
91
+ affectedItems: [
92
+ {
93
+ label: `${functions.length} action(s)`,
94
+ url: setupUrl,
95
+ note: `${plugins.length} topic(s), ${activeAgents.length} active agent(s)`,
96
+ },
97
+ ],
98
+ });
99
+ }
100
+ return { findings };
101
+ }
102
+ isWriteCapable(f) {
103
+ const type = (f.InvocationTargetType ?? '').toLowerCase();
104
+ return WRITE_CAPABLE_TYPE_HINTS.some((h) => type.includes(h));
105
+ }
106
+ // Query `baseObject`, falling back to `${baseObject}Definition` when the Tooling client
107
+ // cannot address the base object (INVALID_TYPE etc.). Returns null only when BOTH the base
108
+ // and the *Definition twin are missing (feature absent → degrade silently).
109
+ async queryWithFallback(ctx, baseObject, selectClause) {
110
+ try {
111
+ return await ctx.tooling.query(`${selectClause} FROM ${baseObject}`);
112
+ }
113
+ catch (e1) {
114
+ if (!isMissingObjectError(e1))
115
+ return null;
116
+ try {
117
+ return await ctx.tooling.query(`${selectClause} FROM ${baseObject}Definition`);
118
+ }
119
+ catch {
120
+ return null;
121
+ }
122
+ }
123
+ }
124
+ }
125
+ //# sourceMappingURL=AgentActionSurfaceCheck.js.map
@@ -0,0 +1,15 @@
1
+ import type { AuditContext } from '../../context/AuditContext.js';
2
+ import type { SecurityCheck, CheckResult } from '../SecurityCheck.js';
3
+ export declare class AgentChannelExposureCheck implements SecurityCheck {
4
+ readonly id = "agent-channel-exposure";
5
+ readonly name = "Agentforce Channel Exposure";
6
+ readonly category = "AI & Agents";
7
+ readonly description = "Correlates active Agentforce agents with the channels that reach them (Experience Cloud sites, embedded deployments, messaging channels) and flags guest-reachable exposure.";
8
+ readonly dependsOnCache: readonly ["agentInventory", "agentAccess"];
9
+ run(ctx: AuditContext): Promise<CheckResult>;
10
+ private queryGuestSites;
11
+ private queryMessagingChannels;
12
+ private queryEmbeddedDeployments;
13
+ private queryAgentChannelBindings;
14
+ }
15
+ //# sourceMappingURL=AgentChannelExposureCheck.d.ts.map