@cclabsnz/sf-audit 1.4.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.
- package/README.md +96 -11
- package/lib/api/RestClient.d.ts +1 -0
- package/lib/api/RestClientImpl.d.ts +1 -0
- package/lib/api/RestClientImpl.js +27 -0
- package/lib/apps/analyzeApps.d.ts +8 -0
- package/lib/apps/analyzeApps.js +19 -0
- package/lib/apps/appResolver.d.ts +4 -0
- package/lib/apps/appResolver.js +50 -0
- package/lib/apps/grantedAccess.d.ts +4 -0
- package/lib/apps/grantedAccess.js +36 -0
- package/lib/apps/leastPrivilege.d.ts +6 -0
- package/lib/apps/leastPrivilege.js +47 -0
- package/lib/apps/renderApps.d.ts +5 -0
- package/lib/apps/renderApps.js +23 -0
- package/lib/apps/standardAppCatalog.d.ts +11 -0
- package/lib/apps/standardAppCatalog.js +14 -0
- package/lib/apps/types.d.ts +64 -0
- package/lib/apps/types.js +2 -0
- package/lib/apps/usageCollector.d.ts +9 -0
- package/lib/apps/usageCollector.js +104 -0
- package/lib/chains/namedChains.js +45 -0
- package/lib/checks/impl/AgentActionSurfaceCheck.d.ts +13 -0
- package/lib/checks/impl/AgentActionSurfaceCheck.js +125 -0
- package/lib/checks/impl/AgentChannelExposureCheck.d.ts +15 -0
- package/lib/checks/impl/AgentChannelExposureCheck.js +223 -0
- package/lib/checks/impl/AgentInventoryCheck.d.ts +15 -0
- package/lib/checks/impl/AgentInventoryCheck.js +228 -0
- package/lib/checks/impl/AgentMonitoringCoverageCheck.d.ts +12 -0
- package/lib/checks/impl/AgentMonitoringCoverageCheck.js +97 -0
- package/lib/checks/impl/AgentUserPrivilegeCheck.d.ts +13 -0
- package/lib/checks/impl/AgentUserPrivilegeCheck.js +204 -0
- package/lib/checks/impl/CspTrustedSitesCheck.d.ts +1 -0
- package/lib/checks/impl/CspTrustedSitesCheck.js +10 -1
- package/lib/checks/impl/TrustedUrlHygieneCheck.d.ts +16 -0
- package/lib/checks/impl/TrustedUrlHygieneCheck.js +198 -0
- package/lib/checks/registry.js +19 -0
- package/lib/commands/audit/apps.d.ts +16 -0
- package/lib/commands/audit/apps.js +64 -0
- package/lib/commands/audit/security.d.ts +1 -0
- package/lib/commands/audit/security.js +7 -1
- package/lib/compliance/catalogs/index.js +2 -0
- package/lib/compliance/catalogs/owaspLlm.d.ts +3 -0
- package/lib/compliance/catalogs/owaspLlm.js +34 -0
- package/lib/compliance/mapping.js +19 -0
- package/lib/compliance/resolve.js +4 -3
- package/lib/compliance/types.d.ts +1 -1
- package/lib/context/AuditCache.d.ts +28 -0
- package/lib/context/AuditContext.d.ts +4 -0
- package/lib/events/pullEventLogs.js +3 -3
- package/lib/findings/CheckMeta.js +6 -0
- package/lib/lib/wire.d.ts +2 -2
- package/lib/lib/wire.js +2 -1
- package/lib/renderers/ClientReportRenderer.js +1 -1
- package/package.json +4 -1
|
@@ -0,0 +1,228 @@
|
|
|
1
|
+
import { isApiError } from '../../api/ApiError.js';
|
|
2
|
+
// BotDefinition.Type values that denote an Agentforce / GenAI agent rather than a
|
|
3
|
+
// classic Einstein Bot. Matched case-insensitively; anything else (typically 'Bot')
|
|
4
|
+
// is treated as a classic bot. LIKE-style matching so exact enum spellings across
|
|
5
|
+
// releases are not load-bearing.
|
|
6
|
+
const AGENT_TYPE_HINTS = ['agent', 'einsteinservice', 'einsteincopilot', 'genai', 'copilot'];
|
|
7
|
+
// Permission set license labels that grant Agentforce / Einstein Agent capability.
|
|
8
|
+
// Substring match so exact SKU names are not load-bearing.
|
|
9
|
+
const AGENT_LICENSE_HINTS = ['agentforce', 'einstein agent'];
|
|
10
|
+
// A Tooling error whose cause is "the object does not exist" (feature absent) rather
|
|
11
|
+
// than a transient/permission failure. Mirrors classifyEventLogAccessError's not-enabled arm.
|
|
12
|
+
function isMissingObjectError(err) {
|
|
13
|
+
if (isApiError(err)) {
|
|
14
|
+
if (/INVALID_TYPE|NOT_FOUND|MALFORMED_QUERY/i.test(err.errorCode))
|
|
15
|
+
return true;
|
|
16
|
+
if (err.statusCode === 404)
|
|
17
|
+
return true;
|
|
18
|
+
}
|
|
19
|
+
const msg = (err instanceof Error ? err.message : String(err)).toLowerCase();
|
|
20
|
+
return (msg.includes('not supported') ||
|
|
21
|
+
msg.includes('invalid type') ||
|
|
22
|
+
msg.includes('is not supported') ||
|
|
23
|
+
msg.includes('sobject type'));
|
|
24
|
+
}
|
|
25
|
+
export class AgentInventoryCheck {
|
|
26
|
+
id = 'agent-inventory';
|
|
27
|
+
name = 'Agentforce Agent Inventory';
|
|
28
|
+
category = 'AI & Agents';
|
|
29
|
+
description = 'Inventories Agentforce agents and classic Einstein Bots, their active versions, run-as users, and the users licensed to run agents.';
|
|
30
|
+
populatesCache = ['agentInventory', 'agentUsers', 'agentAccess'];
|
|
31
|
+
async run(ctx) {
|
|
32
|
+
const findings = [];
|
|
33
|
+
const baseUrl = ctx.orgInfo.instanceUrl;
|
|
34
|
+
// Step 1: BotDefinition is the entry query. If the object itself does not exist the
|
|
35
|
+
// org has no Agentforce/Bot feature — degrade to 'not-enabled' and stay silent.
|
|
36
|
+
let bots;
|
|
37
|
+
try {
|
|
38
|
+
bots = await this.queryBotDefinitions(ctx);
|
|
39
|
+
}
|
|
40
|
+
catch (e) {
|
|
41
|
+
if (isMissingObjectError(e)) {
|
|
42
|
+
ctx.cache.agentAccess = 'not-enabled';
|
|
43
|
+
}
|
|
44
|
+
else {
|
|
45
|
+
ctx.cache.agentAccess = 'unknown';
|
|
46
|
+
}
|
|
47
|
+
ctx.cache.agentInventory = [];
|
|
48
|
+
ctx.cache.agentUsers = [];
|
|
49
|
+
return { findings };
|
|
50
|
+
}
|
|
51
|
+
// Step 2+: active versions, planner definitions, and agent users. Any failure here
|
|
52
|
+
// (the objects exist, so this is not 'not-enabled') means we could not fully build the
|
|
53
|
+
// inventory — record 'unknown' and return no findings rather than assert a partial view.
|
|
54
|
+
let versions;
|
|
55
|
+
let agentUsers;
|
|
56
|
+
try {
|
|
57
|
+
versions = await ctx.tooling.query(`SELECT Id, BotDefinitionId, Status, VersionNumber FROM BotVersion WHERE Status = 'Active'`);
|
|
58
|
+
// GenAiPlannerDefinition is queried for completeness of the agent picture (Phase 2
|
|
59
|
+
// action-surface work joins on it); a failure here still counts as an incomplete build.
|
|
60
|
+
await ctx.tooling.query(`SELECT Id, DeveloperName, MasterLabel FROM GenAiPlannerDefinition`);
|
|
61
|
+
agentUsers = await this.queryAgentUsers(ctx);
|
|
62
|
+
}
|
|
63
|
+
catch (e) {
|
|
64
|
+
if (isMissingObjectError(e)) {
|
|
65
|
+
// BotDefinition existed but a GenAI object did not: the feature is partially present
|
|
66
|
+
// (e.g. classic bots without Agentforce). Treat as 'unknown' — we cannot vouch for a
|
|
67
|
+
// complete agent inventory — rather than 'not-enabled'.
|
|
68
|
+
ctx.cache.agentAccess = 'unknown';
|
|
69
|
+
}
|
|
70
|
+
else {
|
|
71
|
+
ctx.cache.agentAccess = 'unknown';
|
|
72
|
+
}
|
|
73
|
+
ctx.cache.agentInventory = [];
|
|
74
|
+
ctx.cache.agentUsers = [];
|
|
75
|
+
return { findings };
|
|
76
|
+
}
|
|
77
|
+
// Build the inventory. Active version = the BotVersion (per definition) with Status Active.
|
|
78
|
+
const activeVersionByBot = new Map();
|
|
79
|
+
for (const v of versions) {
|
|
80
|
+
const existing = activeVersionByBot.get(v.BotDefinitionId);
|
|
81
|
+
if (existing === undefined || v.VersionNumber > existing) {
|
|
82
|
+
activeVersionByBot.set(v.BotDefinitionId, v.VersionNumber);
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
const runAsIds = bots.map((b) => b.BotUserId).filter((id) => !!id);
|
|
86
|
+
const runAsStatus = await this.queryRunAsUserStatus(ctx, runAsIds);
|
|
87
|
+
const inventory = bots.map((b) => {
|
|
88
|
+
const activeVersion = activeVersionByBot.get(b.Id);
|
|
89
|
+
const runAsUserId = b.BotUserId ?? undefined;
|
|
90
|
+
const runAsUserActive = runAsUserId !== undefined && runAsStatus.has(runAsUserId)
|
|
91
|
+
? runAsStatus.get(runAsUserId)
|
|
92
|
+
: undefined;
|
|
93
|
+
return {
|
|
94
|
+
developerName: b.DeveloperName,
|
|
95
|
+
label: b.MasterLabel,
|
|
96
|
+
type: this.classifyType(b.Type),
|
|
97
|
+
isActive: activeVersion !== undefined,
|
|
98
|
+
activeVersion,
|
|
99
|
+
runAsUserId,
|
|
100
|
+
runAsUserActive,
|
|
101
|
+
};
|
|
102
|
+
});
|
|
103
|
+
ctx.cache.agentInventory = inventory;
|
|
104
|
+
ctx.cache.agentUsers = agentUsers;
|
|
105
|
+
ctx.cache.agentAccess = 'ok';
|
|
106
|
+
const agents = inventory.filter((a) => a.type === 'agent');
|
|
107
|
+
const activeAgents = agents.filter((a) => a.isActive);
|
|
108
|
+
if (inventory.length === 0) {
|
|
109
|
+
// Feature present but nothing configured: no noise, cache already records 'ok'.
|
|
110
|
+
return { findings };
|
|
111
|
+
}
|
|
112
|
+
// Info: the inventory itself is the product.
|
|
113
|
+
findings.push({
|
|
114
|
+
id: 'agent-inventory-summary',
|
|
115
|
+
category: this.category,
|
|
116
|
+
riskLevel: 'INFO',
|
|
117
|
+
title: `Agentforce inventory: ${agents.length} agent(s), ${activeAgents.length} active, ${agentUsers.length} agent user(s)`,
|
|
118
|
+
detail: `Found ${inventory.length} bot/agent definition(s): ${agents.length} Agentforce agent(s) ` +
|
|
119
|
+
`(${activeAgents.length} with an active version) and ${inventory.length - agents.length} classic Einstein Bot(s). ` +
|
|
120
|
+
`${agentUsers.length} user(s) are licensed to run agents (Einstein Agent User profile or an Agentforce / Einstein Agent permission set license). ` +
|
|
121
|
+
`Each active agent executes as a run-as user whose data access defines the blast radius of a prompt injection.`,
|
|
122
|
+
remediation: 'Confirm every active agent is expected and documented, that its run-as user follows least privilege, and that the agent users list contains no stale accounts.',
|
|
123
|
+
affectedItems: inventory.map((a) => ({
|
|
124
|
+
label: `${a.label} (${a.developerName})`,
|
|
125
|
+
note: `${a.type === 'agent' ? 'Agentforce agent' : 'classic Einstein Bot'} | ` +
|
|
126
|
+
`${a.isActive ? `active v${a.activeVersion}` : 'no active version'}` +
|
|
127
|
+
(a.runAsUserId ? ` | run-as: ${a.runAsUserId}` : ''),
|
|
128
|
+
})),
|
|
129
|
+
});
|
|
130
|
+
// Medium: an active agent whose run-as user is inactive or frozen. The agent stays
|
|
131
|
+
// reachable but its identity is disabled — a latent misconfiguration and, if reactivated
|
|
132
|
+
// without review, a way to smuggle access back in.
|
|
133
|
+
const brokenRunAs = inventory.filter((a) => a.type === 'agent' && a.isActive && a.runAsUserActive === false);
|
|
134
|
+
for (const a of brokenRunAs) {
|
|
135
|
+
findings.push({
|
|
136
|
+
id: `agent-inventory-runas-inactive-${a.developerName}`,
|
|
137
|
+
category: this.category,
|
|
138
|
+
riskLevel: 'MEDIUM',
|
|
139
|
+
title: `Active agent "${a.label}" runs as an inactive or frozen user`,
|
|
140
|
+
detail: `The Agentforce agent "${a.label}" (${a.developerName}) has an active version but its run-as user ` +
|
|
141
|
+
`is inactive or frozen. Requests to the agent will fail, and if the user is later reactivated its ` +
|
|
142
|
+
`permissions take effect again without a fresh review.`,
|
|
143
|
+
remediation: 'Confirm the run-as user should be disabled. If the agent is still needed, assign an active, least-privilege run-as user; otherwise deactivate the agent version.',
|
|
144
|
+
affectedItems: [
|
|
145
|
+
{
|
|
146
|
+
label: `${a.label} (${a.developerName})`,
|
|
147
|
+
url: a.runAsUserId ? `${baseUrl}/${a.runAsUserId}` : undefined,
|
|
148
|
+
note: `run-as user ${a.runAsUserId ?? 'unknown'} is inactive/frozen`,
|
|
149
|
+
},
|
|
150
|
+
],
|
|
151
|
+
});
|
|
152
|
+
}
|
|
153
|
+
return { findings };
|
|
154
|
+
}
|
|
155
|
+
classifyType(type) {
|
|
156
|
+
const t = (type ?? '').toLowerCase();
|
|
157
|
+
return AGENT_TYPE_HINTS.some((h) => t.includes(h)) ? 'agent' : 'classic-bot';
|
|
158
|
+
}
|
|
159
|
+
// BotDefinition query with a defensive fallback: if Type/BotUserId are not queryable in
|
|
160
|
+
// this org/release (MALFORMED_QUERY on the field), retry with the minimal field set rather
|
|
161
|
+
// than throw. A genuinely missing object still throws and is handled by the caller.
|
|
162
|
+
async queryBotDefinitions(ctx) {
|
|
163
|
+
try {
|
|
164
|
+
return await ctx.tooling.query(`SELECT Id, DeveloperName, MasterLabel, Type, BotUserId FROM BotDefinition`);
|
|
165
|
+
}
|
|
166
|
+
catch (e) {
|
|
167
|
+
if (isApiError(e) && /MALFORMED_QUERY|INVALID_FIELD/i.test(e.errorCode)) {
|
|
168
|
+
return ctx.tooling.query(`SELECT Id, DeveloperName, MasterLabel FROM BotDefinition`);
|
|
169
|
+
}
|
|
170
|
+
throw e;
|
|
171
|
+
}
|
|
172
|
+
}
|
|
173
|
+
// Users on the Einstein Agent User profile OR holding an Agentforce / Einstein Agent
|
|
174
|
+
// permission set license, with their PermissionSetAssignment ids and license labels.
|
|
175
|
+
async queryAgentUsers(ctx) {
|
|
176
|
+
const licenseLike = AGENT_LICENSE_HINTS.map((h) => `PermissionSetLicense.MasterLabel LIKE '%${h}%'`).join(' OR ');
|
|
177
|
+
// License assignments first, so the User filter can include those assignees.
|
|
178
|
+
const licenseAssigns = await ctx.soql.queryAll(`SELECT AssigneeId, PermissionSetLicense.MasterLabel
|
|
179
|
+
FROM PermissionSetLicenseAssign
|
|
180
|
+
WHERE ${licenseLike}
|
|
181
|
+
LIMIT 500`);
|
|
182
|
+
const licenseNamesByUser = new Map();
|
|
183
|
+
for (const a of licenseAssigns) {
|
|
184
|
+
const label = a.PermissionSetLicense?.MasterLabel;
|
|
185
|
+
if (!label)
|
|
186
|
+
continue;
|
|
187
|
+
const list = licenseNamesByUser.get(a.AssigneeId) ?? [];
|
|
188
|
+
list.push(label);
|
|
189
|
+
licenseNamesByUser.set(a.AssigneeId, list);
|
|
190
|
+
}
|
|
191
|
+
const licensedIds = [...licenseNamesByUser.keys()];
|
|
192
|
+
const idInClause = licensedIds.length
|
|
193
|
+
? ` OR Id IN (${licensedIds.map((id) => `'${id}'`).join(',')})`
|
|
194
|
+
: '';
|
|
195
|
+
const users = await ctx.soql.queryAll(`SELECT Id, Username, IsActive, Profile.Name,
|
|
196
|
+
(SELECT PermissionSetId FROM PermissionSetAssignments)
|
|
197
|
+
FROM User
|
|
198
|
+
WHERE Profile.Name = 'Einstein Agent User'${idInClause}
|
|
199
|
+
LIMIT 500`);
|
|
200
|
+
return users.map((u) => ({
|
|
201
|
+
userId: u.Id,
|
|
202
|
+
username: u.Username,
|
|
203
|
+
profileName: u.Profile?.Name ?? '',
|
|
204
|
+
isActive: u.IsActive,
|
|
205
|
+
permissionSetIds: (u.PermissionSetAssignments?.records ?? []).map((r) => r.PermissionSetId),
|
|
206
|
+
permissionSetLicenseNames: licenseNamesByUser.get(u.Id) ?? [],
|
|
207
|
+
}));
|
|
208
|
+
}
|
|
209
|
+
// Resolve which run-as users are active (and not frozen). A frozen user has an active
|
|
210
|
+
// IsActive flag but a UserLogin.IsFrozen = true row, so exclude those from the "active" set.
|
|
211
|
+
async queryRunAsUserStatus(ctx, runAsIds) {
|
|
212
|
+
const status = new Map();
|
|
213
|
+
if (runAsIds.length === 0)
|
|
214
|
+
return status;
|
|
215
|
+
const idList = runAsIds.map((id) => `'${id}'`).join(',');
|
|
216
|
+
const rows = await ctx.soql.queryAll(`SELECT Id, IsActive
|
|
217
|
+
FROM User
|
|
218
|
+
WHERE Id IN (${idList})
|
|
219
|
+
AND Id NOT IN (SELECT UserId FROM UserLogin WHERE IsFrozen = true)`);
|
|
220
|
+
// Rows returned = active and not frozen. Any run-as id absent from the result set is
|
|
221
|
+
// therefore inactive or frozen.
|
|
222
|
+
const activeIds = new Set(rows.filter((r) => r.IsActive).map((r) => r.Id));
|
|
223
|
+
for (const id of runAsIds)
|
|
224
|
+
status.set(id, activeIds.has(id));
|
|
225
|
+
return status;
|
|
226
|
+
}
|
|
227
|
+
}
|
|
228
|
+
//# sourceMappingURL=AgentInventoryCheck.js.map
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import type { AuditContext } from '../../context/AuditContext.js';
|
|
2
|
+
import type { SecurityCheck, CheckResult } from '../SecurityCheck.js';
|
|
3
|
+
export declare class AgentMonitoringCoverageCheck implements SecurityCheck {
|
|
4
|
+
readonly id = "agent-monitoring-coverage";
|
|
5
|
+
readonly name = "Agentforce Monitoring Coverage";
|
|
6
|
+
readonly category = "AI & Agents";
|
|
7
|
+
readonly description = "Flags orgs that run active Agentforce agents without Event Monitoring capture or Transaction Security policies to detect and respond to agent abuse.";
|
|
8
|
+
readonly dependsOnCache: readonly ["agentInventory", "agentAccess", "eventLogSummary"];
|
|
9
|
+
run(ctx: AuditContext): Promise<CheckResult>;
|
|
10
|
+
private hasEnabledTransactionSecurityPolicy;
|
|
11
|
+
}
|
|
12
|
+
//# sourceMappingURL=AgentMonitoringCoverageCheck.d.ts.map
|
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
export class AgentMonitoringCoverageCheck {
|
|
2
|
+
id = 'agent-monitoring-coverage';
|
|
3
|
+
name = 'Agentforce Monitoring Coverage';
|
|
4
|
+
category = 'AI & Agents';
|
|
5
|
+
description = 'Flags orgs that run active Agentforce agents without Event Monitoring capture or Transaction Security policies to detect and respond to agent abuse.';
|
|
6
|
+
// Depends on the agent inventory plus the event-log summary that EventMonitoringCheck
|
|
7
|
+
// populates. TransactionSecurityPolicy is queried directly (Tooling), not cached.
|
|
8
|
+
dependsOnCache = ['agentInventory', 'agentAccess', 'eventLogSummary'];
|
|
9
|
+
async run(ctx) {
|
|
10
|
+
const findings = [];
|
|
11
|
+
const baseUrl = ctx.orgInfo.instanceUrl;
|
|
12
|
+
// Gate: silent unless the agent inventory was built successfully.
|
|
13
|
+
if (ctx.cache.agentAccess !== 'ok')
|
|
14
|
+
return { findings };
|
|
15
|
+
const inventory = ctx.cache.agentInventory ?? [];
|
|
16
|
+
const activeAgents = inventory.filter((a) => a.type === 'agent' && a.isActive);
|
|
17
|
+
if (activeAgents.length === 0)
|
|
18
|
+
return { findings };
|
|
19
|
+
// Event capture signal, interpreted the same way SiemIntegrationCheck reads the
|
|
20
|
+
// EventLogSummary: capture exists only when the log is accessible AND has files.
|
|
21
|
+
// A blind log (not-enabled / no-permission) counts as "no capture" — there is no
|
|
22
|
+
// monitoring the agent's activity can be seen through.
|
|
23
|
+
const els = ctx.cache.eventLogSummary;
|
|
24
|
+
const hasEventCapture = !!els && els.accessible !== false && (els.totalFiles ?? 0) > 0;
|
|
25
|
+
// Transaction Security policies (real-time threat response). Defensive: a missing
|
|
26
|
+
// object / access failure is treated as "no policy" rather than throwing — the
|
|
27
|
+
// absence of detectable policy is what matters for this coverage check.
|
|
28
|
+
const hasTransactionSecurity = await this.hasEnabledTransactionSecurityPolicy(ctx);
|
|
29
|
+
const agentList = activeAgents
|
|
30
|
+
.map((a) => `${a.label} (${a.developerName})`)
|
|
31
|
+
.slice(0, 20)
|
|
32
|
+
.join(', ');
|
|
33
|
+
// High: agents run, nothing captures their activity, and no automated response
|
|
34
|
+
// exists. Point at the events pull command.
|
|
35
|
+
if (!hasEventCapture && !hasTransactionSecurity) {
|
|
36
|
+
findings.push({
|
|
37
|
+
id: 'agent-monitoring-coverage-none',
|
|
38
|
+
category: this.category,
|
|
39
|
+
riskLevel: 'HIGH',
|
|
40
|
+
title: `${activeAgents.length} active agent(s) run with no Event Monitoring capture and no Transaction Security policy`,
|
|
41
|
+
detail: `This org has ${activeAgents.length} active Agentforce agent(s) (${agentList}) but ` +
|
|
42
|
+
`Event Monitoring is not capturing any log files${els && els.accessible === false ? ' (the event log was not accessible to this audit)' : ''} ` +
|
|
43
|
+
`and no Transaction Security policy is enabled. Agent activity — including prompt injection, mass reads by the run-as user, ` +
|
|
44
|
+
`and data exfiltration — would leave no auditable trail and trigger no automated response. This is the monitoring gap in the ForcedLeak pattern.`,
|
|
45
|
+
remediation: 'Enable Event Monitoring (Setup → Event Monitoring Settings) and pull agent-relevant logs with `sf audit events pull` on a schedule, forwarding to a SIEM. Add Transaction Security policies for login and data-export anomalies so agent misuse triggers a real-time response.',
|
|
46
|
+
affectedItems: [
|
|
47
|
+
{
|
|
48
|
+
label: 'Event Monitoring',
|
|
49
|
+
url: `${baseUrl}/lightning/setup/EventLogFile/home`,
|
|
50
|
+
note: 'No event log files captured — run `sf audit events pull`',
|
|
51
|
+
},
|
|
52
|
+
{
|
|
53
|
+
label: 'Transaction Security Policies',
|
|
54
|
+
url: `${baseUrl}/lightning/setup/TransactionSecurityPolicies/home`,
|
|
55
|
+
note: 'No enabled policy — no automated response to agent abuse',
|
|
56
|
+
},
|
|
57
|
+
],
|
|
58
|
+
});
|
|
59
|
+
return { findings };
|
|
60
|
+
}
|
|
61
|
+
// Low (partial): event logs exist but there is no Transaction Security policy — the
|
|
62
|
+
// activity is recorded but nothing responds in real time.
|
|
63
|
+
if (hasEventCapture && !hasTransactionSecurity) {
|
|
64
|
+
findings.push({
|
|
65
|
+
id: 'agent-monitoring-coverage-partial',
|
|
66
|
+
category: this.category,
|
|
67
|
+
riskLevel: 'LOW',
|
|
68
|
+
title: `Agent activity is logged but no Transaction Security policy provides real-time response`,
|
|
69
|
+
detail: `Event Monitoring is capturing log files, so ${activeAgents.length} active agent(s) leave an auditable trail. ` +
|
|
70
|
+
`However, no Transaction Security policy is enabled, so anomalies in agent-driven activity (bulk reads, off-hours access, ` +
|
|
71
|
+
`data export) are recorded after the fact but not blocked or alerted on in real time.`,
|
|
72
|
+
remediation: 'Add Transaction Security policies (Setup → Transaction Security Policies) for login anomalies and bulk data export so agent misuse is caught in real time, not only in retrospective log review.',
|
|
73
|
+
affectedItems: [
|
|
74
|
+
{
|
|
75
|
+
label: 'Transaction Security Policies',
|
|
76
|
+
url: `${baseUrl}/lightning/setup/TransactionSecurityPolicies/home`,
|
|
77
|
+
note: 'No enabled policy — add real-time response for agent activity',
|
|
78
|
+
},
|
|
79
|
+
],
|
|
80
|
+
});
|
|
81
|
+
return { findings };
|
|
82
|
+
}
|
|
83
|
+
// Otherwise monitoring is adequate (capture present, or capture + policy). Silent.
|
|
84
|
+
return { findings };
|
|
85
|
+
}
|
|
86
|
+
async hasEnabledTransactionSecurityPolicy(ctx) {
|
|
87
|
+
try {
|
|
88
|
+
const policies = await ctx.tooling.query(`SELECT Id, State FROM TransactionSecurityPolicy WHERE State = 'Enabled'`);
|
|
89
|
+
return policies.length > 0;
|
|
90
|
+
}
|
|
91
|
+
catch {
|
|
92
|
+
// Object missing or inaccessible: no detectable policy.
|
|
93
|
+
return false;
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
//# sourceMappingURL=AgentMonitoringCoverageCheck.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 AgentUserPrivilegeCheck implements SecurityCheck {
|
|
4
|
+
readonly id = "agent-user-privilege";
|
|
5
|
+
readonly name = "Agent User Privilege";
|
|
6
|
+
readonly category = "AI & Agents";
|
|
7
|
+
readonly description = "Flags Agentforce run-as / agent users whose effective access is over-broad: Modify/View All Data, write access to many objects, or read access to data classified as sensitive. An injected prompt can exfiltrate or mutate exactly what the agent user can reach.";
|
|
8
|
+
readonly dependsOnCache: readonly ["agentUsers", "agentAccess"];
|
|
9
|
+
run(ctx: AuditContext): Promise<CheckResult>;
|
|
10
|
+
private evaluateUser;
|
|
11
|
+
private querySensitiveObjects;
|
|
12
|
+
}
|
|
13
|
+
//# sourceMappingURL=AgentUserPrivilegeCheck.d.ts.map
|
|
@@ -0,0 +1,204 @@
|
|
|
1
|
+
// An agent user's write access is "broad" when it can create/update/delete on more than
|
|
2
|
+
// this many objects. Chosen to match DataClassificationCheck's small-key-object set size
|
|
3
|
+
// (7 key objects) with headroom: a legitimate task-scoped agent user should touch only a
|
|
4
|
+
// handful of objects, so >10 is a signal of over-provisioning.
|
|
5
|
+
const BROAD_WRITE_OBJECT_THRESHOLD = 10;
|
|
6
|
+
export class AgentUserPrivilegeCheck {
|
|
7
|
+
id = 'agent-user-privilege';
|
|
8
|
+
name = 'Agent User Privilege';
|
|
9
|
+
category = 'AI & Agents';
|
|
10
|
+
description = 'Flags Agentforce run-as / agent users whose effective access is over-broad: Modify/View All Data, write access to many objects, or read access to data classified as sensitive. An injected prompt can exfiltrate or mutate exactly what the agent user can reach.';
|
|
11
|
+
dependsOnCache = ['agentUsers', 'agentAccess'];
|
|
12
|
+
async run(ctx) {
|
|
13
|
+
const findings = [];
|
|
14
|
+
// Gate: only run when AgentInventoryCheck confirmed the agent queries succeeded.
|
|
15
|
+
if (ctx.cache.agentAccess !== 'ok')
|
|
16
|
+
return { findings };
|
|
17
|
+
const agentUsers = ctx.cache.agentUsers ?? [];
|
|
18
|
+
if (agentUsers.length === 0)
|
|
19
|
+
return { findings };
|
|
20
|
+
const baseUrl = ctx.orgInfo.instanceUrl;
|
|
21
|
+
const setupUrl = `${baseUrl}/lightning/setup/PermSets/home`;
|
|
22
|
+
// Collect every permission set assigned to any agent user, then query the two
|
|
23
|
+
// permission surfaces once for the whole set (not per user).
|
|
24
|
+
const allPsIds = [...new Set(agentUsers.flatMap((u) => u.permissionSetIds))];
|
|
25
|
+
if (allPsIds.length === 0)
|
|
26
|
+
return { findings };
|
|
27
|
+
const psIn = allPsIds.map((id) => `'${id}'`).join(', ');
|
|
28
|
+
// System permissions (ModifyAllData / ViewAllData) per permission set.
|
|
29
|
+
let systemPerms;
|
|
30
|
+
try {
|
|
31
|
+
systemPerms = await ctx.soql.queryAll(`SELECT Id, Label, PermissionsModifyAllData, PermissionsViewAllData
|
|
32
|
+
FROM PermissionSet
|
|
33
|
+
WHERE Id IN (${psIn})`);
|
|
34
|
+
}
|
|
35
|
+
catch (err) {
|
|
36
|
+
findings.push({
|
|
37
|
+
id: 'agent-user-privilege-inconclusive',
|
|
38
|
+
category: this.category,
|
|
39
|
+
riskLevel: 'INFO',
|
|
40
|
+
inconclusive: true,
|
|
41
|
+
title: 'Agent user permissions could not be resolved',
|
|
42
|
+
detail: `The PermissionSet query for agent users was not accessible: ${err instanceof Error ? err.message : String(err)}`,
|
|
43
|
+
remediation: 'Grant the audit user "View Setup and Configuration", then re-run the audit.',
|
|
44
|
+
});
|
|
45
|
+
return { findings };
|
|
46
|
+
}
|
|
47
|
+
// Object-level CRUD per permission set. A failure here is non-fatal — we still report
|
|
48
|
+
// the system-permission findings.
|
|
49
|
+
let objectPerms = [];
|
|
50
|
+
let objectPermsFailed = false;
|
|
51
|
+
try {
|
|
52
|
+
objectPerms = await ctx.soql.queryAll(`SELECT ParentId, SobjectType, PermissionsRead, PermissionsCreate, PermissionsEdit, PermissionsDelete
|
|
53
|
+
FROM ObjectPermissions
|
|
54
|
+
WHERE ParentId IN (${psIn})`);
|
|
55
|
+
}
|
|
56
|
+
catch {
|
|
57
|
+
objectPermsFailed = true;
|
|
58
|
+
}
|
|
59
|
+
// Sensitive objects = objects with at least one classified field (ComplianceGroup set).
|
|
60
|
+
// Query once for every readable object across the agent users; skip the sub-signal
|
|
61
|
+
// silently if the org has no classification data or the Tooling query is unavailable.
|
|
62
|
+
const readableObjects = [
|
|
63
|
+
...new Set(objectPerms.filter((p) => p.PermissionsRead).map((p) => p.SobjectType)),
|
|
64
|
+
];
|
|
65
|
+
const sensitiveObjects = await this.querySensitiveObjects(ctx, readableObjects);
|
|
66
|
+
// Index permission-set metadata by id for per-user attribution.
|
|
67
|
+
const psById = new Map(systemPerms.map((p) => [p.Id, p]));
|
|
68
|
+
const objPermsByPs = new Map();
|
|
69
|
+
for (const op of objectPerms) {
|
|
70
|
+
const list = objPermsByPs.get(op.ParentId) ?? [];
|
|
71
|
+
list.push(op);
|
|
72
|
+
objPermsByPs.set(op.ParentId, list);
|
|
73
|
+
}
|
|
74
|
+
for (const u of agentUsers) {
|
|
75
|
+
this.evaluateUser(u, psById, objPermsByPs, sensitiveObjects, {
|
|
76
|
+
findings,
|
|
77
|
+
setupUrl,
|
|
78
|
+
objectPermsFailed,
|
|
79
|
+
});
|
|
80
|
+
}
|
|
81
|
+
return { findings };
|
|
82
|
+
}
|
|
83
|
+
evaluateUser(u, psById, objPermsByPs, sensitiveObjects, out) {
|
|
84
|
+
const { findings, setupUrl } = out;
|
|
85
|
+
// Which of the user's permission sets grant ModifyAllData / ViewAllData.
|
|
86
|
+
const adminPsLabels = [];
|
|
87
|
+
let hasModifyAll = false;
|
|
88
|
+
let hasViewAll = false;
|
|
89
|
+
for (const psId of u.permissionSetIds) {
|
|
90
|
+
const ps = psById.get(psId);
|
|
91
|
+
if (!ps)
|
|
92
|
+
continue;
|
|
93
|
+
if (ps.PermissionsModifyAllData) {
|
|
94
|
+
hasModifyAll = true;
|
|
95
|
+
adminPsLabels.push(`${ps.Label} (Modify All Data)`);
|
|
96
|
+
}
|
|
97
|
+
else if (ps.PermissionsViewAllData) {
|
|
98
|
+
hasViewAll = true;
|
|
99
|
+
adminPsLabels.push(`${ps.Label} (View All Data)`);
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
if (hasModifyAll || hasViewAll) {
|
|
103
|
+
const which = hasModifyAll ? 'Modify All Data' : 'View All Data';
|
|
104
|
+
findings.push({
|
|
105
|
+
id: `agent-user-privilege-admin-${u.userId}`,
|
|
106
|
+
category: this.category,
|
|
107
|
+
riskLevel: 'CRITICAL',
|
|
108
|
+
title: `Agent user ${u.username} holds ${which}`,
|
|
109
|
+
detail: `The agent user "${u.username}" (profile ${u.profileName || 'unknown'}) effectively holds ` +
|
|
110
|
+
`${which}, which bypasses sharing across the entire org. Because an Agentforce agent runs as ` +
|
|
111
|
+
`this user, a successful prompt injection inherits ${which.toLowerCase()}: it can ` +
|
|
112
|
+
`${hasModifyAll ? 'read, edit, and delete' : 'read'} every record in the org. This is the ` +
|
|
113
|
+
`worst-case blast radius for an exposed agent.`,
|
|
114
|
+
remediation: `Remove ${which} from the offending permission set(s) unless the agent genuinely requires ` +
|
|
115
|
+
`org-wide access. Scope the agent user to only the objects and records its topics need.`,
|
|
116
|
+
affectedItems: [
|
|
117
|
+
{
|
|
118
|
+
label: u.username,
|
|
119
|
+
url: setupUrl,
|
|
120
|
+
note: `Permission set(s): ${adminPsLabels.join(', ')}`,
|
|
121
|
+
},
|
|
122
|
+
],
|
|
123
|
+
});
|
|
124
|
+
}
|
|
125
|
+
// Broad object write access: union of objects this user can create/update/delete across
|
|
126
|
+
// all of their permission sets.
|
|
127
|
+
const writableObjects = new Set();
|
|
128
|
+
const readableObjects = new Set();
|
|
129
|
+
for (const psId of u.permissionSetIds) {
|
|
130
|
+
for (const op of objPermsByPs.get(psId) ?? []) {
|
|
131
|
+
if (op.PermissionsCreate || op.PermissionsEdit || op.PermissionsDelete) {
|
|
132
|
+
writableObjects.add(op.SobjectType);
|
|
133
|
+
}
|
|
134
|
+
if (op.PermissionsRead)
|
|
135
|
+
readableObjects.add(op.SobjectType);
|
|
136
|
+
}
|
|
137
|
+
}
|
|
138
|
+
if (writableObjects.size > BROAD_WRITE_OBJECT_THRESHOLD) {
|
|
139
|
+
const objList = [...writableObjects].sort();
|
|
140
|
+
findings.push({
|
|
141
|
+
id: `agent-user-privilege-broad-write-${u.userId}`,
|
|
142
|
+
category: this.category,
|
|
143
|
+
riskLevel: 'HIGH',
|
|
144
|
+
title: `Agent user ${u.username} has write access to ${writableObjects.size} objects`,
|
|
145
|
+
detail: `The agent user "${u.username}" can create, update, or delete records on ${writableObjects.size} ` +
|
|
146
|
+
`objects (threshold ${BROAD_WRITE_OBJECT_THRESHOLD}). An injected prompt runs with this write ` +
|
|
147
|
+
`surface, so it could mutate or destroy data across all of them. Objects: ` +
|
|
148
|
+
`${objList.slice(0, 20).join(', ')}${objList.length > 20 ? `, and ${objList.length - 20} more` : ''}.`,
|
|
149
|
+
remediation: 'Narrow the agent user\'s object CRUD to only the objects its topics act on. Prefer read-only access ' +
|
|
150
|
+
'where the agent only needs to answer questions, and move write actions behind explicit, reviewed Apex/Flow.',
|
|
151
|
+
affectedItems: [
|
|
152
|
+
{
|
|
153
|
+
label: u.username,
|
|
154
|
+
url: setupUrl,
|
|
155
|
+
note: `${writableObjects.size} writable object(s) via permission set(s): ${u.permissionSetIds.join(', ')}`,
|
|
156
|
+
},
|
|
157
|
+
],
|
|
158
|
+
});
|
|
159
|
+
}
|
|
160
|
+
// Read access to sensitive/classified objects. Silent when the org has no classification
|
|
161
|
+
// data (sensitiveObjects is empty).
|
|
162
|
+
const sensitiveReadable = [...readableObjects].filter((o) => sensitiveObjects.has(o)).sort();
|
|
163
|
+
if (sensitiveReadable.length > 0) {
|
|
164
|
+
findings.push({
|
|
165
|
+
id: `agent-user-privilege-sensitive-read-${u.userId}`,
|
|
166
|
+
category: this.category,
|
|
167
|
+
riskLevel: 'HIGH',
|
|
168
|
+
title: `Agent user ${u.username} can read ${sensitiveReadable.length} object(s) classified as sensitive`,
|
|
169
|
+
detail: `The agent user "${u.username}" has read access to ${sensitiveReadable.length} object(s) that carry ` +
|
|
170
|
+
`Data Classification / Compliance Group markings (PII, PCI, HIPAA, GDPR, etc.): ` +
|
|
171
|
+
`${sensitiveReadable.join(', ')}. An injected prompt can exfiltrate exactly this classified data ` +
|
|
172
|
+
`through whatever channel the agent is exposed on.`,
|
|
173
|
+
remediation: 'Confirm the agent legitimately needs to read these sensitive objects. If not, remove read access. ' +
|
|
174
|
+
'Where it is required, ensure the agent\'s output channels are internal-only and monitored.',
|
|
175
|
+
affectedItems: sensitiveReadable.map((o) => ({
|
|
176
|
+
label: o,
|
|
177
|
+
note: 'read access, object has classified (sensitive) fields',
|
|
178
|
+
})),
|
|
179
|
+
});
|
|
180
|
+
}
|
|
181
|
+
}
|
|
182
|
+
// Objects that have at least one classified field. Reuses DataClassificationCheck's
|
|
183
|
+
// FieldDefinition/ComplianceGroup query, scoped to the objects the agent users can read.
|
|
184
|
+
// Returns an empty set (sub-signal silently skipped) if there is no classification data
|
|
185
|
+
// or the Tooling query is unavailable.
|
|
186
|
+
async querySensitiveObjects(ctx, readableObjects) {
|
|
187
|
+
if (readableObjects.length === 0)
|
|
188
|
+
return new Set();
|
|
189
|
+
const objList = readableObjects.map((o) => `'${o}'`).join(', ');
|
|
190
|
+
try {
|
|
191
|
+
const rows = await ctx.tooling.query(`SELECT EntityDefinition.QualifiedApiName objectName, COUNT(Id) classifiedCount
|
|
192
|
+
FROM FieldDefinition
|
|
193
|
+
WHERE EntityDefinition.QualifiedApiName IN (${objList})
|
|
194
|
+
AND ComplianceGroup != null
|
|
195
|
+
GROUP BY EntityDefinition.QualifiedApiName`);
|
|
196
|
+
return new Set(rows.filter((r) => (r.classifiedCount ?? 0) > 0).map((r) => r.objectName));
|
|
197
|
+
}
|
|
198
|
+
catch {
|
|
199
|
+
// No classification feature / no Tooling access: skip the sub-signal silently.
|
|
200
|
+
return new Set();
|
|
201
|
+
}
|
|
202
|
+
}
|
|
203
|
+
}
|
|
204
|
+
//# sourceMappingURL=AgentUserPrivilegeCheck.js.map
|
|
@@ -5,6 +5,7 @@ export declare class CspTrustedSitesCheck implements SecurityCheck {
|
|
|
5
5
|
readonly name = "CSP Trusted Sites";
|
|
6
6
|
readonly category = "Network Security";
|
|
7
7
|
readonly description = "Checks Content Security Policy trusted sites for insecure HTTP endpoints that allow mixed-content loading.";
|
|
8
|
+
readonly populatesCache: readonly ["cspTrustedSites"];
|
|
8
9
|
run(ctx: AuditContext): Promise<CheckResult>;
|
|
9
10
|
}
|
|
10
11
|
//# sourceMappingURL=CspTrustedSitesCheck.d.ts.map
|
|
@@ -3,8 +3,17 @@ export class CspTrustedSitesCheck {
|
|
|
3
3
|
name = 'CSP Trusted Sites';
|
|
4
4
|
category = 'Network Security';
|
|
5
5
|
description = 'Checks Content Security Policy trusted sites for insecure HTTP endpoints that allow mixed-content loading.';
|
|
6
|
+
// Shares the fetched trusted-sites allowlist with TrustedUrlHygieneCheck (AI & Agents)
|
|
7
|
+
// so it does not re-query CspTrustedSite. Findings/behavior are unchanged by this.
|
|
8
|
+
populatesCache = ['cspTrustedSites'];
|
|
6
9
|
async run(ctx) {
|
|
7
|
-
const sites = await ctx.soql.queryAll(`SELECT Id, EndpointUrl, Context, IsActive FROM CspTrustedSite WHERE IsActive = true`);
|
|
10
|
+
const sites = await ctx.soql.queryAll(`SELECT Id, DeveloperName, EndpointUrl, Context, IsActive FROM CspTrustedSite WHERE IsActive = true`);
|
|
11
|
+
ctx.cache.cspTrustedSites = sites.map((s) => ({
|
|
12
|
+
developerName: s.DeveloperName ?? '',
|
|
13
|
+
endpointUrl: s.EndpointUrl,
|
|
14
|
+
isActive: s.IsActive,
|
|
15
|
+
context: s.Context,
|
|
16
|
+
}));
|
|
8
17
|
if (sites.length === 0) {
|
|
9
18
|
return {
|
|
10
19
|
findings: [{
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import type { AuditContext } from '../../context/AuditContext.js';
|
|
2
|
+
import type { SecurityCheck, CheckResult } from '../SecurityCheck.js';
|
|
3
|
+
export declare class TrustedUrlHygieneCheck implements SecurityCheck {
|
|
4
|
+
readonly id = "trusted-url-hygiene";
|
|
5
|
+
readonly name = "Trusted URL Hygiene";
|
|
6
|
+
readonly category = "AI & Agents";
|
|
7
|
+
readonly description = "Reviews the CSP trusted-sites allowlist for non-Salesforce domains that could be repurposed as data-exfiltration channels (the ForcedLeak pattern). With --resolve-domains, DNS-checks each domain for unresolvable or parked entries.";
|
|
8
|
+
readonly dependsOnCache: readonly ["cspTrustedSites"];
|
|
9
|
+
run(ctx: AuditContext): Promise<CheckResult>;
|
|
10
|
+
private reviewFinding;
|
|
11
|
+
private unresolvableFinding;
|
|
12
|
+
private parkedFinding;
|
|
13
|
+
private unverifiableFinding;
|
|
14
|
+
}
|
|
15
|
+
export declare function extractDomain(endpoint: string): string | null;
|
|
16
|
+
//# sourceMappingURL=TrustedUrlHygieneCheck.d.ts.map
|