@cclabsnz/sf-audit 1.16.0 → 1.18.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 +172 -1
- package/PERMISSIONS.md +139 -0
- package/README.md +98 -26
- package/config/scoring.sample.json +104 -5
- package/docs/permissionset/SF_Audit_ReadOnly.permissionset-meta.xml +54 -0
- 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/ChainEngine.js +11 -1
- package/lib/chains/namedChains.js +130 -24
- package/lib/checks/CheckEngine.d.ts +3 -1
- package/lib/checks/CheckEngine.js +65 -26
- package/lib/checks/impl/AgentUserPrivilegeCheck.js +5 -4
- package/lib/checks/impl/AnonymousApexAuditCheck.js +41 -8
- package/lib/checks/impl/ApexCrudFLSCheck.js +45 -10
- package/lib/checks/impl/ApexSharingCheck.js +19 -26
- package/lib/checks/impl/ApiClientPermissionCheck.js +21 -5
- package/lib/checks/impl/AuditTrailCheck.js +23 -8
- package/lib/checks/impl/AuthProviderRegistrationHandlerCheck.d.ts +10 -0
- package/lib/checks/impl/AuthProviderRegistrationHandlerCheck.js +131 -0
- package/lib/checks/impl/CertificateExpiryCheck.js +2 -1
- package/lib/checks/impl/ConnectedAppScopeCheck.js +61 -5
- package/lib/checks/impl/ConnectedAppsCheck.js +60 -5
- package/lib/checks/impl/ContentLinksCheck.js +33 -9
- package/lib/checks/impl/CorsAllowlistCheck.js +3 -2
- package/lib/checks/impl/DataClassificationCheck.js +15 -13
- package/lib/checks/impl/DataCloudDataSpaceIsolationCheck.d.ts +10 -0
- package/lib/checks/impl/DataCloudDataSpaceIsolationCheck.js +116 -0
- package/lib/checks/impl/DebugLogAccessCheck.js +4 -4
- package/lib/checks/impl/DelegatedAdministrationGroupsCheck.d.ts +10 -0
- package/lib/checks/impl/DelegatedAdministrationGroupsCheck.js +76 -0
- package/lib/checks/impl/DelegatedAuthenticationExposureCheck.d.ts +10 -0
- package/lib/checks/impl/DelegatedAuthenticationExposureCheck.js +105 -0
- package/lib/checks/impl/DeploymentIdentityCheck.js +32 -5
- package/lib/checks/impl/EmailSecurityCheck.d.ts +1 -1
- package/lib/checks/impl/EmailSecurityCheck.js +14 -34
- package/lib/checks/impl/EncryptionCoverageCheck.js +21 -15
- package/lib/checks/impl/EnhancedDomainsCheck.js +17 -2
- package/lib/checks/impl/EscalationPermsCheck.d.ts +2 -0
- package/lib/checks/impl/EscalationPermsCheck.js +88 -21
- package/lib/checks/impl/ExperienceCloudSiteCheck.js +56 -5
- package/lib/checks/impl/ExternalAccountHierarchyExposureCheck.d.ts +10 -0
- package/lib/checks/impl/ExternalAccountHierarchyExposureCheck.js +65 -0
- package/lib/checks/impl/ExternalCredentialsCheck.js +6 -3
- package/lib/checks/impl/FailedLoginCheck.js +36 -9
- package/lib/checks/impl/FieldHistoryTrackingCheck.js +14 -11
- 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/GuestRecordAccessPolicyCheck.js +52 -11
- package/lib/checks/impl/HardcodedCredentialsCheck.js +7 -2
- package/lib/checks/impl/HealthCheckCheck.js +1 -0
- package/lib/checks/impl/HighAssuranceSessionCheck.js +16 -11
- package/lib/checks/impl/InactiveUsersCheck.js +1 -1
- package/lib/checks/impl/InboundEmailHandlerExposureCheck.d.ts +10 -0
- package/lib/checks/impl/InboundEmailHandlerExposureCheck.js +136 -0
- package/lib/checks/impl/IntegrationLeastPrivilegeCheck.js +7 -6
- package/lib/checks/impl/InternalUserMfaCheck.js +26 -8
- package/lib/checks/impl/IpRestrictionsCheck.js +35 -16
- package/lib/checks/impl/LoginAccessPolicyCheck.js +5 -4
- package/lib/checks/impl/LoginAnomalyCheck.js +10 -7
- package/lib/checks/impl/LoginSessionCheck.js +2 -0
- package/lib/checks/impl/MfaEnforcementCheck.js +23 -6
- package/lib/checks/impl/MfaMethodStrengthCheck.js +18 -3
- package/lib/checks/impl/MfaRegistrationCheck.js +4 -3
- package/lib/checks/impl/MyDomainLoginPolicyCheck.js +23 -10
- 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/OutboundMessagesCheck.js +48 -6
- 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 +88 -0
- package/lib/checks/impl/PrivilegedAccessCheck.js +12 -5
- package/lib/checks/impl/ReleaseUpdatesCheck.js +18 -3
- package/lib/checks/impl/RemoteSitesCheck.js +4 -4
- package/lib/checks/impl/RestrictionRulesIntegrityCheck.d.ts +10 -0
- package/lib/checks/impl/RestrictionRulesIntegrityCheck.js +105 -0
- package/lib/checks/impl/SeparationOfDutiesCheck.js +14 -3
- package/lib/checks/impl/ShieldTenantSecretLifecycleCheck.d.ts +10 -0
- package/lib/checks/impl/ShieldTenantSecretLifecycleCheck.js +90 -0
- package/lib/checks/impl/SoapLoginApiAuthCheck.js +20 -8
- package/lib/checks/impl/SsoEnforcementCheck.js +16 -5
- package/lib/checks/impl/TransactionSecurityPolicyCheck.js +5 -5
- package/lib/checks/impl/TrustedIPRangesCheck.js +18 -9
- package/lib/checks/impl/UsersAndAdminsCheck.js +24 -4
- package/lib/checks/permCatalog.js +1 -1
- 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 +37 -0
- package/lib/checks/support/schema.d.ts +17 -0
- package/lib/checks/support/schema.js +41 -0
- package/lib/commands/audit/apps.d.ts +1 -0
- package/lib/commands/audit/apps.js +86 -30
- package/lib/commands/audit/diff.js +2 -2
- package/lib/commands/audit/events/pull.js +3 -1
- package/lib/commands/audit/history.js +2 -2
- package/lib/commands/audit/incident/collect.js +3 -1
- package/lib/commands/audit/incident/report.js +2 -2
- package/lib/commands/audit/security.d.ts +3 -0
- package/lib/commands/audit/security.js +65 -10
- package/lib/commands/audit/timeline.js +2 -2
- package/lib/compliance/mapping.js +28 -7
- package/lib/findings/AuditResult.d.ts +10 -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 +34 -0
- package/lib/findings/coverage.js +42 -0
- package/lib/findings/exitCode.js +1 -1
- package/lib/findings/loadScoringConfig.js +51 -8
- package/lib/findings/scoring.js +61 -10
- 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/preflight/permissionMap.d.ts +2 -20
- package/lib/preflight/permissionMap.js +2 -43
- package/lib/preflight/permissions.d.ts +25 -0
- package/lib/preflight/permissions.js +50 -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 +23 -6
- package/lib/renderers/MarkdownRenderer.js +11 -1
- 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.d.ts +5 -1
- package/lib/report/RemediationRoadmap.js +6 -2
- 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 +6 -4
|
@@ -1,3 +1,17 @@
|
|
|
1
|
+
/** Minutes, or null when the app sets no timeout of its own. */
|
|
2
|
+
function timeoutMinutes(app) {
|
|
3
|
+
const n = app.SessionTimeout === null || app.SessionTimeout === '' ? NaN : Number(app.SessionTimeout);
|
|
4
|
+
return Number.isFinite(n) && n > 0 ? n : null;
|
|
5
|
+
}
|
|
6
|
+
/**
|
|
7
|
+
* External Client Apps are absent from orgs that predate them, where the query answers with
|
|
8
|
+
* INVALID_TYPE. That, and only that, means "none"; any other failure is reported as inconclusive.
|
|
9
|
+
*/
|
|
10
|
+
function isExternalClientAppUnsupported(err) {
|
|
11
|
+
const code = err?.errorCode ?? '';
|
|
12
|
+
const msg = err instanceof Error ? err.message : String(err);
|
|
13
|
+
return code === 'INVALID_TYPE' || /sObject type 'ExternalClientApplication' is not supported/i.test(msg);
|
|
14
|
+
}
|
|
1
15
|
export class ConnectedAppsCheck {
|
|
2
16
|
id = 'connected-apps';
|
|
3
17
|
name = 'Connected Apps';
|
|
@@ -8,10 +22,34 @@ export class ConnectedAppsCheck {
|
|
|
8
22
|
const findings = [];
|
|
9
23
|
const baseUrl = ctx.orgInfo.instanceUrl;
|
|
10
24
|
// Single query fetches both access-control and session-timeout fields — no N+1 calls needed.
|
|
11
|
-
|
|
25
|
+
// SessionTimeout is served only by the Tooling API; the standard API rejects the column.
|
|
26
|
+
const connectedApps = await ctx.tooling.query(`SELECT Id, Name, OptionsAllowAdminApprovedUsersOnly, SessionTimeout
|
|
12
27
|
FROM ConnectedApplication`);
|
|
13
28
|
const count = connectedApps.length;
|
|
14
|
-
//
|
|
29
|
+
// External Client Apps are the successor to connected apps. Their policies (permitted users,
|
|
30
|
+
// session timeout) are not exposed on the objects this check can read reliably, so they are
|
|
31
|
+
// inventoried and listed for manual review rather than judged on guessed fields.
|
|
32
|
+
let externalApps = [];
|
|
33
|
+
try {
|
|
34
|
+
externalApps = await ctx.soql.queryAll('SELECT Id, DeveloperName, MasterLabel FROM ExternalClientApplication');
|
|
35
|
+
}
|
|
36
|
+
catch (err) {
|
|
37
|
+
if (!isExternalClientAppUnsupported(err)) {
|
|
38
|
+
findings.push({
|
|
39
|
+
id: 'external-client-apps-inconclusive',
|
|
40
|
+
category: this.category,
|
|
41
|
+
riskLevel: 'INFO',
|
|
42
|
+
inconclusive: true,
|
|
43
|
+
title: 'External Client Apps could not be listed',
|
|
44
|
+
detail: `The connected-app results below stand, but External Client Apps were not checked: ${err instanceof Error ? err.message : String(err)}`,
|
|
45
|
+
remediation: 'Grant the audit user View Setup and Configuration, then re-run. Meanwhile review Setup → External Client App Manager manually.',
|
|
46
|
+
});
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
// Cache app names for DeploymentIdentityCheck and SiemIntegrationCheck — no extra query.
|
|
50
|
+
// Connected apps only: ConnectedAppInactivityCheck matches these names against LoginHistory,
|
|
51
|
+
// and how External Client App logins are labelled there is unverified, so adding them could
|
|
52
|
+
// report every External Client App as inactive.
|
|
15
53
|
ctx.cache.connectedAppNames = connectedApps.map((a) => a.Name);
|
|
16
54
|
// Check for apps with unrestricted user access
|
|
17
55
|
const unrestrictedApps = connectedApps.filter((app) => !app.OptionsAllowAdminApprovedUsersOnly);
|
|
@@ -44,7 +82,10 @@ export class ConnectedAppsCheck {
|
|
|
44
82
|
// SBS-DEP-006: access token (session) timeout must be ≤ 15 minutes for CLI/integration apps.
|
|
45
83
|
// SessionTimeout = 0 means the app inherits the org-level session timeout (often 2–8 hours),
|
|
46
84
|
// which exceeds the 15-minute SBS requirement. Flag null/0 and values > 15 minutes.
|
|
47
|
-
const longSessionApps = connectedApps.filter((app) =>
|
|
85
|
+
const longSessionApps = connectedApps.filter((app) => {
|
|
86
|
+
const minutes = timeoutMinutes(app);
|
|
87
|
+
return minutes === null || minutes > 15;
|
|
88
|
+
});
|
|
48
89
|
if (longSessionApps.length > 0) {
|
|
49
90
|
findings.push({
|
|
50
91
|
id: 'connected-apps-long-session-timeout',
|
|
@@ -56,9 +97,9 @@ export class ConnectedAppsCheck {
|
|
|
56
97
|
affectedItems: longSessionApps.map((app) => ({
|
|
57
98
|
label: app.Name,
|
|
58
99
|
url: `${baseUrl}/${app.Id}`,
|
|
59
|
-
note: app
|
|
100
|
+
note: timeoutMinutes(app) === null
|
|
60
101
|
? 'No explicit timeout: inherits org default (likely > 15 min)'
|
|
61
|
-
: `Session timeout: ${app
|
|
102
|
+
: `Session timeout: ${timeoutMinutes(app)} min, reduce to ≤ 15`,
|
|
62
103
|
})),
|
|
63
104
|
});
|
|
64
105
|
}
|
|
@@ -73,6 +114,20 @@ export class ConnectedAppsCheck {
|
|
|
73
114
|
remediation: 'Continue monitoring as new connected apps are added.',
|
|
74
115
|
});
|
|
75
116
|
}
|
|
117
|
+
if (externalApps.length > 0) {
|
|
118
|
+
findings.push({
|
|
119
|
+
id: 'external-client-apps-review',
|
|
120
|
+
category: this.category,
|
|
121
|
+
riskLevel: 'INFO',
|
|
122
|
+
title: `${externalApps.length} External Client App(s) need their OAuth policies reviewed manually`,
|
|
123
|
+
detail: 'External Client Apps carry the same risks as connected apps: who may authorise them, and how long their sessions and refresh tokens last. This audit lists them but does not evaluate their policies, so the connected-app results above do not cover them.',
|
|
124
|
+
remediation: 'In Setup → External Client App Manager, open each app\'s OAuth policies: set Permitted Users to admin-approved users, an access-token timeout of 15 minutes or less for CLI and CI/CD apps, and a bounded refresh-token validity.',
|
|
125
|
+
affectedItems: externalApps.map((app) => ({
|
|
126
|
+
label: app.MasterLabel || app.DeveloperName,
|
|
127
|
+
url: `${baseUrl}/${app.Id}`,
|
|
128
|
+
})),
|
|
129
|
+
});
|
|
130
|
+
}
|
|
76
131
|
return {
|
|
77
132
|
findings,
|
|
78
133
|
metrics: {
|
|
@@ -1,3 +1,7 @@
|
|
|
1
|
+
/** Live links read per run. A full page means more exist, so the result is partial. */
|
|
2
|
+
const LINK_LIMIT = 500;
|
|
3
|
+
/** A link expires only when PreferencesExpires is set; ExpiryDate alone is not enforced. */
|
|
4
|
+
const expires = (r) => r.PreferencesExpires && Boolean(r.ExpiryDate);
|
|
1
5
|
// Links older than this with no expiry date are considered stale (SBS-FILE-003)
|
|
2
6
|
const STALE_DAYS = 90;
|
|
3
7
|
export class ContentLinksCheck {
|
|
@@ -11,25 +15,45 @@ export class ContentLinksCheck {
|
|
|
11
15
|
// Single query — fetches all data needed for FILE-001 (no expiry),
|
|
12
16
|
// FILE-002 (no password), and FILE-003 (stale links).
|
|
13
17
|
let records;
|
|
18
|
+
let truncated = false;
|
|
14
19
|
try {
|
|
15
|
-
|
|
20
|
+
// Every ContentDistribution is a public link (there is no IsPublic field). Links already past
|
|
21
|
+
// their expiry no longer serve the file, so they are excluded in the query, before the LIMIT:
|
|
22
|
+
// filtering after it could fill the page with dead links and hide live ones.
|
|
23
|
+
const now = Date.now();
|
|
24
|
+
const nowLiteral = new Date(now).toISOString().replace(/\.\d{3}Z$/, 'Z');
|
|
25
|
+
const all = await ctx.soql.queryAll(`SELECT Id, Name, ContentDocumentId, ExpiryDate, PreferencesExpires, PreferencesPasswordRequired, CreatedDate
|
|
16
26
|
FROM ContentDistribution
|
|
17
|
-
WHERE
|
|
27
|
+
WHERE (PreferencesExpires = false OR ExpiryDate = null OR ExpiryDate > ${nowLiteral})
|
|
18
28
|
ORDER BY CreatedDate ASC
|
|
19
|
-
LIMIT
|
|
29
|
+
LIMIT ${LINK_LIMIT}`);
|
|
30
|
+
truncated = all.length >= LINK_LIMIT;
|
|
31
|
+
records = all.filter((r) => !(expires(r) && new Date(r.ExpiryDate).getTime() < now));
|
|
20
32
|
}
|
|
21
|
-
catch {
|
|
33
|
+
catch (err) {
|
|
22
34
|
findings.push({
|
|
23
35
|
id: 'content-links-inaccessible',
|
|
24
36
|
category: this.category,
|
|
25
37
|
riskLevel: 'INFO',
|
|
26
38
|
inconclusive: true,
|
|
27
39
|
title: 'Content distribution links could not be queried',
|
|
28
|
-
detail:
|
|
40
|
+
detail: `SBS-FILE-001/002/003 require review of public content distribution links. The ContentDistribution query failed: ${err instanceof Error ? err.message : String(err)}`,
|
|
29
41
|
remediation: 'Grant the audit user read access to ContentDistribution records to enable this check.',
|
|
30
42
|
});
|
|
31
43
|
return { findings };
|
|
32
44
|
}
|
|
45
|
+
if (truncated) {
|
|
46
|
+
// MN-051: links past the page were not read, so a clean result here proves nothing about them.
|
|
47
|
+
findings.push({
|
|
48
|
+
id: 'content-links-partial',
|
|
49
|
+
category: this.category,
|
|
50
|
+
riskLevel: 'INFO',
|
|
51
|
+
inconclusive: true,
|
|
52
|
+
title: `Only the oldest ${LINK_LIMIT} live public content links were reviewed`,
|
|
53
|
+
detail: `The org has more than ${LINK_LIMIT} live public content distribution links. Findings below cover the oldest ${LINK_LIMIT}; newer links were not reviewed, so their absence from a finding is not a pass.`,
|
|
54
|
+
remediation: 'Review public links in Setup or with a report on Content Deliveries, and expire or delete the ones no longer needed.',
|
|
55
|
+
});
|
|
56
|
+
}
|
|
33
57
|
if (records.length === 0) {
|
|
34
58
|
findings.push({
|
|
35
59
|
id: 'content-links-none',
|
|
@@ -43,9 +67,9 @@ export class ContentLinksCheck {
|
|
|
43
67
|
return { findings };
|
|
44
68
|
}
|
|
45
69
|
const staleThreshold = new Date(Date.now() - STALE_DAYS * 86_400_000);
|
|
46
|
-
const noExpiry = records.filter((r) => !r
|
|
47
|
-
const noPassword = records.filter((r) => !r.
|
|
48
|
-
const stale = records.filter((r) => !r
|
|
70
|
+
const noExpiry = records.filter((r) => !expires(r));
|
|
71
|
+
const noPassword = records.filter((r) => !r.PreferencesPasswordRequired);
|
|
72
|
+
const stale = records.filter((r) => !expires(r) && new Date(r.CreatedDate) < staleThreshold);
|
|
49
73
|
let hasPositiveFinding = false;
|
|
50
74
|
// SBS-FILE-001: all public content links must have an expiry date
|
|
51
75
|
if (noExpiry.length > 0) {
|
|
@@ -98,7 +122,7 @@ export class ContentLinksCheck {
|
|
|
98
122
|
})),
|
|
99
123
|
});
|
|
100
124
|
}
|
|
101
|
-
if (!hasPositiveFinding) {
|
|
125
|
+
if (!hasPositiveFinding && !truncated) {
|
|
102
126
|
findings.push({
|
|
103
127
|
id: 'content-links-ok',
|
|
104
128
|
category: this.category,
|
|
@@ -8,7 +8,8 @@ export class CorsAllowlistCheck {
|
|
|
8
8
|
const setupUrl = `${ctx.orgInfo.instanceUrl}/lightning/setup/CorsWhitelistEntries/home`;
|
|
9
9
|
let rows;
|
|
10
10
|
try {
|
|
11
|
-
|
|
11
|
+
// CorsWhitelistEntry is served by the standard API; the Tooling API does not support it.
|
|
12
|
+
rows = await ctx.soql.queryAll('SELECT Id, UrlPattern FROM CorsWhitelistEntry');
|
|
12
13
|
}
|
|
13
14
|
catch (err) {
|
|
14
15
|
const msg = err instanceof Error ? err.message : String(err);
|
|
@@ -18,7 +19,7 @@ export class CorsAllowlistCheck {
|
|
|
18
19
|
riskLevel: 'INFO',
|
|
19
20
|
inconclusive: true,
|
|
20
21
|
title: 'CORS allowlist could not be read',
|
|
21
|
-
detail: `The CorsWhitelistEntry
|
|
22
|
+
detail: `The CorsWhitelistEntry query failed: ${msg}`,
|
|
22
23
|
remediation: 'Grant the audit user "View Setup and Configuration", then re-run the audit.',
|
|
23
24
|
});
|
|
24
25
|
return { findings };
|
|
@@ -11,23 +11,25 @@ export class DataClassificationCheck {
|
|
|
11
11
|
const findings = [];
|
|
12
12
|
const baseUrl = ctx.orgInfo.instanceUrl;
|
|
13
13
|
const objectList = CLASSIFICATION_OBJECTS.map((o) => `'${o}'`).join(', ');
|
|
14
|
-
// Q1 (Tooling API):
|
|
14
|
+
// Q1 (Tooling API): fields with a ComplianceGroup set on each key object, counted here.
|
|
15
15
|
// Salesforce Data Classification sets ComplianceGroup on FieldDefinition to mark fields
|
|
16
16
|
// as PII, PCI, HIPAA, GDPR, etc. Objects with zero classified fields are uncovered.
|
|
17
|
-
|
|
18
|
-
|
|
17
|
+
// FieldDefinition supports no aggregates (its Id is not aggregatable), so no COUNT/GROUP BY.
|
|
18
|
+
const classifiedMap = new Map();
|
|
19
|
+
let classificationError;
|
|
19
20
|
try {
|
|
20
|
-
const classResult = await ctx.tooling.query(`SELECT EntityDefinition.QualifiedApiName
|
|
21
|
+
const classResult = await ctx.tooling.query(`SELECT EntityDefinition.QualifiedApiName, QualifiedApiName
|
|
21
22
|
FROM FieldDefinition
|
|
22
23
|
WHERE EntityDefinition.QualifiedApiName IN (${objectList})
|
|
23
|
-
AND ComplianceGroup != null
|
|
24
|
-
GROUP BY EntityDefinition.QualifiedApiName`);
|
|
24
|
+
AND ComplianceGroup != null`);
|
|
25
25
|
for (const r of classResult) {
|
|
26
|
-
|
|
26
|
+
const obj = r.EntityDefinition?.QualifiedApiName;
|
|
27
|
+
if (obj)
|
|
28
|
+
classifiedMap.set(obj, (classifiedMap.get(obj) ?? 0) + 1);
|
|
27
29
|
}
|
|
28
30
|
}
|
|
29
|
-
catch {
|
|
30
|
-
|
|
31
|
+
catch (err) {
|
|
32
|
+
classificationError = err instanceof Error ? err.message : String(err);
|
|
31
33
|
}
|
|
32
34
|
// Q2 (SOQL): check for Shield Platform Encryption keys.
|
|
33
35
|
// EncryptionKey records indicate Shield is licensed and active.
|
|
@@ -45,15 +47,15 @@ export class DataClassificationCheck {
|
|
|
45
47
|
encryptionQueryFailed = true;
|
|
46
48
|
}
|
|
47
49
|
// SBS-DATA-001/002: data classification coverage
|
|
48
|
-
if (
|
|
50
|
+
if (classificationError !== undefined) {
|
|
49
51
|
findings.push({
|
|
50
52
|
id: 'data-classification-inconclusive',
|
|
51
53
|
category: this.category,
|
|
52
54
|
riskLevel: 'INFO',
|
|
53
55
|
inconclusive: true,
|
|
54
|
-
title: 'Data classification status could not be determined
|
|
55
|
-
detail:
|
|
56
|
-
remediation: '
|
|
56
|
+
title: 'Data classification status could not be determined',
|
|
57
|
+
detail: `SBS-DATA-001 requires all data fields to be classified by sensitivity. SBS-DATA-002 requires PII fields to be explicitly identified. The Tooling API FieldDefinition query failed, so classification is unassessed, not absent: ${classificationError}`,
|
|
58
|
+
remediation: 'Check the error above. If it is an access error, confirm the audit user has API Enabled and View Setup and Configuration; otherwise review data classification manually in Setup → Data Management → Data Classification for Account, Contact, Lead, Opportunity, Case, Contract, and User.',
|
|
57
59
|
});
|
|
58
60
|
}
|
|
59
61
|
else {
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import type { AuditContext } from '@cclabsnz/sf-core';
|
|
2
|
+
import type { SecurityCheck, CheckResult } from '../SecurityCheck.js';
|
|
3
|
+
export declare class DataCloudDataSpaceIsolationCheck implements SecurityCheck {
|
|
4
|
+
readonly id = "data-cloud-data-space-isolation";
|
|
5
|
+
readonly name = "Data Cloud Data Space Isolation";
|
|
6
|
+
readonly category = "Data Security";
|
|
7
|
+
readonly description = "Flags orgs where external integrations, partner users, or agent users are mapped to the default Data Space, or unconstrained Data Share Targets exist.";
|
|
8
|
+
run(ctx: AuditContext): Promise<CheckResult>;
|
|
9
|
+
}
|
|
10
|
+
//# sourceMappingURL=DataCloudDataSpaceIsolationCheck.d.ts.map
|
|
@@ -0,0 +1,116 @@
|
|
|
1
|
+
import { isMissingObjectError, queryIfPresent } from '../support/missingObject.js';
|
|
2
|
+
const EXTERNAL_USER_TYPES = new Set(['PowerPartner', 'CustomerSuccess', 'PowerCustomerSuccess', 'CspLitePortal', 'Guest']);
|
|
3
|
+
function isDataCloudPermSet(ps) {
|
|
4
|
+
return /datacloud|dataspace|cdp/i.test(`${ps?.Name ?? ''} ${ps?.Label ?? ''}`);
|
|
5
|
+
}
|
|
6
|
+
export class DataCloudDataSpaceIsolationCheck {
|
|
7
|
+
id = 'data-cloud-data-space-isolation';
|
|
8
|
+
name = 'Data Cloud Data Space Isolation';
|
|
9
|
+
category = 'Data Security';
|
|
10
|
+
description = 'Flags orgs where external integrations, partner users, or agent users are mapped to the default Data Space, or unconstrained Data Share Targets exist.';
|
|
11
|
+
async run(ctx) {
|
|
12
|
+
const findings = [];
|
|
13
|
+
const baseUrl = ctx.orgInfo.instanceUrl;
|
|
14
|
+
let dataSpaces;
|
|
15
|
+
try {
|
|
16
|
+
dataSpaces = await ctx.soql.queryAll('SELECT Id, Name, Description FROM DataSpace');
|
|
17
|
+
}
|
|
18
|
+
catch (err) {
|
|
19
|
+
if (isMissingObjectError(err)) {
|
|
20
|
+
findings.push({
|
|
21
|
+
id: 'data-cloud-data-space-not-enabled',
|
|
22
|
+
category: this.category,
|
|
23
|
+
riskLevel: 'LOW',
|
|
24
|
+
passed: true,
|
|
25
|
+
title: 'Data Cloud is not enabled or DataSpace is not configured in this org',
|
|
26
|
+
detail: 'DataSpace object is not available; Data Cloud is not enabled or licensed in this org.',
|
|
27
|
+
remediation: 'No action required if Data Cloud is not deployed.',
|
|
28
|
+
});
|
|
29
|
+
return { findings };
|
|
30
|
+
}
|
|
31
|
+
findings.push({
|
|
32
|
+
id: 'data-cloud-data-space-inaccessible',
|
|
33
|
+
category: this.category,
|
|
34
|
+
riskLevel: 'INFO',
|
|
35
|
+
inconclusive: true,
|
|
36
|
+
title: 'Data Cloud Data Spaces could not be read',
|
|
37
|
+
detail: `Query to DataSpace failed: ${err instanceof Error ? err.message : String(err)}`,
|
|
38
|
+
remediation: 'Ensure the audit user has permission to view Data Cloud Data Spaces and configuration.',
|
|
39
|
+
});
|
|
40
|
+
return { findings };
|
|
41
|
+
}
|
|
42
|
+
if (dataSpaces.length === 0) {
|
|
43
|
+
findings.push({
|
|
44
|
+
id: 'data-cloud-data-space-ok',
|
|
45
|
+
category: this.category,
|
|
46
|
+
riskLevel: 'LOW',
|
|
47
|
+
passed: true,
|
|
48
|
+
title: 'No Data Cloud Data Spaces found',
|
|
49
|
+
detail: 'Zero DataSpace records exist in this org.',
|
|
50
|
+
remediation: 'Define segmented Data Spaces if Data Cloud is activated in the future.',
|
|
51
|
+
});
|
|
52
|
+
return { findings };
|
|
53
|
+
}
|
|
54
|
+
// Data Cloud names its default data space "default". Only Name is selected, so only Name is read.
|
|
55
|
+
const defaultDataSpace = dataSpaces.find((ds) => (ds.Name ?? '').toLowerCase() === 'default');
|
|
56
|
+
// External, guest or agent users holding a Data Cloud permission set they were assigned
|
|
57
|
+
// directly. A profile's own permission set, or an unrelated one, grants no data space access.
|
|
58
|
+
const assignments = await ctx.soql.queryAll("SELECT Id, AssigneeId, Assignee.Username, Assignee.UserType, Assignee.Profile.Name, PermissionSet.Name, PermissionSet.Label FROM PermissionSetAssignment WHERE Assignee.IsActive = true AND PermissionSet.IsOwnedByProfile = false AND (PermissionSet.Name LIKE '%DataCloud%' OR PermissionSet.Name LIKE '%DataSpace%' OR PermissionSet.Name LIKE '%CDP%')");
|
|
59
|
+
const byUser = new Map();
|
|
60
|
+
for (const a of assignments) {
|
|
61
|
+
const uType = a.Assignee?.UserType ?? '';
|
|
62
|
+
const uname = (a.Assignee?.Username ?? '').toLowerCase();
|
|
63
|
+
const lowTrust = EXTERNAL_USER_TYPES.has(uType) || uname.includes('agent');
|
|
64
|
+
if (lowTrust && isDataCloudPermSet(a.PermissionSet) && !byUser.has(a.AssigneeId))
|
|
65
|
+
byUser.set(a.AssigneeId, a);
|
|
66
|
+
}
|
|
67
|
+
const oversharedUsers = [...byUser.values()];
|
|
68
|
+
if (defaultDataSpace && oversharedUsers.length > 0) {
|
|
69
|
+
findings.push({
|
|
70
|
+
id: 'data-cloud-data-space-default-overshared',
|
|
71
|
+
category: this.category,
|
|
72
|
+
riskLevel: 'HIGH',
|
|
73
|
+
title: `${oversharedUsers.length} external, partner, or agent user(s) hold Data Cloud access while the default Data Space is in use`,
|
|
74
|
+
detail: 'Data Cloud default Data Space flattens standard Salesforce OWD record-level sharing. Exposing the default Data Space to external partner, integration, or agent accounts grants bulk visibility across data lake objects (DLOs) and data model objects (DMOs).',
|
|
75
|
+
remediation: 'Segment data by creating dedicated Data Spaces with restricted permissions, and map partner and agent users only to their respective segmented spaces.',
|
|
76
|
+
affectedItems: oversharedUsers.map((u) => ({
|
|
77
|
+
label: u.Assignee?.Username ?? u.AssigneeId,
|
|
78
|
+
url: `${baseUrl}/lightning/setup/DataCloudDataSpace/home`,
|
|
79
|
+
note: `UserType: ${u.Assignee?.UserType ?? 'Unknown'}; permission set ${u.PermissionSet?.Label ?? u.PermissionSet?.Name ?? 'unknown'}`,
|
|
80
|
+
})),
|
|
81
|
+
});
|
|
82
|
+
}
|
|
83
|
+
// Query DataShareTarget for unconstrained external data sharing
|
|
84
|
+
const shareTargets = await queryIfPresent(() => ctx.soql.queryAll('SELECT Id, Name, TargetType, Status FROM DataShareTarget'));
|
|
85
|
+
const unconstrainedTargets = shareTargets.filter((t) => (t.Status ?? '').toLowerCase() === 'active');
|
|
86
|
+
if (unconstrainedTargets.length > 0) {
|
|
87
|
+
findings.push({
|
|
88
|
+
id: 'data-cloud-data-share-target-unconstrained',
|
|
89
|
+
category: this.category,
|
|
90
|
+
riskLevel: 'HIGH',
|
|
91
|
+
title: `${unconstrainedTargets.length} active Data Cloud Data Share Target(s) without IP or authentication constraints`,
|
|
92
|
+
detail: 'External Data Share Targets allow zero-copy outbound sharing to external platforms (Snowflake, AWS S3, BigQuery). Active targets without strict constraints expose bulk customer data outside Salesforce boundaries.',
|
|
93
|
+
remediation: 'Audit all active Data Share Targets, apply IP restrictions, and verify authentication and encryption configurations.',
|
|
94
|
+
affectedItems: unconstrainedTargets.map((t) => ({
|
|
95
|
+
label: t.Name ?? t.Id,
|
|
96
|
+
url: `${baseUrl}/lightning/setup/DataShare/home`,
|
|
97
|
+
note: `TargetType: ${t.TargetType ?? 'Unknown'}, Status: ${t.Status ?? 'Unknown'}`,
|
|
98
|
+
})),
|
|
99
|
+
});
|
|
100
|
+
}
|
|
101
|
+
if ((!defaultDataSpace || oversharedUsers.length === 0) &&
|
|
102
|
+
unconstrainedTargets.length === 0) {
|
|
103
|
+
findings.push({
|
|
104
|
+
id: 'data-cloud-data-space-ok',
|
|
105
|
+
category: this.category,
|
|
106
|
+
riskLevel: 'LOW',
|
|
107
|
+
passed: true,
|
|
108
|
+
title: 'Data Cloud Data Spaces and Data Share Targets are properly segmented and isolated',
|
|
109
|
+
detail: `${dataSpaces.length} Data Space(s) inspected; no over-sharing to low-trust identities or unconstrained share targets detected.`,
|
|
110
|
+
remediation: 'Continue enforcing segmented Data Spaces for any new integration or external user.',
|
|
111
|
+
});
|
|
112
|
+
}
|
|
113
|
+
return { findings };
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
//# sourceMappingURL=DataCloudDataSpaceIsolationCheck.js.map
|
|
@@ -10,22 +10,22 @@ export class DebugLogAccessCheck {
|
|
|
10
10
|
const setupUrl = `${baseUrl}/lightning/setup/ApexDebugLog/home`;
|
|
11
11
|
let traces = [];
|
|
12
12
|
try {
|
|
13
|
-
|
|
13
|
+
// TraceFlag is served by the Tooling API only.
|
|
14
|
+
traces = await ctx.tooling.query(`SELECT Id, TracedEntityId, LogType, ExpirationDate,
|
|
14
15
|
DebugLevel.DeveloperName, DebugLevel.ApexCode
|
|
15
16
|
FROM TraceFlag
|
|
16
17
|
WHERE ExpirationDate >= TODAY
|
|
17
18
|
ORDER BY ExpirationDate ASC
|
|
18
19
|
LIMIT 200`);
|
|
19
|
-
traces = result.records;
|
|
20
20
|
}
|
|
21
|
-
catch {
|
|
21
|
+
catch (err) {
|
|
22
22
|
findings.push({
|
|
23
23
|
id: 'debug-log-inaccessible',
|
|
24
24
|
category: this.category,
|
|
25
25
|
riskLevel: 'INFO',
|
|
26
26
|
inconclusive: true,
|
|
27
27
|
title: 'TraceFlag records could not be retrieved: active debug traces cannot be verified',
|
|
28
|
-
detail:
|
|
28
|
+
detail: `The TraceFlag query failed: ${err instanceof Error ? err.message : String(err)}. If the org denied access, the audit user may lack "View Setup and Configuration".`,
|
|
29
29
|
remediation: 'Grant "Manage Users" or "View All Data" permission to the audit user, or review active debug traces manually in Setup → Debug Logs.',
|
|
30
30
|
affectedItems: [{ label: 'Debug Log Setup', url: setupUrl }],
|
|
31
31
|
});
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import type { AuditContext } from '@cclabsnz/sf-core';
|
|
2
|
+
import type { SecurityCheck, CheckResult } from '../SecurityCheck.js';
|
|
3
|
+
export declare class DelegatedAdministrationGroupsCheck implements SecurityCheck {
|
|
4
|
+
readonly id = "delegated-administration-groups";
|
|
5
|
+
readonly name = "Delegated Administration Groups";
|
|
6
|
+
readonly category = "Privileged Access";
|
|
7
|
+
readonly description = "Identifies unmonitored Delegated Admin Groups that grant shadow-admin privileges outside profiles and permission sets.";
|
|
8
|
+
run(ctx: AuditContext): Promise<CheckResult>;
|
|
9
|
+
}
|
|
10
|
+
//# sourceMappingURL=DelegatedAdministrationGroupsCheck.d.ts.map
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
export class DelegatedAdministrationGroupsCheck {
|
|
2
|
+
id = 'delegated-administration-groups';
|
|
3
|
+
name = 'Delegated Administration Groups';
|
|
4
|
+
category = 'Privileged Access';
|
|
5
|
+
description = 'Identifies unmonitored Delegated Admin Groups that grant shadow-admin privileges outside profiles and permission sets.';
|
|
6
|
+
async run(ctx) {
|
|
7
|
+
const findings = [];
|
|
8
|
+
const baseUrl = ctx.orgInfo.instanceUrl;
|
|
9
|
+
const setupUrl = `${baseUrl}/lightning/setup/DelegateGroups/home`;
|
|
10
|
+
let groups = [];
|
|
11
|
+
try {
|
|
12
|
+
// DelegateGroup and DelegateGroupMember are served by the Tooling API only.
|
|
13
|
+
groups = await ctx.tooling.query('SELECT Id, DeveloperName FROM DelegateGroup');
|
|
14
|
+
}
|
|
15
|
+
catch (err) {
|
|
16
|
+
// This object exists in every org, so a failure is lack of access, never an absent feature.
|
|
17
|
+
findings.push({
|
|
18
|
+
id: 'delegated-administration-groups-inaccessible',
|
|
19
|
+
category: this.category,
|
|
20
|
+
riskLevel: 'INFO',
|
|
21
|
+
inconclusive: true,
|
|
22
|
+
title: 'Delegated Administration Groups could not be queried',
|
|
23
|
+
detail: `Failed to query DelegateGroup: ${err instanceof Error ? err.message : String(err)}`,
|
|
24
|
+
remediation: 'Grant the audit user "View Setup and Configuration" to inspect delegated admin groups.',
|
|
25
|
+
});
|
|
26
|
+
return { findings };
|
|
27
|
+
}
|
|
28
|
+
if (groups.length === 0) {
|
|
29
|
+
findings.push({
|
|
30
|
+
id: 'delegated-administration-groups-ok',
|
|
31
|
+
category: this.category,
|
|
32
|
+
riskLevel: 'LOW',
|
|
33
|
+
passed: true,
|
|
34
|
+
title: 'No Delegated Administration Groups found',
|
|
35
|
+
detail: 'Zero DelegateGroup records are configured in this org.',
|
|
36
|
+
remediation: 'Continue avoiding unmonitored delegated administration groups.',
|
|
37
|
+
});
|
|
38
|
+
return { findings };
|
|
39
|
+
}
|
|
40
|
+
// Query members of delegated admin groups
|
|
41
|
+
let members = [];
|
|
42
|
+
members = await ctx.tooling.query('SELECT Id, DelegateGroupId, UserOrGroupId FROM DelegateGroupMember');
|
|
43
|
+
// Collect user names if members exist
|
|
44
|
+
const userIds = members
|
|
45
|
+
.map((m) => m.UserOrGroupId)
|
|
46
|
+
.filter((id) => Boolean(id && id.startsWith('005')));
|
|
47
|
+
let userMap = new Map();
|
|
48
|
+
if (userIds.length > 0) {
|
|
49
|
+
const users = await ctx.soql.queryAll(`SELECT Id, Username, Profile.Name FROM User WHERE Id IN ('${userIds.join("','")}')`);
|
|
50
|
+
for (const u of users) {
|
|
51
|
+
userMap.set(u.Id, `${u.Username} (${u.Profile?.Name ?? 'Unknown Profile'})`);
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
findings.push({
|
|
55
|
+
id: 'delegated-administration-groups-active',
|
|
56
|
+
category: this.category,
|
|
57
|
+
riskLevel: 'HIGH',
|
|
58
|
+
title: `${groups.length} Delegated Administration Group(s) grant unmonitored shadow-admin privileges`,
|
|
59
|
+
detail: 'Delegated Administration groups operate completely outside Profiles, Permission Sets, and Permission Set Groups. A user with a standard read-only profile assigned to a DelegateGroup can create users, reset passwords, unlock accounts, assign permission sets, and log in as users in their subordinate role hierarchy—effectively serving as an invisible Shadow Admin that standard privilege audits miss.',
|
|
60
|
+
remediation: 'Review all members and assigned grants in Setup → Delegated Administration. Ensure all delegated administrators are known, assignable permission sets are tightly scoped, and remove obsolete groups.',
|
|
61
|
+
affectedItems: groups.map((g) => {
|
|
62
|
+
const groupMembers = members.filter((m) => m.DelegateGroupId === g.Id);
|
|
63
|
+
const memberDesc = groupMembers
|
|
64
|
+
.map((m) => userMap.get(m.UserOrGroupId) ?? m.UserOrGroupId)
|
|
65
|
+
.join(', ');
|
|
66
|
+
return {
|
|
67
|
+
label: g.DeveloperName || g.Name || g.Id,
|
|
68
|
+
url: setupUrl,
|
|
69
|
+
note: memberDesc ? `Members: ${memberDesc}` : 'Active delegated administration group',
|
|
70
|
+
};
|
|
71
|
+
}),
|
|
72
|
+
});
|
|
73
|
+
return { findings };
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
//# sourceMappingURL=DelegatedAdministrationGroupsCheck.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 DelegatedAuthenticationExposureCheck implements SecurityCheck {
|
|
4
|
+
readonly id = "delegated-authentication-exposure";
|
|
5
|
+
readonly name = "Delegated Authentication Exposure";
|
|
6
|
+
readonly category = "Identity & Access";
|
|
7
|
+
readonly description = "Flags Delegated Authentication enabled over non-mTLS endpoints or assigned to System Administrator profiles.";
|
|
8
|
+
run(ctx: AuditContext): Promise<CheckResult>;
|
|
9
|
+
}
|
|
10
|
+
//# sourceMappingURL=DelegatedAuthenticationExposureCheck.d.ts.map
|
|
@@ -0,0 +1,105 @@
|
|
|
1
|
+
import { hasField } from '../support/schema.js';
|
|
2
|
+
// "Is Single Sign-On Enabled". Salesforce adds this permission field only to orgs where it has
|
|
3
|
+
// enabled delegated authentication; without the field no profile can route sign-in through a
|
|
4
|
+
// delegated gateway.
|
|
5
|
+
const SSO_PERMISSION = 'PermissionsIsSsoEnabled';
|
|
6
|
+
export class DelegatedAuthenticationExposureCheck {
|
|
7
|
+
id = 'delegated-authentication-exposure';
|
|
8
|
+
name = 'Delegated Authentication Exposure';
|
|
9
|
+
category = 'Identity & Access';
|
|
10
|
+
description = 'Flags Delegated Authentication enabled over non-mTLS endpoints or assigned to System Administrator profiles.';
|
|
11
|
+
async run(ctx) {
|
|
12
|
+
const findings = [];
|
|
13
|
+
const baseUrl = ctx.orgInfo.instanceUrl;
|
|
14
|
+
const ssoUrl = `${baseUrl}/lightning/setup/SingleSignOn/home`;
|
|
15
|
+
// Enabled, disabled, or unknown. Only a boolean actually returned by the settings read
|
|
16
|
+
// decides; a failed read or an absent Metadata client leaves it unknown, never "disabled".
|
|
17
|
+
let delegatedAuth;
|
|
18
|
+
let gatewayUrl = '';
|
|
19
|
+
if (ctx.metadata) {
|
|
20
|
+
try {
|
|
21
|
+
const sec = await ctx.metadata.read('SecuritySettings', 'Security');
|
|
22
|
+
const sso = sec?.singleSignOnSettings;
|
|
23
|
+
if (typeof sso?.isDelegatedAuthEnabled === 'boolean') {
|
|
24
|
+
delegatedAuth = sso.isDelegatedAuthEnabled;
|
|
25
|
+
gatewayUrl = sso.delegatedGatewayUrl ?? '';
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
catch {
|
|
29
|
+
delegatedAuth = undefined;
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
const isDelegatedAuthEnabled = delegatedAuth === true;
|
|
33
|
+
const profiles = (await hasField(ctx, 'Profile', SSO_PERMISSION))
|
|
34
|
+
? await ctx.soql.queryAll(`SELECT Id, Name, ${SSO_PERMISSION} FROM Profile WHERE ${SSO_PERMISSION} = true`)
|
|
35
|
+
: [];
|
|
36
|
+
const adminProfilesWithDelegatedAuth = profiles.filter((p) => p.Name.toLowerCase().includes('admin') || p.Name === 'System Administrator');
|
|
37
|
+
if (isDelegatedAuthEnabled) {
|
|
38
|
+
// Check 1: Insecure Gateway URL (non-https or cleartext)
|
|
39
|
+
const isInsecure = !gatewayUrl ||
|
|
40
|
+
gatewayUrl.startsWith('http://') ||
|
|
41
|
+
(!gatewayUrl.startsWith('https://') && gatewayUrl.length > 0);
|
|
42
|
+
if (isInsecure) {
|
|
43
|
+
findings.push({
|
|
44
|
+
id: 'delegated-authentication-insecure-gateway',
|
|
45
|
+
category: this.category,
|
|
46
|
+
riskLevel: 'CRITICAL',
|
|
47
|
+
title: 'Delegated Authentication gateway is unencrypted or missing mutual TLS',
|
|
48
|
+
detail: `Delegated Authentication is enabled with gateway URL "${gatewayUrl || 'empty'}". Unlike SAML or OIDC, Delegated Authentication relies on a simple SOAP boolean response without cryptographic assertion signatures. Transmitting credentials over unencrypted or unauthenticated endpoints allows credential harvesting and spoofed responses.`,
|
|
49
|
+
remediation: 'Configure a secure HTTPS endpoint with mutual TLS (mTLS) client certificate verification for the Delegated Authentication gateway, or migrate to SAML 2.0 / OpenID Connect.',
|
|
50
|
+
affectedItems: [
|
|
51
|
+
{
|
|
52
|
+
label: 'Delegated Gateway Endpoint',
|
|
53
|
+
url: ssoUrl,
|
|
54
|
+
note: `Gateway URL: ${gatewayUrl || 'None configured'}`,
|
|
55
|
+
},
|
|
56
|
+
],
|
|
57
|
+
});
|
|
58
|
+
}
|
|
59
|
+
// Check 2: Assigned to System Administrators
|
|
60
|
+
if (adminProfilesWithDelegatedAuth.length > 0) {
|
|
61
|
+
findings.push({
|
|
62
|
+
id: 'delegated-authentication-admin-assigned',
|
|
63
|
+
category: this.category,
|
|
64
|
+
riskLevel: 'CRITICAL',
|
|
65
|
+
title: `Delegated Authentication is assigned to ${adminProfilesWithDelegatedAuth.length} Administrator profile(s)`,
|
|
66
|
+
detail: 'The "Is Single Sign-On Enabled" permission routes user authentication through the external delegated gateway. When assigned to System Administrators, compromising or spoofing the delegated gateway grants instantaneous full org takeover as an admin.',
|
|
67
|
+
remediation: 'Remove "Is Single Sign-On Enabled" from System Administrator and privileged profiles. Reserve Delegated Authentication strictly for standard users, or enforce SAML/OIDC.',
|
|
68
|
+
affectedItems: adminProfilesWithDelegatedAuth.map((p) => ({
|
|
69
|
+
label: p.Name,
|
|
70
|
+
url: `${baseUrl}/lightning/setup/EnhancedProfiles/page?address=%2F${p.Id}`,
|
|
71
|
+
note: 'Admin profile routes authentication through delegated gateway',
|
|
72
|
+
})),
|
|
73
|
+
});
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
if (delegatedAuth === undefined) {
|
|
77
|
+
findings.push({
|
|
78
|
+
id: 'delegated-authentication-advisory',
|
|
79
|
+
category: this.category,
|
|
80
|
+
riskLevel: 'INFO',
|
|
81
|
+
title: 'Verify Delegated Authentication settings manually',
|
|
82
|
+
detail: `This run could not read SecuritySettings, so whether Delegated Authentication is enabled is unknown. ${adminProfilesWithDelegatedAuth.length} administrator profile(s) hold "Is Single Sign-On Enabled", which routes their sign-in through the delegated gateway if it is on.`,
|
|
83
|
+
remediation: 'In Setup → Single Sign-On Settings, check whether Delegated Authentication is enabled. If it is, the gateway must be HTTPS with mutual TLS, and administrator profiles should not hold "Is Single Sign-On Enabled".',
|
|
84
|
+
affectedItems: [{ label: 'Single Sign-On Settings', url: ssoUrl }],
|
|
85
|
+
});
|
|
86
|
+
}
|
|
87
|
+
else if (findings.length === 0) {
|
|
88
|
+
findings.push({
|
|
89
|
+
id: 'delegated-authentication-exposure-ok',
|
|
90
|
+
category: this.category,
|
|
91
|
+
riskLevel: 'LOW',
|
|
92
|
+
passed: true,
|
|
93
|
+
title: isDelegatedAuthEnabled
|
|
94
|
+
? 'Delegated Authentication uses an HTTPS gateway and is not assigned to administrators'
|
|
95
|
+
: 'Delegated Authentication is disabled',
|
|
96
|
+
detail: isDelegatedAuthEnabled
|
|
97
|
+
? 'SecuritySettings shows Delegated Authentication enabled with an HTTPS gateway, and no administrator profile holds "Is Single Sign-On Enabled".'
|
|
98
|
+
: 'SecuritySettings confirms Delegated Authentication is disabled, so no sign-in is routed through an external gateway.',
|
|
99
|
+
remediation: 'Continue using SAML 2.0 or OpenID Connect with signed assertions for SSO.',
|
|
100
|
+
});
|
|
101
|
+
}
|
|
102
|
+
return { findings };
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
//# sourceMappingURL=DelegatedAuthenticationExposureCheck.js.map
|