@cclabsnz/sf-audit 1.0.1 → 1.1.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 +75 -0
- package/lib/api/ToolingClientImpl.js +5 -2
- package/lib/chains/AttackChain.d.ts +20 -0
- package/lib/chains/AttackChain.js +2 -0
- package/lib/chains/Capability.d.ts +7 -0
- package/lib/chains/Capability.js +11 -0
- package/lib/chains/CapabilityRegistry.d.ts +18 -0
- package/lib/chains/CapabilityRegistry.js +53 -0
- package/lib/chains/ChainEngine.d.ts +13 -0
- package/lib/chains/ChainEngine.js +137 -0
- package/lib/chains/namedChains.d.ts +14 -0
- package/lib/chains/namedChains.js +99 -0
- package/lib/checks/CheckEngine.js +33 -5
- package/lib/checks/impl/AnonymousApexAuditCheck.d.ts +10 -0
- package/lib/checks/impl/AnonymousApexAuditCheck.js +106 -0
- package/lib/checks/impl/ApexCrudFLSCheck.d.ts +11 -0
- package/lib/checks/impl/ApexCrudFLSCheck.js +98 -0
- package/lib/checks/impl/ApexLoggingCheck.d.ts +11 -0
- package/lib/checks/impl/ApexLoggingCheck.js +124 -0
- package/lib/checks/impl/ApexRestEndpointCheck.d.ts +11 -0
- package/lib/checks/impl/ApexRestEndpointCheck.js +94 -0
- package/lib/checks/impl/ApexSharingCheck.js +29 -0
- package/lib/checks/impl/ApiClientPermissionCheck.d.ts +10 -0
- package/lib/checks/impl/ApiClientPermissionCheck.js +59 -0
- package/lib/checks/impl/AuditTrailCheck.js +29 -0
- package/lib/checks/impl/CertificateExpiryCheck.d.ts +10 -0
- package/lib/checks/impl/CertificateExpiryCheck.js +123 -0
- package/lib/checks/impl/CodeSecurityCheck.d.ts +2 -1
- package/lib/checks/impl/CodeSecurityCheck.js +46 -6
- package/lib/checks/impl/ConnectedAppInactivityCheck.d.ts +11 -0
- package/lib/checks/impl/ConnectedAppInactivityCheck.js +86 -0
- package/lib/checks/impl/ConnectedAppScopeCheck.d.ts +10 -0
- package/lib/checks/impl/ConnectedAppScopeCheck.js +125 -0
- package/lib/checks/impl/ConnectedAppsCheck.d.ts +1 -0
- package/lib/checks/impl/ConnectedAppsCheck.js +37 -2
- package/lib/checks/impl/ContentLinksCheck.d.ts +10 -0
- package/lib/checks/impl/ContentLinksCheck.js +115 -0
- package/lib/checks/impl/CorsAllowlistCheck.d.ts +10 -0
- package/lib/checks/impl/CorsAllowlistCheck.js +80 -0
- package/lib/checks/impl/CspTrustedSitesCheck.d.ts +10 -0
- package/lib/checks/impl/CspTrustedSitesCheck.js +55 -0
- package/lib/checks/impl/CustomLabelsCredentialCheck.d.ts +10 -0
- package/lib/checks/impl/CustomLabelsCredentialCheck.js +97 -0
- package/lib/checks/impl/DataClassificationCheck.d.ts +10 -0
- package/lib/checks/impl/DataClassificationCheck.js +112 -0
- package/lib/checks/impl/DebugLogAccessCheck.d.ts +10 -0
- package/lib/checks/impl/DebugLogAccessCheck.js +81 -0
- package/lib/checks/impl/DeploymentIdentityCheck.d.ts +11 -0
- package/lib/checks/impl/DeploymentIdentityCheck.js +144 -0
- package/lib/checks/impl/EnhancedDomainsCheck.d.ts +10 -0
- package/lib/checks/impl/EnhancedDomainsCheck.js +84 -0
- package/lib/checks/impl/EscalationPermsCheck.d.ts +10 -0
- package/lib/checks/impl/EscalationPermsCheck.js +77 -0
- package/lib/checks/impl/EventMonitoringCheck.d.ts +11 -0
- package/lib/checks/impl/EventMonitoringCheck.js +84 -0
- package/lib/checks/impl/ExperienceCloudSiteCheck.d.ts +10 -0
- package/lib/checks/impl/ExperienceCloudSiteCheck.js +91 -0
- package/lib/checks/impl/FailedLoginCheck.d.ts +10 -0
- package/lib/checks/impl/FailedLoginCheck.js +122 -0
- package/lib/checks/impl/FieldHistoryTrackingCheck.d.ts +10 -0
- package/lib/checks/impl/FieldHistoryTrackingCheck.js +70 -0
- package/lib/checks/impl/FieldLevelSecurityCheck.js +28 -18
- package/lib/checks/impl/GuestExecutableApexCheck.d.ts +11 -0
- package/lib/checks/impl/GuestExecutableApexCheck.js +93 -0
- package/lib/checks/impl/GuestUserAccessCheck.js +74 -66
- package/lib/checks/impl/HardcodedCredentialsCheck.js +2 -2
- package/lib/checks/impl/HighAssuranceSessionCheck.d.ts +10 -0
- package/lib/checks/impl/HighAssuranceSessionCheck.js +103 -0
- package/lib/checks/impl/InactiveUsersCheck.js +38 -19
- package/lib/checks/impl/InstalledPackagesCheck.d.ts +10 -0
- package/lib/checks/impl/InstalledPackagesCheck.js +94 -0
- package/lib/checks/impl/IntegrationUsersCheck.d.ts +10 -0
- package/lib/checks/impl/IntegrationUsersCheck.js +108 -0
- package/lib/checks/impl/InternalUserMfaCheck.d.ts +10 -0
- package/lib/checks/impl/InternalUserMfaCheck.js +81 -0
- package/lib/checks/impl/IpRestrictionsCheck.js +86 -23
- package/lib/checks/impl/LegacyApiVersionCheck.d.ts +10 -0
- package/lib/checks/impl/LegacyApiVersionCheck.js +91 -0
- package/lib/checks/impl/MfaEnforcementCheck.d.ts +10 -0
- package/lib/checks/impl/MfaEnforcementCheck.js +76 -0
- package/lib/checks/impl/MfaMethodStrengthCheck.d.ts +11 -0
- package/lib/checks/impl/MfaMethodStrengthCheck.js +116 -0
- package/lib/checks/impl/MfaRegistrationCheck.d.ts +11 -0
- package/lib/checks/impl/MfaRegistrationCheck.js +95 -0
- package/lib/checks/impl/MyDomainLoginPolicyCheck.d.ts +10 -0
- package/lib/checks/impl/MyDomainLoginPolicyCheck.js +105 -0
- package/lib/checks/impl/NamedCredentialsCheck.js +37 -2
- package/lib/checks/impl/PermissionsCheck.js +67 -14
- package/lib/checks/impl/PublicGroupSharingCheck.js +20 -9
- package/lib/checks/impl/ReleaseUpdatesCheck.d.ts +10 -0
- package/lib/checks/impl/ReleaseUpdatesCheck.js +106 -0
- package/lib/checks/impl/ReportFolderAccessCheck.d.ts +10 -0
- package/lib/checks/impl/ReportFolderAccessCheck.js +54 -0
- package/lib/checks/impl/ScheduledApexCheck.d.ts +1 -0
- package/lib/checks/impl/ScheduledApexCheck.js +3 -0
- package/lib/checks/impl/SharingModelCheck.d.ts +1 -1
- package/lib/checks/impl/SharingModelCheck.js +103 -32
- package/lib/checks/impl/SiemIntegrationCheck.d.ts +11 -0
- package/lib/checks/impl/SiemIntegrationCheck.js +102 -0
- package/lib/checks/impl/SsoEnforcementCheck.d.ts +10 -0
- package/lib/checks/impl/SsoEnforcementCheck.js +90 -0
- package/lib/checks/impl/StandardProfilesCheck.d.ts +10 -0
- package/lib/checks/impl/StandardProfilesCheck.js +68 -0
- package/lib/checks/impl/TransactionSecurityPolicyCheck.d.ts +10 -0
- package/lib/checks/impl/TransactionSecurityPolicyCheck.js +62 -0
- package/lib/checks/impl/TrustedIPRangesCheck.d.ts +10 -0
- package/lib/checks/impl/TrustedIPRangesCheck.js +106 -0
- package/lib/checks/impl/UsersAndAdminsCheck.js +50 -20
- package/lib/checks/impl/VisualforceXssCheck.d.ts +11 -0
- package/lib/checks/impl/VisualforceXssCheck.js +150 -0
- package/lib/checks/registry.js +97 -12
- package/lib/commands/audit/diff.d.ts +17 -0
- package/lib/commands/audit/diff.js +76 -0
- package/lib/commands/audit/history.d.ts +15 -0
- package/lib/commands/audit/history.js +59 -0
- package/lib/commands/audit/security.js +6 -6
- package/lib/context/AuditCache.d.ts +20 -0
- package/lib/context/AuditContext.d.ts +0 -2
- package/lib/findings/AuditResult.d.ts +3 -0
- package/lib/findings/ComplianceMapping.d.ts +3 -0
- package/lib/findings/ComplianceMapping.js +75 -0
- package/lib/findings/Finding.d.ts +20 -0
- package/lib/findings/loadScoringConfig.js +9 -2
- package/lib/findings/scoring.d.ts +2 -1
- package/lib/findings/scoring.js +20 -7
- package/lib/history/AuditDiff.d.ts +26 -0
- package/lib/history/AuditDiff.js +2 -0
- package/lib/history/DiffEngine.d.ts +4 -0
- package/lib/history/DiffEngine.js +61 -0
- package/lib/history/HistoryStore.d.ts +11 -0
- package/lib/history/HistoryStore.js +56 -0
- package/lib/history/metricMeta.d.ts +9 -0
- package/lib/history/metricMeta.js +28 -0
- package/lib/index.d.ts +7 -1
- package/lib/index.js +2 -1
- package/lib/lib/wire.d.ts +1 -2
- package/lib/lib/wire.js +1 -2
- package/lib/renderers/DiffHtmlRenderer.d.ts +8 -0
- package/lib/renderers/DiffHtmlRenderer.js +164 -0
- package/lib/renderers/DiffJsonRenderer.d.ts +8 -0
- package/lib/renderers/DiffJsonRenderer.js +8 -0
- package/lib/renderers/DiffRenderer.d.ts +7 -0
- package/lib/renderers/DiffRenderer.js +2 -0
- package/lib/renderers/HistoryRenderer.d.ts +6 -0
- package/lib/renderers/HistoryRenderer.js +140 -0
- package/lib/renderers/HtmlRenderer.d.ts +1 -0
- package/lib/renderers/HtmlRenderer.js +354 -54
- package/lib/renderers/MarkdownRenderer.js +34 -1
- package/package.json +3 -3
|
@@ -0,0 +1,106 @@
|
|
|
1
|
+
function isAdminProfile(profileName) {
|
|
2
|
+
const lower = profileName.toLowerCase();
|
|
3
|
+
return lower.includes('admin') || lower.includes('system administrator');
|
|
4
|
+
}
|
|
5
|
+
export class AnonymousApexAuditCheck {
|
|
6
|
+
id = 'anonymous-apex-audit';
|
|
7
|
+
name = 'Anonymous Apex Execution Audit';
|
|
8
|
+
category = 'Code Security';
|
|
9
|
+
description = 'Detects anonymous Apex execution in the last 90 days via SetupAuditTrail';
|
|
10
|
+
async run(ctx) {
|
|
11
|
+
const findings = [];
|
|
12
|
+
const baseUrl = ctx.orgInfo.instanceUrl;
|
|
13
|
+
const auditTrailUrl = `${baseUrl}/lightning/setup/AuditTrail/home`;
|
|
14
|
+
let records = [];
|
|
15
|
+
try {
|
|
16
|
+
records = await ctx.soql.queryAll(`SELECT CreatedDate, CreatedBy.Id, CreatedBy.Username, CreatedBy.Profile.Name,
|
|
17
|
+
Section, Action, Display
|
|
18
|
+
FROM SetupAuditTrail
|
|
19
|
+
WHERE CreatedDate > LAST_N_DAYS:90
|
|
20
|
+
AND (Section IN ('Developer Console', 'Developer Tools', 'IDE', 'Development', 'Workbench')
|
|
21
|
+
OR Action LIKE '%anon%'
|
|
22
|
+
OR Action LIKE '%runAs%'
|
|
23
|
+
OR Action LIKE '%executeCode%')
|
|
24
|
+
ORDER BY CreatedDate DESC
|
|
25
|
+
LIMIT 200`);
|
|
26
|
+
}
|
|
27
|
+
catch {
|
|
28
|
+
findings.push({
|
|
29
|
+
id: 'anonymous-apex-inaccessible',
|
|
30
|
+
category: this.category,
|
|
31
|
+
riskLevel: 'INFO',
|
|
32
|
+
inconclusive: true,
|
|
33
|
+
title: 'SetupAuditTrail could not be queried — anonymous Apex execution cannot be verified',
|
|
34
|
+
detail: 'The SetupAuditTrail object was not accessible. This may indicate insufficient permissions to view the org audit trail.',
|
|
35
|
+
remediation: 'Grant "View Setup and Configuration" permission to the audit user. Review anonymous Apex execution manually in Setup → Audit Trail.',
|
|
36
|
+
affectedItems: [{ label: 'Setup Audit Trail', url: auditTrailUrl }],
|
|
37
|
+
});
|
|
38
|
+
return { findings };
|
|
39
|
+
}
|
|
40
|
+
if (records.length === 0) {
|
|
41
|
+
findings.push({
|
|
42
|
+
id: 'anonymous-apex-none',
|
|
43
|
+
category: this.category,
|
|
44
|
+
riskLevel: 'LOW',
|
|
45
|
+
passed: true,
|
|
46
|
+
title: 'No anonymous Apex execution detected in the last 90 days',
|
|
47
|
+
detail: 'No SetupAuditTrail entries matching anonymous Apex execution patterns were found in the last 90 days. This indicates the Developer Console and anonymous Apex execution have not been used recently in production.',
|
|
48
|
+
remediation: 'Continue monitoring. If anonymous Apex execution is ever required, ensure it is pre-approved, logged, and reviewed.',
|
|
49
|
+
});
|
|
50
|
+
return { findings };
|
|
51
|
+
}
|
|
52
|
+
const userMap = new Map();
|
|
53
|
+
for (const r of records) {
|
|
54
|
+
const userId = r.CreatedBy.Id;
|
|
55
|
+
const existing = userMap.get(userId);
|
|
56
|
+
const profileName = r.CreatedBy.Profile?.Name ?? 'Unknown';
|
|
57
|
+
if (existing) {
|
|
58
|
+
existing.count += 1;
|
|
59
|
+
if (r.CreatedDate > existing.latest)
|
|
60
|
+
existing.latest = r.CreatedDate;
|
|
61
|
+
}
|
|
62
|
+
else {
|
|
63
|
+
userMap.set(userId, {
|
|
64
|
+
username: r.CreatedBy.Username,
|
|
65
|
+
profile: profileName,
|
|
66
|
+
count: 1,
|
|
67
|
+
latest: r.CreatedDate,
|
|
68
|
+
});
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
const nonAdminUsers = [...userMap.values()].filter((u) => !isAdminProfile(u.profile));
|
|
72
|
+
const adminOnlyUsers = [...userMap.values()].filter((u) => isAdminProfile(u.profile));
|
|
73
|
+
if (nonAdminUsers.length > 0) {
|
|
74
|
+
findings.push({
|
|
75
|
+
id: 'anonymous-apex-executed',
|
|
76
|
+
category: this.category,
|
|
77
|
+
riskLevel: 'HIGH',
|
|
78
|
+
title: `${nonAdminUsers.length} non-admin user(s) executed anonymous Apex in the last 90 days`,
|
|
79
|
+
detail: 'Anonymous Apex execution in production is a privileged, hard-to-audit operation. Anon Apex runs as the executing user but leaves no code artifact — it cannot be reviewed, versioned, or rolled back. Non-admin users executing anonymous Apex indicates a significant control gap: these users have Developer Console access in production and can manipulate data or bypass sharing rules without leaving a traceable code change.',
|
|
80
|
+
remediation: 'Remove Developer Console access from non-admin users. Revoke the "Author Apex" permission from all profiles and permission sets that do not require it. All code changes in production must go through a formal deployment process (change sets, Salesforce DX). Review each execution instance to determine what code was run and what data was affected.',
|
|
81
|
+
affectedItems: nonAdminUsers.map((u) => ({
|
|
82
|
+
label: u.username,
|
|
83
|
+
url: auditTrailUrl,
|
|
84
|
+
note: `${u.count} execution(s) — latest: ${new Date(u.latest).toISOString().split('T')[0]} — profile: ${u.profile}`,
|
|
85
|
+
})),
|
|
86
|
+
});
|
|
87
|
+
}
|
|
88
|
+
if (adminOnlyUsers.length > 0) {
|
|
89
|
+
findings.push({
|
|
90
|
+
id: 'anonymous-apex-admin-only',
|
|
91
|
+
category: this.category,
|
|
92
|
+
riskLevel: 'MEDIUM',
|
|
93
|
+
title: `Anonymous Apex executed by ${adminOnlyUsers.length} admin-profile user(s) in the last 90 days — monitoring recommended`,
|
|
94
|
+
detail: 'Anonymous Apex execution by administrator-profile users still represents a risk in production: it bypasses change management, leaves no deployable artifact, and cannot be peer-reviewed. Even legitimate use by admins should be tracked, approved, and documented as part of a change management process.',
|
|
95
|
+
remediation: 'Establish a policy requiring pre-approval for any anonymous Apex execution in production. Log approvals in your change management system. Prefer metadata deployments over anonymous Apex for all production data or configuration changes. Consider restricting Developer Console to a dedicated integration user only.',
|
|
96
|
+
affectedItems: adminOnlyUsers.map((u) => ({
|
|
97
|
+
label: u.username,
|
|
98
|
+
url: auditTrailUrl,
|
|
99
|
+
note: `${u.count} execution(s) — latest: ${new Date(u.latest).toISOString().split('T')[0]} — profile: ${u.profile}`,
|
|
100
|
+
})),
|
|
101
|
+
});
|
|
102
|
+
}
|
|
103
|
+
return { findings };
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
//# sourceMappingURL=AnonymousApexAuditCheck.js.map
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import type { AuditContext } from '../../context/AuditContext.js';
|
|
2
|
+
import type { SecurityCheck, CheckResult } from '../SecurityCheck.js';
|
|
3
|
+
export declare class ApexCrudFLSCheck implements SecurityCheck {
|
|
4
|
+
readonly id = "apex-crud-fls";
|
|
5
|
+
readonly name = "Apex CRUD/FLS Enforcement";
|
|
6
|
+
readonly category = "Code Security";
|
|
7
|
+
readonly description = "Flags Apex classes that perform DML or SOQL without checking CRUD/FLS permissions \u2014 OWASP Top 10 for Salesforce";
|
|
8
|
+
readonly dependsOnCache: readonly ["apexBodies"];
|
|
9
|
+
run(ctx: AuditContext): Promise<CheckResult>;
|
|
10
|
+
}
|
|
11
|
+
//# sourceMappingURL=ApexCrudFLSCheck.d.ts.map
|
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
// Patterns that indicate DML or inline SOQL is being performed
|
|
2
|
+
const HAS_DML = /\b(?:insert|update|delete|upsert|merge)\s+\w+|Database\.(?:insert|update|delete|upsert|merge)\s*\(/i;
|
|
3
|
+
const HAS_SOQL = /\[\s*SELECT\b|Database\.(?:query|queryWithBinds|countQuery)\s*\(/i;
|
|
4
|
+
// Patterns that indicate FLS/CRUD is being checked or enforced
|
|
5
|
+
const HAS_FLS = /(?:\.isAccessible\(\)|\.isCreateable\(\)|\.isUpdateable\(\)|\.isDeletable\(\)|Security\.stripInaccessible|SObjectAccessDecision|Schema\.describeSObjects|Schema\.sObjectType\.\w+\.fields)/i;
|
|
6
|
+
// Classes that are exempt from CRUD/FLS enforcement by design:
|
|
7
|
+
// batch, scheduled, and trigger handlers run in a system context
|
|
8
|
+
const IS_BATCH_OR_SCHEDULED = /implements\s+(?:Database\.Batchable|Schedulable|Database\.StatefulBatch|Database\.AllowsCallouts)/i;
|
|
9
|
+
const IS_TEST = /@IsTest\b/i;
|
|
10
|
+
const WITHOUT_SHARING = /\bwithout\s+sharing\b/i;
|
|
11
|
+
export class ApexCrudFLSCheck {
|
|
12
|
+
id = 'apex-crud-fls';
|
|
13
|
+
name = 'Apex CRUD/FLS Enforcement';
|
|
14
|
+
category = 'Code Security';
|
|
15
|
+
description = 'Flags Apex classes that perform DML or SOQL without checking CRUD/FLS permissions — OWASP Top 10 for Salesforce';
|
|
16
|
+
dependsOnCache = ['apexBodies'];
|
|
17
|
+
async run(ctx) {
|
|
18
|
+
const findings = [];
|
|
19
|
+
const apexClassesUrl = `${ctx.orgInfo.instanceUrl}/lightning/setup/ApexClasses/home`;
|
|
20
|
+
const apexBodies = ctx.cache.apexBodies ?? [];
|
|
21
|
+
if (apexBodies.length === 0) {
|
|
22
|
+
findings.push({
|
|
23
|
+
id: 'apex-crud-fls-no-bodies',
|
|
24
|
+
category: this.category,
|
|
25
|
+
riskLevel: 'INFO',
|
|
26
|
+
inconclusive: true,
|
|
27
|
+
title: 'Apex class bodies not available — CRUD/FLS check skipped',
|
|
28
|
+
detail: 'Apex class bodies were not cached. Ensure HardcodedCredentialsCheck runs before this check.',
|
|
29
|
+
remediation: 'Verify registry ordering so HardcodedCredentialsCheck (which populates apexBodies) precedes ApexCrudFLSCheck.',
|
|
30
|
+
});
|
|
31
|
+
return { findings };
|
|
32
|
+
}
|
|
33
|
+
const withoutSharingNoFls = [];
|
|
34
|
+
const withDmlNoFls = [];
|
|
35
|
+
// apexBodies is pre-filtered by HardcodedCredentialsCheck to exclude test classes;
|
|
36
|
+
// IS_TEST guard here is redundant but kept for cache-miss safety
|
|
37
|
+
for (const { name, body } of apexBodies) {
|
|
38
|
+
if (!body || IS_BATCH_OR_SCHEDULED.test(body))
|
|
39
|
+
continue;
|
|
40
|
+
const hasDml = HAS_DML.test(body);
|
|
41
|
+
const hasSoql = HAS_SOQL.test(body);
|
|
42
|
+
if (!hasDml && !hasSoql)
|
|
43
|
+
continue;
|
|
44
|
+
const hasFls = HAS_FLS.test(body);
|
|
45
|
+
if (hasFls)
|
|
46
|
+
continue;
|
|
47
|
+
if (WITHOUT_SHARING.test(body)) {
|
|
48
|
+
withoutSharingNoFls.push(name);
|
|
49
|
+
}
|
|
50
|
+
else {
|
|
51
|
+
withDmlNoFls.push(name);
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
if (withoutSharingNoFls.length > 0) {
|
|
55
|
+
findings.push({
|
|
56
|
+
id: 'apex-crud-fls-without-sharing',
|
|
57
|
+
category: this.category,
|
|
58
|
+
riskLevel: 'HIGH',
|
|
59
|
+
title: `${withoutSharingNoFls.length} Apex class(es) run "without sharing" and perform DML/SOQL without CRUD/FLS checks`,
|
|
60
|
+
detail: `Apex classes declared "without sharing" bypass record-level visibility AND have no field-level or object-level permission checks, meaning any user who triggers the code can read or write any record and field regardless of their assigned permissions. This is the most exploited Salesforce access control vulnerability. OWASP Salesforce Top 10 ranks CRUD/FLS bypass as the #1 risk.`,
|
|
61
|
+
remediation: 'Refactor to use "with sharing" where possible. Add `Security.stripInaccessible()` before DML and `Schema.SObjectType.[Object].fields.[Field].isAccessible()` before displaying fields. Where "without sharing" is required for a technical reason, document the justification and tighten the scope.',
|
|
62
|
+
affectedItems: withoutSharingNoFls.slice(0, 30).map((n) => ({
|
|
63
|
+
label: n,
|
|
64
|
+
url: apexClassesUrl,
|
|
65
|
+
note: '"without sharing" + DML/SOQL + no FLS check — highest risk',
|
|
66
|
+
})),
|
|
67
|
+
});
|
|
68
|
+
}
|
|
69
|
+
if (withDmlNoFls.length > 0) {
|
|
70
|
+
findings.push({
|
|
71
|
+
id: 'apex-crud-fls-missing',
|
|
72
|
+
category: this.category,
|
|
73
|
+
riskLevel: 'MEDIUM',
|
|
74
|
+
title: `${withDmlNoFls.length} Apex class(es) perform DML or SOQL without CRUD/FLS permission checks`,
|
|
75
|
+
detail: `These classes perform database operations without checking whether the running user has create, read, update, or delete permission on the relevant objects or fields. While sharing rules still apply, object and field-level access is not enforced in code. Users can potentially access or modify data beyond their intended permissions via these code paths.`,
|
|
76
|
+
remediation: `Add CRUD checks before DML: \`Schema.SObjectType.[Object].isCreateable()\`. Use \`Security.stripInaccessible(AccessType.READABLE, records)\` before exposing query results. Consider adopting a shared FLS utility class to centralise enforcement.`,
|
|
77
|
+
affectedItems: withDmlNoFls.slice(0, 30).map((n) => ({
|
|
78
|
+
label: n,
|
|
79
|
+
url: apexClassesUrl,
|
|
80
|
+
note: 'DML/SOQL without FLS check — add Security.stripInaccessible() or isAccessible() guards',
|
|
81
|
+
})),
|
|
82
|
+
});
|
|
83
|
+
}
|
|
84
|
+
if (withoutSharingNoFls.length === 0 && withDmlNoFls.length === 0) {
|
|
85
|
+
findings.push({
|
|
86
|
+
id: 'apex-crud-fls-ok',
|
|
87
|
+
category: this.category,
|
|
88
|
+
riskLevel: 'LOW',
|
|
89
|
+
passed: true,
|
|
90
|
+
title: 'All scanned Apex classes with DML/SOQL include CRUD/FLS permission checks',
|
|
91
|
+
detail: 'No Apex classes were found performing DML or SOQL without corresponding object-level or field-level security checks. This scan covers non-test, non-batch classes in the org namespace.',
|
|
92
|
+
remediation: 'Continue monitoring as new Apex classes are developed.',
|
|
93
|
+
});
|
|
94
|
+
}
|
|
95
|
+
return { findings };
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
//# sourceMappingURL=ApexCrudFLSCheck.js.map
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import type { AuditContext } from '../../context/AuditContext.js';
|
|
2
|
+
import type { SecurityCheck, CheckResult } from '../SecurityCheck.js';
|
|
3
|
+
export declare class ApexLoggingCheck implements SecurityCheck {
|
|
4
|
+
readonly id = "apex-logging";
|
|
5
|
+
readonly name = "Apex Logging Framework";
|
|
6
|
+
readonly category = "Code Security";
|
|
7
|
+
readonly description = "SBS-CODE-003/004: checks for persistent logging framework usage and sensitive data in Apex logs";
|
|
8
|
+
readonly dependsOnCache: readonly ["apexBodies", "scheduledApexClassNames"];
|
|
9
|
+
run(ctx: AuditContext): Promise<CheckResult>;
|
|
10
|
+
}
|
|
11
|
+
//# sourceMappingURL=ApexLoggingCheck.d.ts.map
|
|
@@ -0,0 +1,124 @@
|
|
|
1
|
+
// SBS-CODE-003: indicators of a persistent logging framework (as opposed to System.debug)
|
|
2
|
+
const PERSISTENT_LOGGER_PATTERNS = [
|
|
3
|
+
/\bfflib_Logger\b/i,
|
|
4
|
+
/\bLogger\s*\.\s*(?:log|info|warn|error|debug|fine)\s*\(/i,
|
|
5
|
+
/\bLoggingService\s*\.\s*(?:log|info|warn|error)\s*\(/i,
|
|
6
|
+
/\bLogService\s*\.\s*(?:log|info|warn|error)\s*\(/i,
|
|
7
|
+
/\bApplicationLogger\b/i,
|
|
8
|
+
/\bPlatformLogger\b/i,
|
|
9
|
+
/EventBus\.publish\s*\(/i, // logging via Platform Events
|
|
10
|
+
/insert\s+new\s+Log__c\b/i, // custom log object insert
|
|
11
|
+
/insert\s+logRecords\b/i,
|
|
12
|
+
/\bApplicationLog\s*\.\s*(?:log|add)\b/i,
|
|
13
|
+
];
|
|
14
|
+
// SBS-CODE-004: patterns suggesting sensitive data is passed to System.debug
|
|
15
|
+
const SENSITIVE_LOG_PATTERNS = [
|
|
16
|
+
/System\.debug\s*\([^)]*(?:password|secret|token|apiKey|api_key|credential|ssn|dob|dateOfBirth|creditCard|cardNumber)/i,
|
|
17
|
+
/System\.debug\s*\([^)]*(?:UserInfo\.getSessionId|Auth\.AuthToken|getSessionId\(\))/i,
|
|
18
|
+
];
|
|
19
|
+
const SYSTEM_DEBUG_RE = /\bSystem\.debug\s*\(/;
|
|
20
|
+
const IS_TEST_CLASS_RE = /@IsTest\b/i;
|
|
21
|
+
export class ApexLoggingCheck {
|
|
22
|
+
id = 'apex-logging';
|
|
23
|
+
name = 'Apex Logging Framework';
|
|
24
|
+
category = 'Code Security';
|
|
25
|
+
description = 'SBS-CODE-003/004: checks for persistent logging framework usage and sensitive data in Apex logs';
|
|
26
|
+
// Apex bodies are written by HardcodedCredentialsCheck;
|
|
27
|
+
// scheduled class names are written by ScheduledApexCheck.
|
|
28
|
+
dependsOnCache = ['apexBodies', 'scheduledApexClassNames'];
|
|
29
|
+
async run(ctx) {
|
|
30
|
+
const findings = [];
|
|
31
|
+
const apexClassesUrl = `${ctx.orgInfo.instanceUrl}/lightning/setup/ApexClasses/home`;
|
|
32
|
+
const apexBodies = ctx.cache.apexBodies ?? [];
|
|
33
|
+
const scheduledClassNames = new Set(ctx.cache.scheduledApexClassNames ?? []);
|
|
34
|
+
if (apexBodies.length === 0) {
|
|
35
|
+
findings.push({
|
|
36
|
+
id: 'apex-logging-no-bodies',
|
|
37
|
+
category: this.category,
|
|
38
|
+
riskLevel: 'INFO',
|
|
39
|
+
inconclusive: true,
|
|
40
|
+
title: 'Apex class bodies not available — SBS-CODE-003/004 check skipped',
|
|
41
|
+
detail: 'SBS-CODE-003/004 require scanning Apex class bodies for logging patterns. Apex bodies were not available in the audit cache — ensure HardcodedCredentialsCheck runs before this check.',
|
|
42
|
+
remediation: 'Verify HardcodedCredentialsCheck is registered before ApexLoggingCheck in the check registry.',
|
|
43
|
+
});
|
|
44
|
+
return { findings };
|
|
45
|
+
}
|
|
46
|
+
const productionClasses = apexBodies.filter((c) => c.body && !IS_TEST_CLASS_RE.test(c.body));
|
|
47
|
+
const debugOnlyClasses = [];
|
|
48
|
+
const persistentLoggerClasses = [];
|
|
49
|
+
for (const { name, body } of productionClasses) {
|
|
50
|
+
const hasPersistentLogger = PERSISTENT_LOGGER_PATTERNS.some((p) => p.test(body));
|
|
51
|
+
const hasSystemDebug = SYSTEM_DEBUG_RE.test(body);
|
|
52
|
+
if (hasPersistentLogger) {
|
|
53
|
+
persistentLoggerClasses.push(name);
|
|
54
|
+
}
|
|
55
|
+
else if (hasSystemDebug) {
|
|
56
|
+
debugOnlyClasses.push(name);
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
// SBS-CODE-004: flag classes that appear to log sensitive values
|
|
60
|
+
const sensitiveLogClasses = [];
|
|
61
|
+
for (const { name, body } of productionClasses) {
|
|
62
|
+
if (SENSITIVE_LOG_PATTERNS.some((p) => p.test(body))) {
|
|
63
|
+
sensitiveLogClasses.push(name);
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
const scheduledDebugClasses = debugOnlyClasses.filter((n) => scheduledClassNames.has(n));
|
|
67
|
+
if (persistentLoggerClasses.length > 0) {
|
|
68
|
+
findings.push({
|
|
69
|
+
id: 'apex-logging-framework-in-use',
|
|
70
|
+
category: this.category,
|
|
71
|
+
riskLevel: 'LOW',
|
|
72
|
+
passed: true,
|
|
73
|
+
title: `${persistentLoggerClasses.length} Apex class(es) use a persistent logging framework — SBS-CODE-003`,
|
|
74
|
+
detail: `SBS-CODE-003 requires Apex to use a persistent logging framework rather than transient System.debug calls. ${persistentLoggerClasses.length} class(es) reference a persistent logger. Examples: ${persistentLoggerClasses.slice(0, 5).join(', ')}${persistentLoggerClasses.length > 5 ? ` (+${persistentLoggerClasses.length - 5} more)` : ''}.`,
|
|
75
|
+
remediation: 'Extend persistent logging coverage to all production classes that handle significant business logic or integration operations.',
|
|
76
|
+
});
|
|
77
|
+
}
|
|
78
|
+
if (debugOnlyClasses.length > 0) {
|
|
79
|
+
findings.push({
|
|
80
|
+
id: 'apex-logging-debug-only',
|
|
81
|
+
category: this.category,
|
|
82
|
+
riskLevel: scheduledDebugClasses.length > 0 ? 'MEDIUM' : 'LOW',
|
|
83
|
+
title: `${debugOnlyClasses.length} Apex class(es) use only System.debug — SBS-CODE-003`,
|
|
84
|
+
detail: `SBS-CODE-003 requires a persistent logging framework so that audit and error events are durable and searchable after the fact. ${debugOnlyClasses.length} production class(es) rely solely on System.debug, whose output is transient and unavailable once the debug log expires. ${scheduledDebugClasses.length > 0 ? `${scheduledDebugClasses.length} of these are scheduled or batch jobs — persistent logging is especially important for operational visibility in background processes.` : ''}`,
|
|
85
|
+
remediation: 'Adopt a persistent logging framework (a custom Log__c object, Platform Events, or an open-source framework) and migrate System.debug calls to it for all classes handling critical business logic.',
|
|
86
|
+
affectedItems: debugOnlyClasses.slice(0, 30).map((name) => ({
|
|
87
|
+
label: name,
|
|
88
|
+
url: apexClassesUrl,
|
|
89
|
+
note: scheduledClassNames.has(name)
|
|
90
|
+
? 'scheduled/batch job — high priority to add persistent logging'
|
|
91
|
+
: 'System.debug only — no persistent log trail',
|
|
92
|
+
})),
|
|
93
|
+
});
|
|
94
|
+
}
|
|
95
|
+
if (sensitiveLogClasses.length > 0) {
|
|
96
|
+
findings.push({
|
|
97
|
+
id: 'apex-logging-sensitive-data',
|
|
98
|
+
category: this.category,
|
|
99
|
+
riskLevel: 'HIGH',
|
|
100
|
+
title: `${sensitiveLogClasses.length} Apex class(es) may log sensitive data — SBS-CODE-004`,
|
|
101
|
+
detail: 'SBS-CODE-004 prohibits logging sensitive data (passwords, tokens, session IDs, PII) in Apex. The flagged classes appear to pass sensitive variable names or credential values directly to System.debug(), which writes them to debug logs accessible to any administrator who can view debug logs.',
|
|
102
|
+
remediation: 'Remove all logging of passwords, tokens, API keys, and PII from Apex code. Review each flagged class and mask, redact, or entirely exclude sensitive values before passing them to any logging call.',
|
|
103
|
+
affectedItems: sensitiveLogClasses.map((name) => ({
|
|
104
|
+
label: name,
|
|
105
|
+
url: apexClassesUrl,
|
|
106
|
+
note: 'Review System.debug() calls — sensitive variable names detected near logging statements',
|
|
107
|
+
})),
|
|
108
|
+
});
|
|
109
|
+
}
|
|
110
|
+
if (debugOnlyClasses.length === 0 && sensitiveLogClasses.length === 0 && persistentLoggerClasses.length === 0) {
|
|
111
|
+
findings.push({
|
|
112
|
+
id: 'apex-logging-no-debug',
|
|
113
|
+
category: this.category,
|
|
114
|
+
riskLevel: 'LOW',
|
|
115
|
+
passed: true,
|
|
116
|
+
title: 'No System.debug-only logging or sensitive-data logging patterns found — SBS-CODE-003/004',
|
|
117
|
+
detail: 'SBS-CODE-003 requires a persistent logging framework and SBS-CODE-004 prohibits sensitive data in logs. No violations were detected in the scanned Apex classes.',
|
|
118
|
+
remediation: 'Continue monitoring as new Apex classes are added to the org.',
|
|
119
|
+
});
|
|
120
|
+
}
|
|
121
|
+
return { findings };
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
//# sourceMappingURL=ApexLoggingCheck.js.map
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import type { AuditContext } from '../../context/AuditContext.js';
|
|
2
|
+
import type { SecurityCheck, CheckResult } from '../SecurityCheck.js';
|
|
3
|
+
export declare class ApexRestEndpointCheck implements SecurityCheck {
|
|
4
|
+
readonly id = "apex-rest-endpoint";
|
|
5
|
+
readonly name = "Apex REST Endpoint Security";
|
|
6
|
+
readonly category = "Code Security";
|
|
7
|
+
readonly description = "Flags @RestResource Apex classes that run without sharing, exposing records to REST callers without record-level access control";
|
|
8
|
+
readonly dependsOnCache: readonly ["apexBodies"];
|
|
9
|
+
run(ctx: AuditContext): Promise<CheckResult>;
|
|
10
|
+
}
|
|
11
|
+
//# sourceMappingURL=ApexRestEndpointCheck.d.ts.map
|
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
const REST_RESOURCE_RE = /@RestResource\s*\(\s*urlMapping\s*=/i;
|
|
2
|
+
const WITHOUT_SHARING_RE = /\bwithout\s+sharing\b/i;
|
|
3
|
+
const NO_SHARING_DECLARED_RE = /\b(with|without|inherited)\s+sharing\b/i;
|
|
4
|
+
const IS_TEST_RE = /@IsTest\b/i;
|
|
5
|
+
// Indicators that the endpoint performs some form of caller verification
|
|
6
|
+
const AUTH_CHECK_RE = /(?:RestContext\.request\.headers\.get|UserInfo\.getUserId\(\)|UserInfo\.getOrganizationId\(\)|Auth\.AuthConfiguration|isPortalEnabled\(\)|getSessionId\(\))/i;
|
|
7
|
+
const GUEST_VISIBLE_RE = /(@HttpGet|@HttpPost|@HttpPut|@HttpDelete|@HttpPatch)/i;
|
|
8
|
+
export class ApexRestEndpointCheck {
|
|
9
|
+
id = 'apex-rest-endpoint';
|
|
10
|
+
name = 'Apex REST Endpoint Security';
|
|
11
|
+
category = 'Code Security';
|
|
12
|
+
description = 'Flags @RestResource Apex classes that run without sharing, exposing records to REST callers without record-level access control';
|
|
13
|
+
dependsOnCache = ['apexBodies'];
|
|
14
|
+
async run(ctx) {
|
|
15
|
+
const findings = [];
|
|
16
|
+
const apexClassesUrl = `${ctx.orgInfo.instanceUrl}/lightning/setup/ApexClasses/home`;
|
|
17
|
+
const apexBodies = ctx.cache.apexBodies ?? [];
|
|
18
|
+
if (apexBodies.length === 0) {
|
|
19
|
+
findings.push({
|
|
20
|
+
id: 'apex-rest-no-bodies',
|
|
21
|
+
category: this.category,
|
|
22
|
+
riskLevel: 'INFO',
|
|
23
|
+
inconclusive: true,
|
|
24
|
+
title: 'Apex class bodies not available — REST endpoint check skipped',
|
|
25
|
+
detail: 'Apex bodies were not cached. Ensure HardcodedCredentialsCheck runs before this check.',
|
|
26
|
+
remediation: 'Verify registry ordering.',
|
|
27
|
+
});
|
|
28
|
+
return { findings };
|
|
29
|
+
}
|
|
30
|
+
const restClasses = apexBodies.filter(({ body }) => body && !IS_TEST_RE.test(body) && REST_RESOURCE_RE.test(body));
|
|
31
|
+
if (restClasses.length === 0) {
|
|
32
|
+
findings.push({
|
|
33
|
+
id: 'apex-rest-none',
|
|
34
|
+
category: this.category,
|
|
35
|
+
riskLevel: 'LOW',
|
|
36
|
+
passed: true,
|
|
37
|
+
title: 'No custom @RestResource Apex endpoints found',
|
|
38
|
+
detail: 'No Apex classes with the @RestResource annotation were found in the org namespace.',
|
|
39
|
+
remediation: 'Continue monitoring as new Apex code is developed.',
|
|
40
|
+
});
|
|
41
|
+
return { findings };
|
|
42
|
+
}
|
|
43
|
+
// Always emit an inventory of all REST endpoints
|
|
44
|
+
findings.push({
|
|
45
|
+
id: 'apex-rest-inventory',
|
|
46
|
+
category: this.category,
|
|
47
|
+
riskLevel: 'INFO',
|
|
48
|
+
title: `${restClasses.length} custom Apex REST endpoint(s) found`,
|
|
49
|
+
detail: 'Apex classes with @RestResource expose custom REST APIs. These should be reviewed to ensure they enforce authentication, sharing, and field-level security appropriate to the data they expose.',
|
|
50
|
+
remediation: 'Review each REST endpoint: confirm it uses "with sharing", validates the caller, and applies field-level security before returning data.',
|
|
51
|
+
affectedItems: restClasses.map(({ name }) => ({
|
|
52
|
+
label: name,
|
|
53
|
+
url: apexClassesUrl,
|
|
54
|
+
note: 'Custom REST endpoint — review access controls',
|
|
55
|
+
})),
|
|
56
|
+
});
|
|
57
|
+
// Flag endpoints declared without sharing — REST callers bypass record-level access
|
|
58
|
+
const withoutSharing = restClasses.filter(({ body }) => WITHOUT_SHARING_RE.test(body));
|
|
59
|
+
if (withoutSharing.length > 0) {
|
|
60
|
+
findings.push({
|
|
61
|
+
id: 'apex-rest-without-sharing',
|
|
62
|
+
category: this.category,
|
|
63
|
+
riskLevel: 'HIGH',
|
|
64
|
+
title: `${withoutSharing.length} REST endpoint class(es) declared "without sharing"`,
|
|
65
|
+
detail: `Apex REST endpoints declared "without sharing" execute with elevated system privileges — any authenticated (or, if the endpoint is exposed via a Community, unauthenticated) caller can retrieve or modify records regardless of the running user's sharing rules. This is a common vector for horizontal privilege escalation in Salesforce integrations.`,
|
|
66
|
+
remediation: 'Change declarations to "with sharing" so that record-level access is enforced for REST callers. Where system-level access is genuinely required (e.g. an integration service account), document the justification and ensure the endpoint is not accessible to end-user profiles.',
|
|
67
|
+
affectedItems: withoutSharing.map(({ name }) => ({
|
|
68
|
+
label: name,
|
|
69
|
+
url: apexClassesUrl,
|
|
70
|
+
note: '"without sharing" REST endpoint — callers bypass record sharing rules',
|
|
71
|
+
})),
|
|
72
|
+
});
|
|
73
|
+
}
|
|
74
|
+
// Flag endpoints with no sharing declaration at all (inherits from caller — unpredictable)
|
|
75
|
+
const noSharingDeclaration = restClasses.filter(({ body }) => !WITHOUT_SHARING_RE.test(body) && !NO_SHARING_DECLARED_RE.test(body));
|
|
76
|
+
if (noSharingDeclaration.length > 0) {
|
|
77
|
+
findings.push({
|
|
78
|
+
id: 'apex-rest-no-sharing-declaration',
|
|
79
|
+
category: this.category,
|
|
80
|
+
riskLevel: 'MEDIUM',
|
|
81
|
+
title: `${noSharingDeclaration.length} REST endpoint class(es) have no sharing declaration`,
|
|
82
|
+
detail: `Apex classes with no sharing declaration inherit sharing mode from their caller, which is non-deterministic for REST API calls. In REST API contexts the caller is typically the integration user, whose sharing context may be broader than intended. Explicit "with sharing" is required for predictable, secure behaviour.`,
|
|
83
|
+
remediation: 'Add "with sharing" to all @RestResource classes to make sharing enforcement explicit and predictable.',
|
|
84
|
+
affectedItems: noSharingDeclaration.map(({ name }) => ({
|
|
85
|
+
label: name,
|
|
86
|
+
url: apexClassesUrl,
|
|
87
|
+
note: 'No sharing declaration — add "with sharing" explicitly',
|
|
88
|
+
})),
|
|
89
|
+
});
|
|
90
|
+
}
|
|
91
|
+
return { findings };
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
//# sourceMappingURL=ApexRestEndpointCheck.js.map
|
|
@@ -3,6 +3,8 @@ const WITHOUT_SHARING = /\bwithout\s+sharing\b/i;
|
|
|
3
3
|
const WITH_SHARING = /\bwith\s+sharing\b/i;
|
|
4
4
|
const CLASS_PATTERN = /\bclass\s+\w+/i;
|
|
5
5
|
const IS_TEST_CLASS = /@IsTest\b/i;
|
|
6
|
+
// SBS-CPORTAL-001: @AuraEnabled or @RemoteAction marks a class as portal/community-exposed
|
|
7
|
+
const IS_PORTAL_EXPOSED = /@AuraEnabled|@RemoteAction/i;
|
|
6
8
|
function getSharingDeclaration(body) {
|
|
7
9
|
if (!CLASS_PATTERN.test(body)) {
|
|
8
10
|
return null; // Not a class — skip interfaces, enums, etc.
|
|
@@ -35,6 +37,9 @@ export class ApexSharingCheck {
|
|
|
35
37
|
const withoutSharingClasses = [];
|
|
36
38
|
const inheritedSharingClasses = [];
|
|
37
39
|
const noDeclarationClasses = [];
|
|
40
|
+
// SBS-CPORTAL-001: portal-exposed Apex without enforcement = IDOR risk
|
|
41
|
+
const portalExposedWithoutSharing = [];
|
|
42
|
+
const portalExposedNoDeclaration = [];
|
|
38
43
|
for (const apexClass of apexBodies) {
|
|
39
44
|
const body = apexClass.body ?? '';
|
|
40
45
|
// Test classes run as sysadmin — sharing declarations are not applicable
|
|
@@ -43,18 +48,23 @@ export class ApexSharingCheck {
|
|
|
43
48
|
const declaration = getSharingDeclaration(body);
|
|
44
49
|
if (declaration === null)
|
|
45
50
|
continue; // Not a class definition
|
|
51
|
+
const isPortalExposed = IS_PORTAL_EXPOSED.test(body);
|
|
46
52
|
switch (declaration) {
|
|
47
53
|
case 'with':
|
|
48
54
|
withSharingClasses.push(apexClass.name);
|
|
49
55
|
break;
|
|
50
56
|
case 'without':
|
|
51
57
|
withoutSharingClasses.push(apexClass.name);
|
|
58
|
+
if (isPortalExposed)
|
|
59
|
+
portalExposedWithoutSharing.push(apexClass.name);
|
|
52
60
|
break;
|
|
53
61
|
case 'inherited':
|
|
54
62
|
inheritedSharingClasses.push(apexClass.name);
|
|
55
63
|
break;
|
|
56
64
|
case 'none':
|
|
57
65
|
noDeclarationClasses.push(apexClass.name);
|
|
66
|
+
if (isPortalExposed)
|
|
67
|
+
portalExposedNoDeclaration.push(apexClass.name);
|
|
58
68
|
break;
|
|
59
69
|
}
|
|
60
70
|
}
|
|
@@ -62,6 +72,25 @@ export class ApexSharingCheck {
|
|
|
62
72
|
withoutSharingClasses.length +
|
|
63
73
|
inheritedSharingClasses.length +
|
|
64
74
|
noDeclarationClasses.length;
|
|
75
|
+
// SBS-CPORTAL-001: portal-exposed classes with weak sharing declarations are the highest risk
|
|
76
|
+
const allPortalRisk = [...new Set([...portalExposedWithoutSharing, ...portalExposedNoDeclaration])];
|
|
77
|
+
if (allPortalRisk.length > 0) {
|
|
78
|
+
findings.push({
|
|
79
|
+
id: 'portal-exposed-apex-without-sharing',
|
|
80
|
+
category: this.category,
|
|
81
|
+
riskLevel: 'CRITICAL',
|
|
82
|
+
title: `${allPortalRisk.length} portal-exposed Apex class(es) (@AuraEnabled/@RemoteAction) lack "with sharing" — IDOR risk`,
|
|
83
|
+
detail: 'Classes with @AuraEnabled or @RemoteAction methods that use "without sharing" or have no sharing declaration execute without record-level access control. Attackers can supply arbitrary record IDs to read or manipulate data they should not access (IDOR). SBS-CPORTAL-001 requires server-side authorization for every record accessed via portal Apex.',
|
|
84
|
+
remediation: 'Add "with sharing" to all @AuraEnabled and @RemoteAction classes. Validate user ownership or sharing on every record accessed inside these methods.',
|
|
85
|
+
affectedItems: allPortalRisk.map((name) => ({
|
|
86
|
+
label: name,
|
|
87
|
+
url: apexClassesUrl,
|
|
88
|
+
note: portalExposedWithoutSharing.includes(name)
|
|
89
|
+
? 'Uses explicit "without sharing" — replace with "with sharing"'
|
|
90
|
+
: 'No sharing declaration — add "with sharing"',
|
|
91
|
+
})),
|
|
92
|
+
});
|
|
93
|
+
}
|
|
65
94
|
if (withoutSharingClasses.length > 0) {
|
|
66
95
|
const count = withoutSharingClasses.length;
|
|
67
96
|
findings.push({
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import type { AuditContext } from '../../context/AuditContext.js';
|
|
2
|
+
import type { SecurityCheck, CheckResult } from '../SecurityCheck.js';
|
|
3
|
+
export declare class ApiClientPermissionCheck implements SecurityCheck {
|
|
4
|
+
readonly id = "api-client-permission";
|
|
5
|
+
readonly name = "Use Any API Client Permission";
|
|
6
|
+
readonly category = "Permissions";
|
|
7
|
+
readonly description = "SBS-ACS-006: flags users with the \"Use Any API Client\" permission which bypasses API Access Control";
|
|
8
|
+
run(ctx: AuditContext): Promise<CheckResult>;
|
|
9
|
+
}
|
|
10
|
+
//# sourceMappingURL=ApiClientPermissionCheck.d.ts.map
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
export class ApiClientPermissionCheck {
|
|
2
|
+
id = 'api-client-permission';
|
|
3
|
+
name = 'Use Any API Client Permission';
|
|
4
|
+
category = 'Permissions';
|
|
5
|
+
description = 'SBS-ACS-006: flags users with the "Use Any API Client" permission which bypasses API Access Control';
|
|
6
|
+
async run(ctx) {
|
|
7
|
+
const findings = [];
|
|
8
|
+
const baseUrl = ctx.orgInfo.instanceUrl;
|
|
9
|
+
try {
|
|
10
|
+
// Single query — PermissionsUseAnyApiClient may not exist in orgs without API Access Control
|
|
11
|
+
const result = await ctx.soql.query(`SELECT Assignee.Id, Assignee.Username, Assignee.Profile.Name,
|
|
12
|
+
PermissionSet.Name, PermissionSet.IsOwnedByProfile
|
|
13
|
+
FROM PermissionSetAssignment
|
|
14
|
+
WHERE PermissionSet.PermissionsUseAnyApiClient = true
|
|
15
|
+
AND Assignee.IsActive = true
|
|
16
|
+
AND AssigneeId NOT IN (SELECT UserId FROM UserLogin WHERE IsFrozen = true)`);
|
|
17
|
+
const users = result.records;
|
|
18
|
+
if (users.length === 0) {
|
|
19
|
+
findings.push({
|
|
20
|
+
id: 'api-client-permission-ok',
|
|
21
|
+
category: this.category,
|
|
22
|
+
riskLevel: 'LOW',
|
|
23
|
+
passed: true,
|
|
24
|
+
title: 'No users have the "Use Any API Client" permission',
|
|
25
|
+
detail: 'SBS-ACS-006 requires documented justification for the "Use Any API Client" permission, which bypasses API Access Control restrictions. No active users hold this permission.',
|
|
26
|
+
remediation: 'Continue monitoring as new permission sets are created.',
|
|
27
|
+
});
|
|
28
|
+
return { findings };
|
|
29
|
+
}
|
|
30
|
+
const profileGrantors = users.filter((r) => r.PermissionSet.IsOwnedByProfile);
|
|
31
|
+
findings.push({
|
|
32
|
+
id: 'api-client-permission-assigned',
|
|
33
|
+
category: this.category,
|
|
34
|
+
riskLevel: profileGrantors.length > 0 ? 'HIGH' : 'MEDIUM',
|
|
35
|
+
title: `${users.length} user(s) have the "Use Any API Client" permission — SBS-ACS-006`,
|
|
36
|
+
detail: 'SBS-ACS-006 requires documented justification for this permission and states it must not be granted to end-users. "Use Any API Client" bypasses API Access Control, allowing the user to connect via any third-party API client regardless of allowed-list restrictions. This significantly expands the attack surface for unauthorised data access.',
|
|
37
|
+
remediation: 'Review each assignment. Remove from all end-users. Only keep for documented technical users (integration accounts) with a recorded justification in the system of record. Prefer granting through a dedicated permission set, not a profile.',
|
|
38
|
+
affectedItems: users.map((r) => ({
|
|
39
|
+
label: r.Assignee.Username,
|
|
40
|
+
url: `${baseUrl}/${r.Assignee.Id}`,
|
|
41
|
+
note: `via: ${r.PermissionSet.IsOwnedByProfile ? `Profile (${r.Assignee.Profile?.Name ?? 'unknown'})` : r.PermissionSet.Name}`,
|
|
42
|
+
})),
|
|
43
|
+
});
|
|
44
|
+
}
|
|
45
|
+
catch {
|
|
46
|
+
findings.push({
|
|
47
|
+
id: 'api-client-permission-inconclusive',
|
|
48
|
+
category: this.category,
|
|
49
|
+
riskLevel: 'INFO',
|
|
50
|
+
inconclusive: true,
|
|
51
|
+
title: '"Use Any API Client" permission check could not run — field may not exist in this org edition',
|
|
52
|
+
detail: 'SBS-ACS-006 requires documented justification for the "Use Any API Client" permission. This field is part of the API Access Control feature and may not be available in all Salesforce editions.',
|
|
53
|
+
remediation: 'Verify in Setup → Permission Sets whether "Use Any API Client" is available and review assignments if so.',
|
|
54
|
+
});
|
|
55
|
+
}
|
|
56
|
+
return { findings };
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
//# sourceMappingURL=ApiClientPermissionCheck.js.map
|
|
@@ -63,6 +63,35 @@ export class AuditTrailCheck {
|
|
|
63
63
|
})),
|
|
64
64
|
});
|
|
65
65
|
}
|
|
66
|
+
// SBS-MON-002: flag users who can delete Event Monitoring data (erasing the audit trail).
|
|
67
|
+
// PermissionsManageEventLogFiles grants the "Delete Event Monitoring Data" capability.
|
|
68
|
+
try {
|
|
69
|
+
const eventLogDeleteResult = await ctx.soql.query(`SELECT Assignee.Id, Assignee.Username, Assignee.Profile.Name,
|
|
70
|
+
PermissionSet.Name, PermissionSet.IsOwnedByProfile
|
|
71
|
+
FROM PermissionSetAssignment
|
|
72
|
+
WHERE PermissionSet.PermissionsManageEventLogFiles = true
|
|
73
|
+
AND Assignee.IsActive = true
|
|
74
|
+
AND AssigneeId NOT IN (SELECT UserId FROM UserLogin WHERE IsFrozen = true)`);
|
|
75
|
+
const eventLogDeleteUsers = eventLogDeleteResult.records;
|
|
76
|
+
if (eventLogDeleteUsers.length > 0) {
|
|
77
|
+
findings.push({
|
|
78
|
+
id: 'event-log-delete-permission',
|
|
79
|
+
category: this.category,
|
|
80
|
+
riskLevel: 'HIGH',
|
|
81
|
+
title: `${eventLogDeleteUsers.length} active user(s) can delete Event Monitoring data (Manage Event Log Files)`,
|
|
82
|
+
detail: 'SBS-MON-002 requires event logs to be protected from tampering and unauthorised deletion. Users with "Manage Event Log Files" can delete EventLogFile records, permanently destroying audit evidence.',
|
|
83
|
+
remediation: 'Remove the "Manage Event Log Files" permission from all users who do not have a specific, documented administrative need. Consider exporting logs to an immutable external SIEM before any deletion is possible.',
|
|
84
|
+
affectedItems: eventLogDeleteUsers.map((r) => ({
|
|
85
|
+
label: r.Assignee.Username,
|
|
86
|
+
url: `${baseUrl}/${r.Assignee.Id}`,
|
|
87
|
+
note: `via: ${r.PermissionSet.IsOwnedByProfile ? r.Assignee.Profile?.Name ?? 'Profile' : r.PermissionSet.Name}`,
|
|
88
|
+
})),
|
|
89
|
+
});
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
catch {
|
|
93
|
+
// PermissionsManageEventLogFiles may not exist in orgs without Event Monitoring — skip silently
|
|
94
|
+
}
|
|
66
95
|
return { findings };
|
|
67
96
|
}
|
|
68
97
|
}
|