@cclabsnz/sf-audit 1.16.0 → 1.17.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/CHANGELOG.md +118 -1
- package/README.md +94 -24
- package/config/scoring.sample.json +104 -5
- package/lib/apps/analyzeApps.d.ts +8 -2
- package/lib/apps/analyzeApps.js +7 -2
- package/lib/apps/apiLogSource.d.ts +39 -0
- package/lib/apps/apiLogSource.js +75 -0
- package/lib/apps/appResolver.js +30 -4
- package/lib/apps/grantedAccess.js +16 -3
- package/lib/apps/leastPrivilege.d.ts +3 -1
- package/lib/apps/leastPrivilege.js +7 -3
- package/lib/apps/permissionSetGenerator.d.ts +22 -0
- package/lib/apps/permissionSetGenerator.js +100 -0
- package/lib/apps/types.d.ts +6 -0
- package/lib/apps/usageCollector.d.ts +7 -1
- package/lib/apps/usageCollector.js +57 -26
- package/lib/chains/CapabilityRegistry.js +26 -0
- package/lib/chains/namedChains.js +95 -7
- package/lib/checks/CheckEngine.d.ts +3 -1
- package/lib/checks/CheckEngine.js +11 -3
- package/lib/checks/impl/ApexCrudFLSCheck.js +45 -10
- package/lib/checks/impl/ApexSharingCheck.js +16 -25
- package/lib/checks/impl/AuthProviderRegistrationHandlerCheck.d.ts +10 -0
- package/lib/checks/impl/AuthProviderRegistrationHandlerCheck.js +131 -0
- package/lib/checks/impl/ConnectedAppsCheck.js +47 -1
- package/lib/checks/impl/DataCloudDataSpaceIsolationCheck.d.ts +10 -0
- package/lib/checks/impl/DataCloudDataSpaceIsolationCheck.js +116 -0
- package/lib/checks/impl/DelegatedAdministrationGroupsCheck.d.ts +10 -0
- package/lib/checks/impl/DelegatedAdministrationGroupsCheck.js +75 -0
- package/lib/checks/impl/DelegatedAuthenticationExposureCheck.d.ts +10 -0
- package/lib/checks/impl/DelegatedAuthenticationExposureCheck.js +98 -0
- package/lib/checks/impl/ExternalAccountHierarchyExposureCheck.d.ts +10 -0
- package/lib/checks/impl/ExternalAccountHierarchyExposureCheck.js +73 -0
- package/lib/checks/impl/FlowHttpCalloutCredentialBypassCheck.d.ts +10 -0
- package/lib/checks/impl/FlowHttpCalloutCredentialBypassCheck.js +115 -0
- package/lib/checks/impl/GenAiPromptTemplateGroundingCheck.d.ts +10 -0
- package/lib/checks/impl/GenAiPromptTemplateGroundingCheck.js +227 -0
- package/lib/checks/impl/GuestExecutableApexCheck.d.ts +1 -1
- package/lib/checks/impl/GuestExecutableApexCheck.js +105 -14
- package/lib/checks/impl/HardcodedCredentialsCheck.js +7 -2
- package/lib/checks/impl/InboundEmailHandlerExposureCheck.d.ts +10 -0
- package/lib/checks/impl/InboundEmailHandlerExposureCheck.js +136 -0
- package/lib/checks/impl/OauthDeviceAndAssetTokenFlowsCheck.d.ts +10 -0
- package/lib/checks/impl/OauthDeviceAndAssetTokenFlowsCheck.js +84 -0
- package/lib/checks/impl/OrgWideEmailSpoofingCheck.d.ts +10 -0
- package/lib/checks/impl/OrgWideEmailSpoofingCheck.js +106 -0
- package/lib/checks/impl/PackagePostInstallSupplyChainCheck.d.ts +10 -0
- package/lib/checks/impl/PackagePostInstallSupplyChainCheck.js +89 -0
- package/lib/checks/impl/PlatformEventSubscriberContextCheck.d.ts +10 -0
- package/lib/checks/impl/PlatformEventSubscriberContextCheck.js +84 -0
- package/lib/checks/impl/RestrictionRulesIntegrityCheck.d.ts +10 -0
- package/lib/checks/impl/RestrictionRulesIntegrityCheck.js +105 -0
- package/lib/checks/impl/ShieldTenantSecretLifecycleCheck.d.ts +10 -0
- package/lib/checks/impl/ShieldTenantSecretLifecycleCheck.js +90 -0
- package/lib/checks/registry.js +30 -0
- package/lib/checks/support/apexAccess.d.ts +56 -0
- package/lib/checks/support/apexAccess.js +127 -0
- package/lib/checks/support/missingObject.d.ts +13 -0
- package/lib/checks/support/missingObject.js +35 -0
- package/lib/commands/audit/apps.d.ts +1 -0
- package/lib/commands/audit/apps.js +83 -29
- package/lib/commands/audit/diff.js +2 -2
- package/lib/commands/audit/history.js +2 -2
- package/lib/commands/audit/incident/report.js +2 -2
- package/lib/commands/audit/security.d.ts +3 -0
- package/lib/commands/audit/security.js +58 -9
- package/lib/commands/audit/timeline.js +2 -2
- package/lib/compliance/mapping.js +28 -7
- package/lib/findings/AuditResult.d.ts +8 -0
- package/lib/findings/CheckMeta.js +15 -0
- package/lib/findings/Finding.d.ts +4 -0
- package/lib/findings/ScoringConfig.d.ts +10 -8
- package/lib/findings/ScoringConfig.js +12 -5
- package/lib/findings/coverage.d.ts +28 -0
- package/lib/findings/coverage.js +30 -0
- package/lib/findings/exitCode.js +1 -1
- package/lib/findings/loadScoringConfig.js +51 -8
- package/lib/findings/scoring.js +14 -5
- package/lib/history/HistoryStore.js +9 -3
- package/lib/history/archivePolicy.d.ts +19 -0
- package/lib/history/archivePolicy.js +34 -0
- package/lib/incident/bundleIo.js +4 -3
- package/lib/incident/collect/collectBundle.d.ts +1 -1
- package/lib/incident/collect/collectBundle.js +4 -3
- package/lib/incident/collect/streamGuestLogs.d.ts +1 -1
- package/lib/incident/collect/streamGuestLogs.js +3 -2
- package/lib/incident/csv.js +4 -4
- package/lib/incident/render/evidence.js +3 -3
- package/lib/incident/render/html.js +2 -3
- package/lib/index.d.ts +2 -0
- package/lib/index.js +2 -0
- package/lib/lib/packageInfo.d.ts +6 -0
- package/lib/lib/packageInfo.js +19 -0
- package/lib/renderers/AttackChainDagRenderer.d.ts +7 -0
- package/lib/renderers/AttackChainDagRenderer.js +139 -0
- package/lib/renderers/ClientReportRenderer.d.ts +2 -0
- package/lib/renderers/ClientReportRenderer.js +34 -6
- package/lib/renderers/DiffHtmlRenderer.js +2 -7
- package/lib/renderers/HistoryRenderer.js +19 -11
- package/lib/renderers/HtmlRenderer.js +19 -6
- package/lib/renderers/MarkdownRenderer.js +7 -0
- package/lib/renderers/SarifRenderer.d.ts +43 -0
- package/lib/renderers/SarifRenderer.js +250 -0
- package/lib/report/ExecutivePriorities.js +1 -1
- package/lib/report/RemediationRoadmap.js +1 -1
- package/lib/waivers/WaiverLoader.d.ts +28 -0
- package/lib/waivers/WaiverLoader.js +103 -0
- package/lib/waivers/WaiverModel.d.ts +32 -0
- package/lib/waivers/WaiverModel.js +28 -0
- package/lib/waivers/applyWaivers.d.ts +22 -0
- package/lib/waivers/applyWaivers.js +85 -0
- package/package.json +3 -3
|
@@ -1,11 +1,27 @@
|
|
|
1
1
|
import { ApexRepository } from '@cclabsnz/sf-core';
|
|
2
|
-
|
|
3
|
-
|
|
2
|
+
import { declaresWithoutSharing, effectiveSharing, parentClass, usesSystemMode } from '../support/apexAccess.js';
|
|
3
|
+
/**
|
|
4
|
+
* The org-local classes a class calls, as its compiled SymbolTable records them. A reference with a
|
|
5
|
+
* namespace is to packaged code, which the audit does not read, so it never resolves to a local
|
|
6
|
+
* class that happens to share its name.
|
|
7
|
+
*/
|
|
8
|
+
function referencedClasses(symbolTable) {
|
|
9
|
+
const refs = symbolTable
|
|
10
|
+
?.externalReferences;
|
|
11
|
+
if (!Array.isArray(refs))
|
|
12
|
+
return [];
|
|
13
|
+
return refs
|
|
14
|
+
.filter((r) => !(typeof r?.namespace === 'string' && r.namespace !== ''))
|
|
15
|
+
.map((r) => r?.name)
|
|
16
|
+
.filter((n) => typeof n === 'string' && n !== '')
|
|
17
|
+
// An inner class is referenced as Outer.Inner; its code lives in the outer class's body.
|
|
18
|
+
.map((n) => n.split('.')[0]);
|
|
19
|
+
}
|
|
4
20
|
export class GuestExecutableApexCheck {
|
|
5
21
|
id = 'guest-executable-apex';
|
|
6
22
|
name = 'Guest-Executable Apex';
|
|
7
23
|
category = 'Access Control';
|
|
8
|
-
description = 'Finds Apex classes that unauthenticated guest profiles can execute, flagging those that run without sharing
|
|
24
|
+
description = 'Finds Apex classes that unauthenticated guest profiles can execute, flagging those that run without sharing, call a without-sharing helper, or switch off CRUD/FLS with SYSTEM_MODE';
|
|
9
25
|
// Use cached Apex bodies (from HardcodedCredentialsCheck) when available to classify sharing.
|
|
10
26
|
dependsOnCache = ['apexBodies'];
|
|
11
27
|
async run(ctx) {
|
|
@@ -45,18 +61,75 @@ export class GuestExecutableApexCheck {
|
|
|
45
61
|
// fails the whole query with "invalid ID field", losing every good row with it.
|
|
46
62
|
const nameById = await new ApexRepository(ctx.tooling).namesByIds(classIds);
|
|
47
63
|
const bodies = ctx.cache.apexBodies ?? [];
|
|
48
|
-
|
|
64
|
+
// Apex names are case-insensitive, and a SymbolTable may spell one differently from its declaration.
|
|
65
|
+
const byName = new Map(bodies.map((b) => [b.name.toLowerCase(), b]));
|
|
66
|
+
/**
|
|
67
|
+
* Everything reachable from `start` through SymbolTable references: whichever class is declared
|
|
68
|
+
* without sharing, at any depth, runs its own code without sharing (spec RULE-004), and SYSTEM_MODE
|
|
69
|
+
* anywhere on the path lifts CRUD/FLS for the guest (RULE-003).
|
|
70
|
+
*/
|
|
71
|
+
const bodyOf = (n) => byName.get(n.toLowerCase())?.body;
|
|
72
|
+
// A class reaches what its SymbolTable references, and the class it extends: inherited methods
|
|
73
|
+
// run with the parent's own sharing.
|
|
74
|
+
const neighbours = (n) => {
|
|
75
|
+
const entry = byName.get(n.toLowerCase());
|
|
76
|
+
const parent = entry?.body ? parentClass(n, entry.body) : undefined;
|
|
77
|
+
return [...referencedClasses(entry?.symbolTable), ...(parent ? [parent] : [])];
|
|
78
|
+
};
|
|
79
|
+
const reach = (start) => {
|
|
80
|
+
const seen = new Set([start.toLowerCase()]);
|
|
81
|
+
const queue = neighbours(start);
|
|
82
|
+
let systemModeAt;
|
|
83
|
+
while (queue.length > 0) {
|
|
84
|
+
const ref = queue.shift();
|
|
85
|
+
if (seen.has(ref.toLowerCase()))
|
|
86
|
+
continue;
|
|
87
|
+
seen.add(ref.toLowerCase());
|
|
88
|
+
const helper = byName.get(ref.toLowerCase());
|
|
89
|
+
if (!helper?.body)
|
|
90
|
+
continue;
|
|
91
|
+
if (declaresWithoutSharing(helper.body))
|
|
92
|
+
return { withoutSharing: helper.name };
|
|
93
|
+
if (!systemModeAt && usesSystemMode(helper.body))
|
|
94
|
+
systemModeAt = helper.name;
|
|
95
|
+
queue.push(...neighbours(helper.name));
|
|
96
|
+
}
|
|
97
|
+
return { systemMode: systemModeAt };
|
|
98
|
+
};
|
|
99
|
+
// spec/apex-access-mode.md. A guest call is an entry point: no keyword means without sharing,
|
|
100
|
+
// and inherited sharing means with sharing. SYSTEM_MODE bypasses CRUD/FLS only (RULE-003); a
|
|
101
|
+
// helper declared without sharing bypasses sharing for whatever it does (RULE-004).
|
|
49
102
|
const unprotected = [];
|
|
103
|
+
const systemMode = [];
|
|
50
104
|
const exposed = [];
|
|
51
105
|
for (const id of classIds) {
|
|
52
106
|
const name = nameById.get(id) ?? id;
|
|
53
|
-
const
|
|
54
|
-
|
|
55
|
-
|
|
107
|
+
const entry = byName.get(name.toLowerCase());
|
|
108
|
+
const body = entry?.body;
|
|
109
|
+
// A class with no keyword takes the sharing of the class it extends (spec MN-001).
|
|
110
|
+
const keyword = body ? effectiveSharing(name, body, bodyOf) : null;
|
|
111
|
+
if (keyword === 'without' || (keyword !== null && body && declaresWithoutSharing(body))) {
|
|
112
|
+
unprotected.push({
|
|
113
|
+
name,
|
|
114
|
+
note: keyword === 'without' ? 'Declared "without sharing": fix immediately' : 'Contains an inner class declared "without sharing"',
|
|
115
|
+
});
|
|
116
|
+
continue;
|
|
117
|
+
}
|
|
118
|
+
if (keyword === 'none') {
|
|
119
|
+
unprotected.push({ name, note: 'No sharing declaration: runs without sharing when a guest calls it' });
|
|
120
|
+
continue;
|
|
121
|
+
}
|
|
122
|
+
if (keyword === null || !body) {
|
|
123
|
+
// No readable body (managed or hidden): its sharing cannot be judged.
|
|
124
|
+
exposed.push(name);
|
|
125
|
+
continue;
|
|
126
|
+
}
|
|
127
|
+
const path = reach(name);
|
|
128
|
+
if (path.withoutSharing) {
|
|
129
|
+
unprotected.push({ name, note: `Reaches "${path.withoutSharing}", which is declared "without sharing"` });
|
|
56
130
|
}
|
|
57
|
-
else if (body
|
|
58
|
-
|
|
59
|
-
unprotected.push(name);
|
|
131
|
+
else if (usesSystemMode(body) || path.systemMode) {
|
|
132
|
+
systemMode.push({ name, via: usesSystemMode(body) ? undefined : path.systemMode });
|
|
60
133
|
}
|
|
61
134
|
else {
|
|
62
135
|
exposed.push(name);
|
|
@@ -68,12 +141,30 @@ export class GuestExecutableApexCheck {
|
|
|
68
141
|
id: 'guest-executable-apex-unprotected',
|
|
69
142
|
category: this.category,
|
|
70
143
|
riskLevel: 'CRITICAL',
|
|
71
|
-
title: `${unprotected.length} guest-executable Apex class(es) run without
|
|
72
|
-
detail: 'These Apex classes can be invoked by unauthenticated guest users AND do not enforce record-level sharing
|
|
144
|
+
title: `${unprotected.length} guest-executable Apex class(es) run without sharing, directly or through a helper`,
|
|
145
|
+
detail: 'These Apex classes can be invoked by unauthenticated guest users AND do not enforce record-level sharing, ' +
|
|
146
|
+
'either themselves or in a helper class they call that is declared "without sharing". ' +
|
|
73
147
|
'This is the classic Salesforce guest-user exploit chain: an attacker calls the class and reads or writes ' +
|
|
74
148
|
'business data in bulk with no login. Object-level guest permissions do not mitigate this: the class runs in system context.',
|
|
75
|
-
remediation: 'Add "with sharing" to every guest-reachable Apex class, enforce CRUD/FLS, and remove guest execution access from any class that does not strictly need it.',
|
|
76
|
-
affectedItems: unprotected.map((
|
|
149
|
+
remediation: 'Add "with sharing" to every guest-reachable Apex class and to every helper it calls, enforce CRUD/FLS, and remove guest execution access from any class that does not strictly need it.',
|
|
150
|
+
affectedItems: unprotected.map((u) => ({ label: u.name, url: apexUrl, note: u.note })),
|
|
151
|
+
});
|
|
152
|
+
}
|
|
153
|
+
if (systemMode.length > 0) {
|
|
154
|
+
findings.push({
|
|
155
|
+
id: 'guest-executable-apex-system-mode',
|
|
156
|
+
category: this.category,
|
|
157
|
+
riskLevel: 'HIGH',
|
|
158
|
+
title: `${systemMode.length} guest-executable Apex class(es) switch off CRUD/FLS with SYSTEM_MODE`,
|
|
159
|
+
detail: 'Guest users can execute these classes, which enforce sharing but run queries or DML with WITH SYSTEM_MODE or ' +
|
|
160
|
+
'AccessLevel.SYSTEM_MODE. Sharing still limits which records a guest reaches, but not which objects and fields: ' +
|
|
161
|
+
'a guest can read or change fields the guest profile is denied on any record shared with guests.',
|
|
162
|
+
remediation: 'Replace SYSTEM_MODE with USER_MODE in guest-reachable code, or strip fields with Security.stripInaccessible() before returning results. Remove guest access where unnecessary.',
|
|
163
|
+
affectedItems: systemMode.map(({ name, via }) => ({
|
|
164
|
+
label: name,
|
|
165
|
+
url: apexUrl,
|
|
166
|
+
note: via ? `Calls "${via}", which uses SYSTEM_MODE: guest CRUD/FLS not enforced` : 'SYSTEM_MODE: guest CRUD/FLS not enforced',
|
|
167
|
+
})),
|
|
77
168
|
});
|
|
78
169
|
}
|
|
79
170
|
if (exposed.length > 0) {
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { apexCode } from '../support/apexAccess.js';
|
|
1
2
|
import { ApexRepository } from '@cclabsnz/sf-core';
|
|
2
3
|
const HIGH_RISK_PATTERNS = [
|
|
3
4
|
/Bearer\s+[A-Za-z0-9\-_.~+/]{20,}=*/gi, // Bearer tokens (min length to avoid test stubs)
|
|
@@ -38,10 +39,14 @@ export class HardcodedCredentialsCheck {
|
|
|
38
39
|
Body: c.body ?? '',
|
|
39
40
|
LengthWithoutComments: (c.body ?? '').length,
|
|
40
41
|
NamespacePrefix: c.namespace,
|
|
42
|
+
SymbolTable: c.symbolTable,
|
|
41
43
|
}));
|
|
42
44
|
// Cache apex bodies for downstream checks — exclude test classes and filter null bodies
|
|
43
|
-
|
|
44
|
-
|
|
45
|
+
// @IsTest is read from code only: a production helper mentioning it in a comment must still
|
|
46
|
+
// reach the cache, or the checks that follow calls into it never see its sharing (spec MN-002).
|
|
47
|
+
const nonTestRecords = records.filter((r) => !IS_TEST_CLASS.test(apexCode(r.Body ?? '')));
|
|
48
|
+
// The SymbolTable travels with the body so GuestExecutableApexCheck can follow calls into helpers.
|
|
49
|
+
ctx.cache.apexBodies = nonTestRecords.map((r) => ({ name: r.Name, body: r.Body ?? '', symbolTable: r.SymbolTable }));
|
|
45
50
|
const namedCredentialEndpoints = (ctx.cache.namedCredentialEndpoints ?? []).filter(Boolean);
|
|
46
51
|
const remoteSiteUrls = (ctx.cache.remoteSiteUrls ?? []).filter(Boolean);
|
|
47
52
|
const classesWithCredentials = [];
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import type { AuditContext } from '@cclabsnz/sf-core';
|
|
2
|
+
import type { SecurityCheck, CheckResult } from '../SecurityCheck.js';
|
|
3
|
+
export declare class InboundEmailHandlerExposureCheck implements SecurityCheck {
|
|
4
|
+
readonly id = "inbound-email-handler-exposure";
|
|
5
|
+
readonly name = "Inbound Email Handler Unauthenticated Execution";
|
|
6
|
+
readonly category = "External Connectivity";
|
|
7
|
+
readonly description = "Detects active inbound email services open to all senders without SPF/DKIM verification executing Apex under privileged users.";
|
|
8
|
+
run(ctx: AuditContext): Promise<CheckResult>;
|
|
9
|
+
}
|
|
10
|
+
//# sourceMappingURL=InboundEmailHandlerExposureCheck.d.ts.map
|
|
@@ -0,0 +1,136 @@
|
|
|
1
|
+
export class InboundEmailHandlerExposureCheck {
|
|
2
|
+
id = 'inbound-email-handler-exposure';
|
|
3
|
+
name = 'Inbound Email Handler Unauthenticated Execution';
|
|
4
|
+
category = 'External Connectivity';
|
|
5
|
+
description = 'Detects active inbound email services open to all senders without SPF/DKIM verification executing Apex under privileged users.';
|
|
6
|
+
async run(ctx) {
|
|
7
|
+
const findings = [];
|
|
8
|
+
const baseUrl = ctx.orgInfo.instanceUrl;
|
|
9
|
+
const emailToApexUrl = `${baseUrl}/lightning/setup/EmailToApex/home`;
|
|
10
|
+
let functions = [];
|
|
11
|
+
try {
|
|
12
|
+
functions = await ctx.soql.queryAll('SELECT Id, FunctionName, IsActive, RunAsUserId, ApexClassId, AuthenticationFailureAction FROM EmailServicesFunction WHERE IsActive = true');
|
|
13
|
+
}
|
|
14
|
+
catch (err) {
|
|
15
|
+
// This object exists in every org, so a failure is lack of access, never an absent feature.
|
|
16
|
+
findings.push({
|
|
17
|
+
id: 'inbound-email-handler-exposure-inaccessible',
|
|
18
|
+
category: this.category,
|
|
19
|
+
riskLevel: 'INFO',
|
|
20
|
+
inconclusive: true,
|
|
21
|
+
title: 'Email Services Functions could not be queried',
|
|
22
|
+
detail: `Query to EmailServicesFunction failed: ${err instanceof Error ? err.message : String(err)}`,
|
|
23
|
+
remediation: 'Grant the audit user "View Setup and Configuration".',
|
|
24
|
+
});
|
|
25
|
+
return { findings };
|
|
26
|
+
}
|
|
27
|
+
if (functions.length === 0) {
|
|
28
|
+
findings.push({
|
|
29
|
+
id: 'inbound-email-handler-exposure-ok',
|
|
30
|
+
category: this.category,
|
|
31
|
+
riskLevel: 'LOW',
|
|
32
|
+
passed: true,
|
|
33
|
+
title: 'No active inbound Email-to-Apex services found',
|
|
34
|
+
detail: 'Zero active EmailServicesFunction records exist in the org.',
|
|
35
|
+
remediation: 'When creating inbound email services, enforce sender restrictions and SPF/DKIM verification.',
|
|
36
|
+
});
|
|
37
|
+
return { findings };
|
|
38
|
+
}
|
|
39
|
+
// Query active EmailServicesAddress records
|
|
40
|
+
let addresses = [];
|
|
41
|
+
addresses = await ctx.soql.queryAll('SELECT Id, FunctionId, LocalPart, EmailDomainName, IsActive, AuthorizedSenders FROM EmailServicesAddress WHERE IsActive = true');
|
|
42
|
+
const addressesByFunction = new Map();
|
|
43
|
+
for (const a of addresses) {
|
|
44
|
+
const list = addressesByFunction.get(a.FunctionId) ?? [];
|
|
45
|
+
list.push(a);
|
|
46
|
+
addressesByFunction.set(a.FunctionId, list);
|
|
47
|
+
}
|
|
48
|
+
// Query RunAs users
|
|
49
|
+
const runAsUserIds = [
|
|
50
|
+
...new Set(functions.map((f) => f.RunAsUserId).filter((id) => Boolean(id))),
|
|
51
|
+
];
|
|
52
|
+
let adminUsers = new Set();
|
|
53
|
+
let userDetails = new Map();
|
|
54
|
+
if (runAsUserIds.length > 0) {
|
|
55
|
+
const users = await ctx.soql.queryAll(`SELECT Id, Username, Profile.Name FROM User WHERE Id IN ('${runAsUserIds.join("','")}')`);
|
|
56
|
+
for (const u of users) {
|
|
57
|
+
const prof = u.Profile?.Name ?? '';
|
|
58
|
+
userDetails.set(u.Id, `${u.Username} (${prof})`);
|
|
59
|
+
if (prof === 'System Administrator' || prof.toLowerCase().includes('admin')) {
|
|
60
|
+
adminUsers.add(u.Id);
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
// Query Apex Classes
|
|
65
|
+
const apexClassIds = [
|
|
66
|
+
...new Set(functions.map((f) => f.ApexClassId).filter((id) => Boolean(id))),
|
|
67
|
+
];
|
|
68
|
+
let classBodies = new Map();
|
|
69
|
+
let classNames = new Map();
|
|
70
|
+
if (apexClassIds.length > 0) {
|
|
71
|
+
const classes = await ctx.soql.queryAll(`SELECT Id, Name, Body FROM ApexClass WHERE Id IN ('${apexClassIds.join("','")}')`);
|
|
72
|
+
for (const c of classes) {
|
|
73
|
+
classNames.set(c.Id, c.Name);
|
|
74
|
+
classBodies.set(c.Id, c.Body ?? '');
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
const exposedFunctions = [];
|
|
78
|
+
for (const fn of functions) {
|
|
79
|
+
const funcAddresses = addressesByFunction.get(fn.Id) ?? [];
|
|
80
|
+
// Check 1: Any address with empty/blank AuthorizedSenders
|
|
81
|
+
const openAddress = funcAddresses.find((a) => !a.AuthorizedSenders || a.AuthorizedSenders.trim() === '');
|
|
82
|
+
// Check 2: AuthenticationFailureAction is 0 or '0' (None / accept even spoofed emails)
|
|
83
|
+
const authFailureAction = String(fn.AuthenticationFailureAction ?? '0');
|
|
84
|
+
const acceptsSpoofedEmail = authFailureAction === '0' || authFailureAction === '';
|
|
85
|
+
// Check 3: RunAsUserId is admin or class runs without sharing / performs DML
|
|
86
|
+
const isRunAsAdmin = fn.RunAsUserId ? adminUsers.has(fn.RunAsUserId) : false;
|
|
87
|
+
const classBody = fn.ApexClassId ? classBodies.get(fn.ApexClassId) ?? '' : '';
|
|
88
|
+
const isWithoutSharing = /without\s+sharing/i.test(classBody);
|
|
89
|
+
const hasDmlOrDynamicSoql = /insert\s+|update\s+|upsert\s+|delete\s+|Database\.execute/i.test(classBody);
|
|
90
|
+
if (openAddress && acceptsSpoofedEmail && (isRunAsAdmin || isWithoutSharing || hasDmlOrDynamicSoql)) {
|
|
91
|
+
const addrStr = `${openAddress.LocalPart}${openAddress.EmailDomainName ? '@' + openAddress.EmailDomainName : ''}`;
|
|
92
|
+
const reasons = [
|
|
93
|
+
'No sender restriction (AuthorizedSenders is blank)',
|
|
94
|
+
'AuthenticationFailureAction is set to None (accepts spoofed SPF/DKIM)',
|
|
95
|
+
isRunAsAdmin ? 'Runs as System Administrator' : '',
|
|
96
|
+
isWithoutSharing ? 'Apex runs without sharing' : '',
|
|
97
|
+
]
|
|
98
|
+
.filter(Boolean)
|
|
99
|
+
.join('; ');
|
|
100
|
+
exposedFunctions.push({
|
|
101
|
+
func: fn,
|
|
102
|
+
address: addrStr,
|
|
103
|
+
reason: reasons,
|
|
104
|
+
});
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
if (exposedFunctions.length > 0) {
|
|
108
|
+
findings.push({
|
|
109
|
+
id: 'inbound-email-handler-unauthenticated-execution',
|
|
110
|
+
category: this.category,
|
|
111
|
+
riskLevel: 'HIGH',
|
|
112
|
+
title: `${exposedFunctions.length} inbound email service(s) allow unauthenticated remote Apex execution`,
|
|
113
|
+
detail: 'Active EmailServicesFunction records accept messages from any internet sender with no SPF/DKIM authentication enforcement (AuthenticationFailureAction = 0 / None) and execute under a privileged System Administrator or in an Apex class running without sharing. An external attacker sending an email can trigger unauthenticated backend DML or privilege escalation.',
|
|
114
|
+
remediation: 'Configure "Accept Email From" with an authorized domain allowlist, set the Failure Action to "Bounce message" or "Discard message" upon SPF/DKIM verification failure, and run the service under a least-privileged execution user.',
|
|
115
|
+
affectedItems: exposedFunctions.map((item) => ({
|
|
116
|
+
label: `${item.func.FunctionName} (${item.address})`,
|
|
117
|
+
url: emailToApexUrl,
|
|
118
|
+
note: item.reason,
|
|
119
|
+
})),
|
|
120
|
+
});
|
|
121
|
+
}
|
|
122
|
+
else {
|
|
123
|
+
findings.push({
|
|
124
|
+
id: 'inbound-email-handler-exposure-ok',
|
|
125
|
+
category: this.category,
|
|
126
|
+
riskLevel: 'LOW',
|
|
127
|
+
passed: true,
|
|
128
|
+
title: 'Inbound email services enforce sender restrictions and authentication controls',
|
|
129
|
+
detail: `${functions.length} active inbound email service(s) inspected; all require authentication, enforce sender allowlists, or execute under constrained least-privilege contexts.`,
|
|
130
|
+
remediation: 'Continue enforcing sender allowlists and bounce/discard policies on SPF/DKIM failure.',
|
|
131
|
+
});
|
|
132
|
+
}
|
|
133
|
+
return { findings };
|
|
134
|
+
}
|
|
135
|
+
}
|
|
136
|
+
//# sourceMappingURL=InboundEmailHandlerExposureCheck.js.map
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import type { AuditContext } from '@cclabsnz/sf-core';
|
|
2
|
+
import type { SecurityCheck, CheckResult } from '../SecurityCheck.js';
|
|
3
|
+
export declare class OauthDeviceAndAssetTokenFlowsCheck implements SecurityCheck {
|
|
4
|
+
readonly id = "oauth-device-and-asset-token-flows";
|
|
5
|
+
readonly name = "OAuth Device & Password Flows";
|
|
6
|
+
readonly category = "Identity & Access";
|
|
7
|
+
readonly description = "Flags OAuth 2.0 Device Flow and Username-Password Flow enabled in OAuth and OpenID Connect Settings.";
|
|
8
|
+
run(ctx: AuditContext): Promise<CheckResult>;
|
|
9
|
+
}
|
|
10
|
+
//# sourceMappingURL=OauthDeviceAndAssetTokenFlowsCheck.d.ts.map
|
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
export class OauthDeviceAndAssetTokenFlowsCheck {
|
|
2
|
+
id = 'oauth-device-and-asset-token-flows';
|
|
3
|
+
name = 'OAuth Device & Password Flows';
|
|
4
|
+
category = 'Identity & Access';
|
|
5
|
+
description = 'Flags OAuth 2.0 Device Flow and Username-Password Flow enabled in OAuth and OpenID Connect Settings.';
|
|
6
|
+
async run(ctx) {
|
|
7
|
+
const findings = [];
|
|
8
|
+
const oauthUrl = `${ctx.orgInfo.instanceUrl}/lightning/setup/OauthOidcSettings/home`;
|
|
9
|
+
// Org settings are the only evidence read. A flag counts only when the read returned it as
|
|
10
|
+
// a boolean: a failed read, an absent Metadata client or a missing field is not "disabled".
|
|
11
|
+
let settings = null;
|
|
12
|
+
if (ctx.metadata) {
|
|
13
|
+
try {
|
|
14
|
+
settings = await ctx.metadata.read('OauthOidcSettings', 'OauthOidc');
|
|
15
|
+
}
|
|
16
|
+
catch {
|
|
17
|
+
settings = null;
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
const device = typeof settings?.isDeviceFlowEnabled === 'boolean' ? settings.isDeviceFlowEnabled : undefined;
|
|
21
|
+
const password = typeof settings?.isPasswordFlowEnabled === 'boolean' ? settings.isPasswordFlowEnabled : undefined;
|
|
22
|
+
if (device === true) {
|
|
23
|
+
findings.push({
|
|
24
|
+
id: 'oauth-device-flow-enabled',
|
|
25
|
+
category: this.category,
|
|
26
|
+
riskLevel: 'HIGH',
|
|
27
|
+
title: 'OAuth 2.0 Device Flow is ENABLED in org settings',
|
|
28
|
+
detail: 'OAuth 2.0 Device Flow allows a user to authorize a token by entering an 8-character code on a legitimate verification URL. Attackers frequently use Device Code phishing to bypass standard browser-based conditional access and MFA controls, obtaining persistent refresh tokens.',
|
|
29
|
+
remediation: 'Disable OAuth 2.0 Device Flow in Setup → OAuth and OpenID Connect Settings unless strictly required for headless devices.',
|
|
30
|
+
affectedItems: [
|
|
31
|
+
{
|
|
32
|
+
label: 'OAuth and OpenID Connect Settings',
|
|
33
|
+
url: oauthUrl,
|
|
34
|
+
note: 'Disable "Allow OAuth Device Flow"',
|
|
35
|
+
},
|
|
36
|
+
],
|
|
37
|
+
});
|
|
38
|
+
}
|
|
39
|
+
if (password === true) {
|
|
40
|
+
findings.push({
|
|
41
|
+
id: 'oauth-password-flow-enabled',
|
|
42
|
+
category: this.category,
|
|
43
|
+
riskLevel: 'HIGH',
|
|
44
|
+
title: 'OAuth 2.0 Username-Password Flow is ENABLED in org settings',
|
|
45
|
+
detail: 'The Resource Owner Password Credentials (ROPC / Username-Password) flow allows exchanging raw credentials directly for access tokens, completely bypassing interactive SSO redirects, browser-based MFA, and device trust policies.',
|
|
46
|
+
remediation: 'Disable Username-Password Flow in Setup → OAuth and OpenID Connect Settings, and migrate integrations to OAuth 2.0 Client Credentials or JWT Bearer flow.',
|
|
47
|
+
affectedItems: [
|
|
48
|
+
{
|
|
49
|
+
label: 'OAuth and OpenID Connect Settings',
|
|
50
|
+
url: oauthUrl,
|
|
51
|
+
note: 'Disable "Allow Username-Password Flow"',
|
|
52
|
+
},
|
|
53
|
+
],
|
|
54
|
+
});
|
|
55
|
+
}
|
|
56
|
+
if (device === false && password === false) {
|
|
57
|
+
findings.push({
|
|
58
|
+
id: 'oauth-device-and-asset-flows-ok',
|
|
59
|
+
category: this.category,
|
|
60
|
+
riskLevel: 'LOW',
|
|
61
|
+
passed: true,
|
|
62
|
+
title: 'Phishable OAuth Device Flow and Username-Password Flow are disabled',
|
|
63
|
+
detail: 'Org settings confirm both OAuth 2.0 Device Flow and Username-Password Flow are disabled, eliminating secondary token-issuance backdoors.',
|
|
64
|
+
remediation: 'Keep Device Flow and Password Flow disabled org-wide.',
|
|
65
|
+
});
|
|
66
|
+
}
|
|
67
|
+
else if (device === undefined || password === undefined) {
|
|
68
|
+
const unread = [device === undefined && 'Device Flow', password === undefined && 'Username-Password Flow']
|
|
69
|
+
.filter(Boolean)
|
|
70
|
+
.join(' and ');
|
|
71
|
+
findings.push({
|
|
72
|
+
id: 'oauth-device-and-asset-flows-advisory',
|
|
73
|
+
category: this.category,
|
|
74
|
+
riskLevel: 'INFO',
|
|
75
|
+
title: `Verify the OAuth ${unread} setting manually`,
|
|
76
|
+
detail: `This run could not read the ${unread} setting from OAuth and OpenID Connect Settings, so whether it is enabled is unknown. Both flows let a token be issued outside the browser sign-in, bypassing MFA and conditional access.`,
|
|
77
|
+
remediation: 'In Setup → OAuth and OpenID Connect Settings, confirm "Allow OAuth Device Flow" and "Allow OAuth Username-Password Flows" are off unless a documented integration needs them.',
|
|
78
|
+
affectedItems: [{ label: 'OAuth and OpenID Connect Settings', url: oauthUrl }],
|
|
79
|
+
});
|
|
80
|
+
}
|
|
81
|
+
return { findings };
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
//# sourceMappingURL=OauthDeviceAndAssetTokenFlowsCheck.js.map
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import type { AuditContext } from '@cclabsnz/sf-core';
|
|
2
|
+
import type { SecurityCheck, CheckResult } from '../SecurityCheck.js';
|
|
3
|
+
export declare class OrgWideEmailSpoofingCheck implements SecurityCheck {
|
|
4
|
+
readonly id = "org-wide-email-spoofing";
|
|
5
|
+
readonly name = "Org-Wide Email Spoofing & DKIM Coverage";
|
|
6
|
+
readonly category = "External Connectivity";
|
|
7
|
+
readonly description = "Flags org-wide email addresses open to all profiles and missing DKIM keys enabling internal and outbound email spoofing.";
|
|
8
|
+
run(ctx: AuditContext): Promise<CheckResult>;
|
|
9
|
+
}
|
|
10
|
+
//# sourceMappingURL=OrgWideEmailSpoofingCheck.d.ts.map
|
|
@@ -0,0 +1,106 @@
|
|
|
1
|
+
import { isMissingObjectError } from '../support/missingObject.js';
|
|
2
|
+
export class OrgWideEmailSpoofingCheck {
|
|
3
|
+
id = 'org-wide-email-spoofing';
|
|
4
|
+
name = 'Org-Wide Email Spoofing & DKIM Coverage';
|
|
5
|
+
category = 'External Connectivity';
|
|
6
|
+
description = 'Flags org-wide email addresses open to all profiles and missing DKIM keys enabling internal and outbound email spoofing.';
|
|
7
|
+
async run(ctx) {
|
|
8
|
+
const findings = [];
|
|
9
|
+
const baseUrl = ctx.orgInfo.instanceUrl;
|
|
10
|
+
const owaUrl = `${baseUrl}/lightning/setup/OrgWideEmailAddresses/home`;
|
|
11
|
+
const dkimUrl = `${baseUrl}/lightning/setup/EmailDKIM/home`;
|
|
12
|
+
// 1. Query OrgWideEmailAddress
|
|
13
|
+
let owaRecords = [];
|
|
14
|
+
let owaInaccessible = false;
|
|
15
|
+
try {
|
|
16
|
+
owaRecords = await ctx.soql.queryAll('SELECT Id, Address, DisplayName, IsAllowAllProfiles FROM OrgWideEmailAddress');
|
|
17
|
+
}
|
|
18
|
+
catch (err) {
|
|
19
|
+
if (isMissingObjectError(err)) {
|
|
20
|
+
// Continue to DKIM check
|
|
21
|
+
}
|
|
22
|
+
else {
|
|
23
|
+
owaInaccessible = true;
|
|
24
|
+
findings.push({
|
|
25
|
+
id: 'org-wide-email-spoofing-inaccessible',
|
|
26
|
+
category: this.category,
|
|
27
|
+
riskLevel: 'INFO',
|
|
28
|
+
inconclusive: true,
|
|
29
|
+
title: 'OrgWideEmailAddress could not be queried',
|
|
30
|
+
detail: `Query to OrgWideEmailAddress failed: ${err instanceof Error ? err.message : String(err)}`,
|
|
31
|
+
remediation: 'Grant the audit user "View Setup and Configuration".',
|
|
32
|
+
});
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
const openOwaRecords = owaRecords.filter((r) => r.IsAllowAllProfiles);
|
|
36
|
+
if (openOwaRecords.length > 0) {
|
|
37
|
+
findings.push({
|
|
38
|
+
id: 'org-wide-email-spoofing-all-profiles',
|
|
39
|
+
category: this.category,
|
|
40
|
+
riskLevel: 'MEDIUM',
|
|
41
|
+
title: `${openOwaRecords.length} Org-Wide Email Address(es) are available to All Profiles`,
|
|
42
|
+
detail: 'Org-wide email addresses with "All Profiles" selected allow any internal user, guest user (if misconfigured), or automated Flow to send emails impersonating billing, support, or executive identities. In compromise or insider scenarios, this facilitates high-reputation phishing sent directly from legitimate Salesforce mail servers.',
|
|
43
|
+
remediation: 'Restrict each org-wide address to specific authorized profiles rather than granting access to all profiles.',
|
|
44
|
+
affectedItems: openOwaRecords.map((r) => ({
|
|
45
|
+
label: r.Address,
|
|
46
|
+
url: owaUrl,
|
|
47
|
+
note: `Display Name: "${r.DisplayName || 'None'}" exposed to all profiles`,
|
|
48
|
+
})),
|
|
49
|
+
});
|
|
50
|
+
}
|
|
51
|
+
// 2. Query DkimKey
|
|
52
|
+
let dkimKeys = [];
|
|
53
|
+
let dkimInaccessible = false;
|
|
54
|
+
try {
|
|
55
|
+
dkimKeys = await ctx.soql.queryAll('SELECT Id, Domain, IsActive FROM DkimKey');
|
|
56
|
+
}
|
|
57
|
+
catch (err) {
|
|
58
|
+
if (!isMissingObjectError(err)) {
|
|
59
|
+
dkimInaccessible = true;
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
const activeDkimKeys = dkimKeys.filter((k) => k.IsActive === true);
|
|
63
|
+
if (dkimInaccessible) {
|
|
64
|
+
findings.push({
|
|
65
|
+
id: 'org-wide-email-spoofing-dkim-inaccessible',
|
|
66
|
+
category: this.category,
|
|
67
|
+
riskLevel: 'INFO',
|
|
68
|
+
inconclusive: true,
|
|
69
|
+
title: 'DKIM keys could not be queried',
|
|
70
|
+
detail: 'DkimKey was not readable, so whether outbound Salesforce email is DKIM-signed is unknown.',
|
|
71
|
+
remediation: 'Grant the audit user "View Setup and Configuration", then re-run. Meanwhile check Setup → DKIM Keys manually.',
|
|
72
|
+
affectedItems: [{ label: 'DKIM Keys Configuration', url: dkimUrl }],
|
|
73
|
+
});
|
|
74
|
+
}
|
|
75
|
+
if (!dkimInaccessible && activeDkimKeys.length === 0) {
|
|
76
|
+
findings.push({
|
|
77
|
+
id: 'org-wide-email-spoofing-no-dkim',
|
|
78
|
+
category: this.category,
|
|
79
|
+
riskLevel: 'MEDIUM',
|
|
80
|
+
title: 'Zero active DKIM keys configured for outbound Salesforce email',
|
|
81
|
+
detail: 'Outbound emails sent from Salesforce without DKIM signatures are vulnerable to domain spoofing, recipient rejection, or landing in junk folders. Active DKIM keys ensure cryptographic origin authentication for all outbound Salesforce messages.',
|
|
82
|
+
remediation: 'Generate and activate DKIM keys in Setup → DKIM Keys for all corporate sending domains used by Salesforce.',
|
|
83
|
+
affectedItems: [
|
|
84
|
+
{
|
|
85
|
+
label: 'DKIM Keys Configuration',
|
|
86
|
+
url: dkimUrl,
|
|
87
|
+
note: 'No active DKIM keys found in org',
|
|
88
|
+
},
|
|
89
|
+
],
|
|
90
|
+
});
|
|
91
|
+
}
|
|
92
|
+
if (!owaInaccessible && !dkimInaccessible && openOwaRecords.length === 0 && activeDkimKeys.length > 0) {
|
|
93
|
+
findings.push({
|
|
94
|
+
id: 'org-wide-email-spoofing-ok',
|
|
95
|
+
category: this.category,
|
|
96
|
+
riskLevel: 'LOW',
|
|
97
|
+
passed: true,
|
|
98
|
+
title: 'Org-wide email addresses are properly scoped and DKIM signing is active',
|
|
99
|
+
detail: `${owaRecords.length} org-wide address(es) and ${activeDkimKeys.length} active DKIM key(s) verified; no all-profile exposure detected.`,
|
|
100
|
+
remediation: 'Maintain profile-based scoping on all org-wide sending addresses.',
|
|
101
|
+
});
|
|
102
|
+
}
|
|
103
|
+
return { findings };
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
//# sourceMappingURL=OrgWideEmailSpoofingCheck.js.map
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import type { AuditContext } from '@cclabsnz/sf-core';
|
|
2
|
+
import type { SecurityCheck, CheckResult } from '../SecurityCheck.js';
|
|
3
|
+
export declare class PackagePostInstallSupplyChainCheck implements SecurityCheck {
|
|
4
|
+
readonly id = "package-post-install-supply-chain";
|
|
5
|
+
readonly name = "Package Post-Install Supply Chain Risk";
|
|
6
|
+
readonly category = "Platform Hygiene";
|
|
7
|
+
readonly description = "Finds packaged Apex implementing InstallHandler, which runs in system context on every install and push upgrade.";
|
|
8
|
+
run(ctx: AuditContext): Promise<CheckResult>;
|
|
9
|
+
}
|
|
10
|
+
//# sourceMappingURL=PackagePostInstallSupplyChainCheck.d.ts.map
|
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
import { isMissingObjectError } from '../support/missingObject.js';
|
|
2
|
+
// Managed-package Apex is returned with its body replaced by this marker, so whether such a
|
|
3
|
+
// class implements InstallHandler cannot be read from the org.
|
|
4
|
+
const HIDDEN_BODY = '(hidden)';
|
|
5
|
+
const IMPLEMENTS_INSTALL_HANDLER = /\bimplements\b[^{]*\bInstallHandler\b/i;
|
|
6
|
+
export class PackagePostInstallSupplyChainCheck {
|
|
7
|
+
id = 'package-post-install-supply-chain';
|
|
8
|
+
name = 'Package Post-Install Supply Chain Risk';
|
|
9
|
+
category = 'Platform Hygiene';
|
|
10
|
+
description = 'Finds packaged Apex implementing InstallHandler, which runs in system context on every install and push upgrade.';
|
|
11
|
+
async run(ctx) {
|
|
12
|
+
const findings = [];
|
|
13
|
+
const packagesUrl = `${ctx.orgInfo.instanceUrl}/lightning/setup/ImportedPackage/home`;
|
|
14
|
+
let installedPackages;
|
|
15
|
+
try {
|
|
16
|
+
installedPackages = await ctx.tooling.query('SELECT Id, SubscriberPackageId FROM InstalledSubscriberPackage');
|
|
17
|
+
}
|
|
18
|
+
catch (err) {
|
|
19
|
+
if (!isMissingObjectError(err))
|
|
20
|
+
throw err;
|
|
21
|
+
installedPackages = [];
|
|
22
|
+
}
|
|
23
|
+
if (installedPackages.length === 0) {
|
|
24
|
+
findings.push({
|
|
25
|
+
id: 'package-post-install-ok',
|
|
26
|
+
category: this.category,
|
|
27
|
+
riskLevel: 'LOW',
|
|
28
|
+
passed: true,
|
|
29
|
+
title: 'No installed subscriber packages found in org',
|
|
30
|
+
detail: 'Zero InstalledSubscriberPackage records were identified.',
|
|
31
|
+
remediation: 'Continue inventorying new packages when installed.',
|
|
32
|
+
});
|
|
33
|
+
return { findings };
|
|
34
|
+
}
|
|
35
|
+
const namespacedClasses = await ctx.tooling.query('SELECT Id, Name, NamespacePrefix, Body FROM ApexClass WHERE NamespacePrefix != null');
|
|
36
|
+
const handlers = [];
|
|
37
|
+
const hiddenNamespaces = new Set();
|
|
38
|
+
for (const c of namespacedClasses) {
|
|
39
|
+
const classBody = c.Body ?? '';
|
|
40
|
+
if (classBody.trim() === HIDDEN_BODY || classBody === '') {
|
|
41
|
+
if (c.NamespacePrefix)
|
|
42
|
+
hiddenNamespaces.add(c.NamespacePrefix);
|
|
43
|
+
}
|
|
44
|
+
else if (IMPLEMENTS_INSTALL_HANDLER.test(classBody)) {
|
|
45
|
+
handlers.push(c);
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
if (handlers.length > 0) {
|
|
49
|
+
findings.push({
|
|
50
|
+
id: 'package-post-install-system-script',
|
|
51
|
+
category: this.category,
|
|
52
|
+
riskLevel: 'MEDIUM',
|
|
53
|
+
title: `${handlers.length} packaged class(es) implement InstallHandler and run on install and upgrade`,
|
|
54
|
+
detail: 'A class implementing InstallHandler runs unattended Apex in system context whenever its package is installed or upgraded, including vendor push upgrades. That execution bypasses admin approval and change-management gates.',
|
|
55
|
+
remediation: 'Review what each post-install script does, confirm the vendor publishes it, and agree a push-upgrade schedule with the vendor.',
|
|
56
|
+
affectedItems: handlers.map((c) => ({
|
|
57
|
+
label: `${c.NamespacePrefix}.${c.Name}`,
|
|
58
|
+
url: packagesUrl,
|
|
59
|
+
note: 'Implements InstallHandler',
|
|
60
|
+
})),
|
|
61
|
+
});
|
|
62
|
+
}
|
|
63
|
+
if (hiddenNamespaces.size > 0) {
|
|
64
|
+
const namespaces = [...hiddenNamespaces].sort();
|
|
65
|
+
findings.push({
|
|
66
|
+
id: 'package-post-install-unverifiable',
|
|
67
|
+
category: this.category,
|
|
68
|
+
riskLevel: 'INFO',
|
|
69
|
+
title: `${namespaces.length} managed package namespace(s) hide their Apex, so post-install scripts cannot be checked`,
|
|
70
|
+
detail: 'Managed packages hide their Apex source, so this run cannot tell whether any of them implements InstallHandler. A package that does runs Apex in system context on every install and push upgrade.',
|
|
71
|
+
remediation: 'Ask each vendor whether the package runs a post-install script and what it does, and review push-upgrade notices before they apply.',
|
|
72
|
+
affectedItems: namespaces.map((ns) => ({ label: `Namespace: ${ns}`, url: packagesUrl })),
|
|
73
|
+
});
|
|
74
|
+
}
|
|
75
|
+
if (handlers.length === 0 && hiddenNamespaces.size === 0) {
|
|
76
|
+
findings.push({
|
|
77
|
+
id: 'package-post-install-ok',
|
|
78
|
+
category: this.category,
|
|
79
|
+
riskLevel: 'LOW',
|
|
80
|
+
passed: true,
|
|
81
|
+
title: 'No post-install scripts found in installed packages',
|
|
82
|
+
detail: `${installedPackages.length} package(s) installed; none of their readable Apex implements InstallHandler.`,
|
|
83
|
+
remediation: 'Review post-install scripts and permissions whenever new packages are installed.',
|
|
84
|
+
});
|
|
85
|
+
}
|
|
86
|
+
return { findings };
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
//# sourceMappingURL=PackagePostInstallSupplyChainCheck.js.map
|