@cclabsnz/sf-audit 1.0.1 → 1.2.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 +228 -31
- 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.d.ts +5 -0
- package/lib/commands/audit/security.js +38 -9
- package/lib/compliance/catalogs/hiso10029.d.ts +3 -0
- package/lib/compliance/catalogs/hiso10029.js +35 -0
- package/lib/compliance/catalogs/index.d.ts +4 -0
- package/lib/compliance/catalogs/index.js +21 -0
- package/lib/compliance/catalogs/iso27001.d.ts +3 -0
- package/lib/compliance/catalogs/iso27001.js +39 -0
- package/lib/compliance/catalogs/nzism.d.ts +3 -0
- package/lib/compliance/catalogs/nzism.js +31 -0
- package/lib/compliance/catalogs/owasp.d.ts +3 -0
- package/lib/compliance/catalogs/owasp.js +37 -0
- package/lib/compliance/catalogs/privacyAct.d.ts +3 -0
- package/lib/compliance/catalogs/privacyAct.js +17 -0
- package/lib/compliance/catalogs/sbs.d.ts +3 -0
- package/lib/compliance/catalogs/sbs.js +61 -0
- package/lib/compliance/catalogs/soc2.d.ts +3 -0
- package/lib/compliance/catalogs/soc2.js +42 -0
- package/lib/compliance/mapping.d.ts +2 -0
- package/lib/compliance/mapping.js +111 -0
- package/lib/compliance/resolve.d.ts +12 -0
- package/lib/compliance/resolve.js +49 -0
- package/lib/compliance/types.d.ts +13 -0
- package/lib/compliance/types.js +2 -0
- 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/CheckMeta.d.ts +9 -0
- package/lib/findings/CheckMeta.js +67 -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/AuditRenderer.d.ts +2 -0
- package/lib/renderers/ClientReportRenderer.d.ts +29 -0
- package/lib/renderers/ClientReportRenderer.js +205 -0
- 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 -60
- package/lib/renderers/MarkdownRenderer.js +34 -1
- package/lib/renderers/html-utils.d.ts +2 -0
- package/lib/renderers/html-utils.js +8 -0
- package/lib/report/ComplianceMatrix.d.ts +19 -0
- package/lib/report/ComplianceMatrix.js +47 -0
- package/lib/report/ExecutivePriorities.d.ts +8 -0
- package/lib/report/ExecutivePriorities.js +22 -0
- package/lib/report/RemediationRoadmap.d.ts +9 -0
- package/lib/report/RemediationRoadmap.js +18 -0
- package/lib/report/branding.d.ts +18 -0
- package/lib/report/branding.js +19 -0
- package/lib/report/fonts.d.ts +2 -0
- package/lib/report/fonts.js +22 -0
- package/package.json +4 -3
- package/src/assets/fonts/dm-sans-italic-latin.woff2 +0 -0
- package/src/assets/fonts/dm-sans-normal-latin.woff2 +0 -0
- package/src/assets/fonts/dm-serif-display-italic-latin.woff2 +0 -0
- package/src/assets/fonts/dm-serif-display-normal-latin.woff2 +0 -0
- package/config/queries/soql.json +0 -24
- package/config/queries/tooling.json +0 -28
- package/config/scoring.json +0 -17
|
@@ -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
|
}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import type { AuditContext } from '../../context/AuditContext.js';
|
|
2
|
+
import type { SecurityCheck, CheckResult } from '../SecurityCheck.js';
|
|
3
|
+
export declare class CertificateExpiryCheck implements SecurityCheck {
|
|
4
|
+
readonly id = "certificate-expiry";
|
|
5
|
+
readonly name = "Certificate Expiry";
|
|
6
|
+
readonly category = "Authentication";
|
|
7
|
+
readonly description = "Checks installed certificates for impending expiry (30 / 90 / 180 day thresholds)";
|
|
8
|
+
run(ctx: AuditContext): Promise<CheckResult>;
|
|
9
|
+
}
|
|
10
|
+
//# sourceMappingURL=CertificateExpiryCheck.d.ts.map
|
|
@@ -0,0 +1,123 @@
|
|
|
1
|
+
export class CertificateExpiryCheck {
|
|
2
|
+
id = 'certificate-expiry';
|
|
3
|
+
name = 'Certificate Expiry';
|
|
4
|
+
category = 'Authentication';
|
|
5
|
+
description = 'Checks installed certificates for impending expiry (30 / 90 / 180 day thresholds)';
|
|
6
|
+
async run(ctx) {
|
|
7
|
+
const findings = [];
|
|
8
|
+
const baseUrl = ctx.orgInfo.instanceUrl;
|
|
9
|
+
const setupUrl = `${baseUrl}/lightning/setup/CertificatesAndKeys/home`;
|
|
10
|
+
const now = Date.now();
|
|
11
|
+
let certs = [];
|
|
12
|
+
try {
|
|
13
|
+
certs = await ctx.tooling.query(`SELECT Id, MasterLabel, DeveloperName, ExpirationDate FROM Certificate`);
|
|
14
|
+
}
|
|
15
|
+
catch {
|
|
16
|
+
findings.push({
|
|
17
|
+
id: 'certificate-inaccessible',
|
|
18
|
+
category: this.category,
|
|
19
|
+
riskLevel: 'INFO',
|
|
20
|
+
inconclusive: true,
|
|
21
|
+
title: 'Certificate inventory could not be retrieved',
|
|
22
|
+
detail: 'The Tooling API Certificate object was not accessible. This may indicate insufficient permissions or the org edition does not support certificate management via API.',
|
|
23
|
+
remediation: 'Review installed certificates manually in Setup → Security → Certificate and Key Management.',
|
|
24
|
+
affectedItems: [{ label: 'Certificate and Key Management', url: setupUrl }],
|
|
25
|
+
});
|
|
26
|
+
return { findings };
|
|
27
|
+
}
|
|
28
|
+
if (certs.length === 0) {
|
|
29
|
+
findings.push({
|
|
30
|
+
id: 'certificate-none',
|
|
31
|
+
category: this.category,
|
|
32
|
+
riskLevel: 'INFO',
|
|
33
|
+
title: 'No certificates found in this org',
|
|
34
|
+
detail: 'No Certificate records were found via the Tooling API. If this org uses client certificates or JWT-based integrations, verify certificates are configured correctly.',
|
|
35
|
+
remediation: 'If certificates are required for integrations or identity providers, configure them in Setup → Security → Certificate and Key Management.',
|
|
36
|
+
});
|
|
37
|
+
return { findings };
|
|
38
|
+
}
|
|
39
|
+
const critical = [];
|
|
40
|
+
const soon = [];
|
|
41
|
+
const medium = [];
|
|
42
|
+
for (const cert of certs) {
|
|
43
|
+
if (!cert.ExpirationDate)
|
|
44
|
+
continue;
|
|
45
|
+
const msUntilExpiry = new Date(cert.ExpirationDate).getTime() - now;
|
|
46
|
+
const daysUntilExpiry = Math.ceil(msUntilExpiry / 86_400_000);
|
|
47
|
+
if (daysUntilExpiry <= 30) {
|
|
48
|
+
critical.push(cert);
|
|
49
|
+
}
|
|
50
|
+
else if (daysUntilExpiry <= 90) {
|
|
51
|
+
soon.push(cert);
|
|
52
|
+
}
|
|
53
|
+
else if (daysUntilExpiry <= 180) {
|
|
54
|
+
medium.push(cert);
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
function certNote(cert) {
|
|
58
|
+
if (!cert.ExpirationDate)
|
|
59
|
+
return 'no expiry date';
|
|
60
|
+
const daysLeft = Math.ceil((new Date(cert.ExpirationDate).getTime() - now) / 86_400_000);
|
|
61
|
+
const expiryStr = new Date(cert.ExpirationDate).toISOString().split('T')[0];
|
|
62
|
+
return `${daysLeft} day(s) until expiry — expires ${expiryStr}`;
|
|
63
|
+
}
|
|
64
|
+
if (critical.length > 0) {
|
|
65
|
+
findings.push({
|
|
66
|
+
id: 'certificate-expiring-critical',
|
|
67
|
+
category: this.category,
|
|
68
|
+
riskLevel: 'CRITICAL',
|
|
69
|
+
title: `${critical.length} certificate(s) expire within 30 days`,
|
|
70
|
+
detail: 'Expired certificates break all integrations, SSO logins, and JWT-based authentication that depend on them. Certificates expiring within 30 days require immediate replacement to avoid service disruption.',
|
|
71
|
+
remediation: 'Renew or replace expiring certificates immediately. Update all integrations and connected apps that reference these certificates. Test authentication flows after replacement.',
|
|
72
|
+
affectedItems: critical.map((c) => ({
|
|
73
|
+
label: c.MasterLabel,
|
|
74
|
+
url: setupUrl,
|
|
75
|
+
note: certNote(c),
|
|
76
|
+
})),
|
|
77
|
+
});
|
|
78
|
+
}
|
|
79
|
+
if (soon.length > 0) {
|
|
80
|
+
findings.push({
|
|
81
|
+
id: 'certificate-expiring-soon',
|
|
82
|
+
category: this.category,
|
|
83
|
+
riskLevel: 'HIGH',
|
|
84
|
+
title: `${soon.length} certificate(s) expire within 90 days`,
|
|
85
|
+
detail: 'Certificates expiring within 90 days should be renewed proactively. Waiting until expiry causes integration outages and may require emergency change-management processes.',
|
|
86
|
+
remediation: 'Schedule certificate renewal within the next 30 days. Coordinate with integration owners to update dependent systems before the certificate expires.',
|
|
87
|
+
affectedItems: soon.map((c) => ({
|
|
88
|
+
label: c.MasterLabel,
|
|
89
|
+
url: setupUrl,
|
|
90
|
+
note: certNote(c),
|
|
91
|
+
})),
|
|
92
|
+
});
|
|
93
|
+
}
|
|
94
|
+
if (medium.length > 0) {
|
|
95
|
+
findings.push({
|
|
96
|
+
id: 'certificate-expiring-medium',
|
|
97
|
+
category: this.category,
|
|
98
|
+
riskLevel: 'MEDIUM',
|
|
99
|
+
title: `${medium.length} certificate(s) expire within 180 days`,
|
|
100
|
+
detail: 'Certificates expiring within 180 days should be tracked and scheduled for renewal. Early planning avoids emergency renewals and ensures dependent integrations are updated in time.',
|
|
101
|
+
remediation: 'Add certificate renewal to your security maintenance calendar. Identify all integrations that depend on these certificates so they can be updated when renewed.',
|
|
102
|
+
affectedItems: medium.map((c) => ({
|
|
103
|
+
label: c.MasterLabel,
|
|
104
|
+
url: setupUrl,
|
|
105
|
+
note: certNote(c),
|
|
106
|
+
})),
|
|
107
|
+
});
|
|
108
|
+
}
|
|
109
|
+
if (critical.length === 0 && soon.length === 0 && medium.length === 0) {
|
|
110
|
+
findings.push({
|
|
111
|
+
id: 'certificate-ok',
|
|
112
|
+
category: this.category,
|
|
113
|
+
riskLevel: 'LOW',
|
|
114
|
+
passed: true,
|
|
115
|
+
title: `All ${certs.length} certificate(s) are healthy (none expire within 180 days)`,
|
|
116
|
+
detail: `All installed certificates have more than 180 days until expiry. No immediate certificate rotation is required.`,
|
|
117
|
+
remediation: 'Continue monitoring certificate expiry dates. Re-run this audit as certificates approach the 180-day threshold.',
|
|
118
|
+
});
|
|
119
|
+
}
|
|
120
|
+
return { findings };
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
//# sourceMappingURL=CertificateExpiryCheck.js.map
|
|
@@ -4,7 +4,8 @@ export declare class CodeSecurityCheck implements SecurityCheck {
|
|
|
4
4
|
readonly id = "code-security";
|
|
5
5
|
readonly name = "Code Security and Coverage";
|
|
6
6
|
readonly category = "Code Security";
|
|
7
|
-
readonly description = "Reports org-wide Apex test coverage
|
|
7
|
+
readonly description = "Reports org-wide Apex test coverage, class/trigger counts, and flags potential SOQL injection patterns";
|
|
8
|
+
readonly dependsOnCache: readonly ["apexBodies"];
|
|
8
9
|
run(ctx: AuditContext): Promise<CheckResult>;
|
|
9
10
|
}
|
|
10
11
|
//# sourceMappingURL=CodeSecurityCheck.d.ts.map
|
|
@@ -1,17 +1,27 @@
|
|
|
1
|
+
// SBS-CODE-002: dynamic SOQL with string concatenation is the primary SOQL injection vector.
|
|
2
|
+
// Pattern: Database.query( or Database.countQuery( followed by a + operator before the closing paren/semicolon.
|
|
3
|
+
const DYNAMIC_SOQL_INJECTION = /Database\.(query|countQuery)\s*\([^;)]*\+[^;)]*[);]/gi;
|
|
4
|
+
// Also catch String.escapeSingleQuotes absence heuristic: raw variable use inside query strings
|
|
5
|
+
const UNSAFE_DYNAMIC_QUERY = /\[\s*SELECT\b[^\]]*:(?!'\s*\])[^,\]]+[+][^\]]*\]/gi;
|
|
1
6
|
export class CodeSecurityCheck {
|
|
2
7
|
id = 'code-security';
|
|
3
8
|
name = 'Code Security and Coverage';
|
|
4
9
|
category = 'Code Security';
|
|
5
|
-
description = 'Reports org-wide Apex test coverage
|
|
10
|
+
description = 'Reports org-wide Apex test coverage, class/trigger counts, and flags potential SOQL injection patterns';
|
|
11
|
+
// Reuse Apex bodies cached by HardcodedCredentialsCheck — no extra API call needed
|
|
12
|
+
dependsOnCache = ['apexBodies'];
|
|
6
13
|
async run(ctx) {
|
|
7
14
|
const findings = [];
|
|
8
|
-
//
|
|
9
|
-
|
|
15
|
+
// Fire all three independent Tooling queries in parallel.
|
|
16
|
+
// COUNT(Id) expr0 puts the result in records[0].expr0; COUNT() without a field
|
|
17
|
+
// puts it in totalSize which is not in the typed return value.
|
|
18
|
+
const [classCountResults, triggerCountResults, coverageResults] = await Promise.all([
|
|
19
|
+
ctx.tooling.query('SELECT COUNT(Id) expr0 FROM ApexClass WHERE NamespacePrefix = null'),
|
|
20
|
+
ctx.tooling.query('SELECT COUNT(Id) expr0 FROM ApexTrigger WHERE NamespacePrefix = null'),
|
|
21
|
+
ctx.tooling.query('SELECT PercentCovered FROM ApexOrgWideCoverage'),
|
|
22
|
+
]);
|
|
10
23
|
const classCount = classCountResults[0]?.expr0 ?? 0;
|
|
11
|
-
const triggerCountResults = await ctx.tooling.query('SELECT COUNT() FROM ApexTrigger WHERE NamespacePrefix = null');
|
|
12
24
|
const triggerCount = triggerCountResults[0]?.expr0 ?? 0;
|
|
13
|
-
// Query coverage
|
|
14
|
-
const coverageResults = await ctx.tooling.query('SELECT PercentCovered FROM ApexOrgWideCoverage');
|
|
15
25
|
if (coverageResults.length > 0) {
|
|
16
26
|
const coverage = coverageResults[0].PercentCovered;
|
|
17
27
|
let riskLevel = 'LOW';
|
|
@@ -40,6 +50,36 @@ export class CodeSecurityCheck {
|
|
|
40
50
|
remediation: 'Run Apex tests in this org to generate coverage data. Ensure all Apex code has adequate test coverage.',
|
|
41
51
|
});
|
|
42
52
|
}
|
|
53
|
+
// SBS-CODE-002: scan cached Apex bodies for potential SOQL injection patterns.
|
|
54
|
+
// Bodies are already fetched by HardcodedCredentialsCheck — no additional API call.
|
|
55
|
+
// apexBodies is pre-filtered by HardcodedCredentialsCheck to exclude test classes
|
|
56
|
+
const apexBodies = ctx.cache.apexBodies ?? [];
|
|
57
|
+
const soqlInjectionClasses = [];
|
|
58
|
+
for (const { name, body } of apexBodies) {
|
|
59
|
+
if (!body)
|
|
60
|
+
continue;
|
|
61
|
+
DYNAMIC_SOQL_INJECTION.lastIndex = 0;
|
|
62
|
+
UNSAFE_DYNAMIC_QUERY.lastIndex = 0;
|
|
63
|
+
if (DYNAMIC_SOQL_INJECTION.test(body) || UNSAFE_DYNAMIC_QUERY.test(body)) {
|
|
64
|
+
soqlInjectionClasses.push(name);
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
if (soqlInjectionClasses.length > 0) {
|
|
68
|
+
const apexClassesUrl = `${ctx.orgInfo.instanceUrl}/lightning/setup/ApexClasses/home`;
|
|
69
|
+
findings.push({
|
|
70
|
+
id: 'soql-injection-risk',
|
|
71
|
+
category: this.category,
|
|
72
|
+
riskLevel: 'HIGH',
|
|
73
|
+
title: `${soqlInjectionClasses.length} Apex class(es) contain potential SOQL injection patterns`,
|
|
74
|
+
detail: 'Dynamic SOQL built with string concatenation (Database.query(... + variable ...)) is vulnerable to SOQL injection if the variable originates from user input. SBS-CODE-002 requires pre-merge static analysis to catch these patterns.',
|
|
75
|
+
remediation: 'Replace string concatenation in dynamic SOQL with bind variables (:variable syntax). For unavoidable dynamic clauses, sanitize all user-supplied values with String.escapeSingleQuotes().',
|
|
76
|
+
affectedItems: soqlInjectionClasses.map((name) => ({
|
|
77
|
+
label: name,
|
|
78
|
+
url: apexClassesUrl,
|
|
79
|
+
note: 'Review Database.query() / Database.countQuery() calls for user-controlled input',
|
|
80
|
+
})),
|
|
81
|
+
});
|
|
82
|
+
}
|
|
43
83
|
return {
|
|
44
84
|
findings,
|
|
45
85
|
metrics: {
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import type { AuditContext } from '../../context/AuditContext.js';
|
|
2
|
+
import type { SecurityCheck, CheckResult } from '../SecurityCheck.js';
|
|
3
|
+
export declare class ConnectedAppInactivityCheck implements SecurityCheck {
|
|
4
|
+
readonly id = "connected-app-inactivity";
|
|
5
|
+
readonly name = "Inactive Connected Apps";
|
|
6
|
+
readonly category = "App Security";
|
|
7
|
+
readonly description = "Flags connected apps with no OAuth logins in the past 90 days \u2014 stale apps are unused attack surface";
|
|
8
|
+
readonly dependsOnCache: readonly ["connectedAppNames"];
|
|
9
|
+
run(ctx: AuditContext): Promise<CheckResult>;
|
|
10
|
+
}
|
|
11
|
+
//# sourceMappingURL=ConnectedAppInactivityCheck.d.ts.map
|
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
export class ConnectedAppInactivityCheck {
|
|
2
|
+
id = 'connected-app-inactivity';
|
|
3
|
+
name = 'Inactive Connected Apps';
|
|
4
|
+
category = 'App Security';
|
|
5
|
+
description = 'Flags connected apps with no OAuth logins in the past 90 days — stale apps are unused attack surface';
|
|
6
|
+
dependsOnCache = ['connectedAppNames'];
|
|
7
|
+
async run(ctx) {
|
|
8
|
+
const findings = [];
|
|
9
|
+
const baseUrl = ctx.orgInfo.instanceUrl;
|
|
10
|
+
const setupUrl = `${baseUrl}/lightning/setup/ConnectedApplication/home`;
|
|
11
|
+
const connectedAppNames = ctx.cache.connectedAppNames ?? [];
|
|
12
|
+
if (connectedAppNames.length === 0) {
|
|
13
|
+
findings.push({
|
|
14
|
+
id: 'connected-app-inactivity-none',
|
|
15
|
+
category: this.category,
|
|
16
|
+
riskLevel: 'LOW',
|
|
17
|
+
passed: true,
|
|
18
|
+
title: 'No connected apps to check for inactivity',
|
|
19
|
+
detail: 'No connected apps were found in the org. No inactivity check is needed.',
|
|
20
|
+
remediation: 'Continue monitoring as new connected apps are added.',
|
|
21
|
+
});
|
|
22
|
+
return { findings };
|
|
23
|
+
}
|
|
24
|
+
// Query OAuth login history for the last 90 days, grouped by application name.
|
|
25
|
+
// Apps NOT appearing in this result have had zero OAuth logins in 90 days.
|
|
26
|
+
let activeAppNames = new Set();
|
|
27
|
+
try {
|
|
28
|
+
const result = await ctx.soql.query(`SELECT Application, COUNT(Id) loginCount
|
|
29
|
+
FROM LoginHistory
|
|
30
|
+
WHERE LoginTime > LAST_N_DAYS:90
|
|
31
|
+
AND LoginType LIKE 'OAuth%'
|
|
32
|
+
GROUP BY Application`);
|
|
33
|
+
for (const r of result.records) {
|
|
34
|
+
if (r.Application)
|
|
35
|
+
activeAppNames.add(r.Application.toLowerCase());
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
catch {
|
|
39
|
+
findings.push({
|
|
40
|
+
id: 'connected-app-inactivity-inconclusive',
|
|
41
|
+
category: this.category,
|
|
42
|
+
riskLevel: 'INFO',
|
|
43
|
+
inconclusive: true,
|
|
44
|
+
title: 'Connected app activity could not be determined — LoginHistory not accessible',
|
|
45
|
+
detail: 'LoginHistory was not accessible. Connected app inactivity cannot be computed without login history.',
|
|
46
|
+
remediation: 'Grant LoginHistory read access to the audit user.',
|
|
47
|
+
});
|
|
48
|
+
return { findings };
|
|
49
|
+
}
|
|
50
|
+
// Case-insensitive match between ConnectedApp names and LoginHistory Application names
|
|
51
|
+
const inactiveApps = connectedAppNames.filter((name) => !activeAppNames.has(name.toLowerCase()));
|
|
52
|
+
const activeApps = connectedAppNames.filter((name) => activeAppNames.has(name.toLowerCase()));
|
|
53
|
+
if (inactiveApps.length > 0) {
|
|
54
|
+
findings.push({
|
|
55
|
+
id: 'connected-app-inactive',
|
|
56
|
+
category: this.category,
|
|
57
|
+
riskLevel: inactiveApps.length > 5 ? 'MEDIUM' : 'LOW',
|
|
58
|
+
title: `${inactiveApps.length} connected app(s) have had no OAuth logins in 90 days`,
|
|
59
|
+
detail: `${inactiveApps.length} of ${connectedAppNames.length} connected apps show no OAuth login activity in the past 90 days. Inactive apps still hold valid OAuth credentials and expand the attack surface — a compromised or leaked client secret for an inactive app can be used to obtain access tokens without triggering activity alerts.`,
|
|
60
|
+
remediation: 'Review each inactive connected app. If the integration is no longer in use, delete or disable the app to revoke its OAuth credentials. Ensure active integrations are documented with an owner.',
|
|
61
|
+
affectedItems: inactiveApps.map((name) => ({
|
|
62
|
+
label: name,
|
|
63
|
+
url: setupUrl,
|
|
64
|
+
note: 'No OAuth logins in 90 days — verify if still needed and delete if not',
|
|
65
|
+
})),
|
|
66
|
+
});
|
|
67
|
+
}
|
|
68
|
+
if (activeApps.length > 0) {
|
|
69
|
+
findings.push({
|
|
70
|
+
id: 'connected-app-active',
|
|
71
|
+
category: this.category,
|
|
72
|
+
riskLevel: 'INFO',
|
|
73
|
+
title: `${activeApps.length} connected app(s) have active OAuth logins`,
|
|
74
|
+
detail: `${activeApps.length} connected app(s) show recent OAuth login activity in the past 90 days.`,
|
|
75
|
+
remediation: 'Periodically review active connected apps to ensure all have documented owners and business justification.',
|
|
76
|
+
affectedItems: activeApps.map((name) => ({
|
|
77
|
+
label: name,
|
|
78
|
+
url: setupUrl,
|
|
79
|
+
note: 'Active — verify documented owner and justification',
|
|
80
|
+
})),
|
|
81
|
+
});
|
|
82
|
+
}
|
|
83
|
+
return { findings };
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
//# sourceMappingURL=ConnectedAppInactivityCheck.js.map
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import type { AuditContext } from '../../context/AuditContext.js';
|
|
2
|
+
import type { SecurityCheck, CheckResult } from '../SecurityCheck.js';
|
|
3
|
+
export declare class ConnectedAppScopeCheck implements SecurityCheck {
|
|
4
|
+
readonly id = "connected-app-scope";
|
|
5
|
+
readonly name = "Connected App OAuth Scopes & Token Policy";
|
|
6
|
+
readonly category = "App Security";
|
|
7
|
+
readonly description = "Flags connected apps granting Full OAuth scope or using infinite refresh token policies \u2014 both expand the blast radius of a compromised token";
|
|
8
|
+
run(ctx: AuditContext): Promise<CheckResult>;
|
|
9
|
+
}
|
|
10
|
+
//# sourceMappingURL=ConnectedAppScopeCheck.d.ts.map
|
|
@@ -0,0 +1,125 @@
|
|
|
1
|
+
// Scopes that grant effectively unlimited access as the authorising user.
|
|
2
|
+
const OVERLY_BROAD_SCOPES = new Set(['Full', 'full']);
|
|
3
|
+
// Refresh token policy values that indicate no expiry.
|
|
4
|
+
// refreshTokenValidityPeriod = -1 means "use org default" (often hours or longer).
|
|
5
|
+
// oauthPolicy.refreshTokenPolicy = 'infinite' means no expiry at all.
|
|
6
|
+
function isInfiniteRefreshToken(app) {
|
|
7
|
+
const validityPeriod = app.Metadata?.oauthConfig?.refreshTokenValidityPeriod;
|
|
8
|
+
const policy = app.Metadata?.oauthPolicy?.refreshTokenPolicy;
|
|
9
|
+
return validityPeriod === -1 || policy === 'infinite';
|
|
10
|
+
}
|
|
11
|
+
export class ConnectedAppScopeCheck {
|
|
12
|
+
id = 'connected-app-scope';
|
|
13
|
+
name = 'Connected App OAuth Scopes & Token Policy';
|
|
14
|
+
category = 'App Security';
|
|
15
|
+
description = 'Flags connected apps granting Full OAuth scope or using infinite refresh token policies — both expand the blast radius of a compromised token';
|
|
16
|
+
async run(ctx) {
|
|
17
|
+
const findings = [];
|
|
18
|
+
const setupUrl = `${ctx.orgInfo.instanceUrl}/lightning/setup/ConnectedApplication/home`;
|
|
19
|
+
let apps = [];
|
|
20
|
+
try {
|
|
21
|
+
apps = await ctx.tooling.query('SELECT Id, Name, Metadata FROM ConnectedApplication');
|
|
22
|
+
}
|
|
23
|
+
catch {
|
|
24
|
+
findings.push({
|
|
25
|
+
id: 'connected-app-scope-inconclusive',
|
|
26
|
+
category: this.category,
|
|
27
|
+
riskLevel: 'INFO',
|
|
28
|
+
inconclusive: true,
|
|
29
|
+
title: 'Connected app OAuth scope check could not be completed',
|
|
30
|
+
detail: 'ConnectedApplication Metadata was not accessible via Tooling API. This may indicate a permissions issue on the audit user.',
|
|
31
|
+
remediation: 'Grant the audit user the "Customize Application" permission to enable Tooling API access to connected app metadata.',
|
|
32
|
+
});
|
|
33
|
+
return { findings };
|
|
34
|
+
}
|
|
35
|
+
if (apps.length === 0) {
|
|
36
|
+
findings.push({
|
|
37
|
+
id: 'connected-app-scope-none',
|
|
38
|
+
category: this.category,
|
|
39
|
+
riskLevel: 'LOW',
|
|
40
|
+
passed: true,
|
|
41
|
+
title: 'No connected apps found',
|
|
42
|
+
detail: 'No connected apps exist in this org.',
|
|
43
|
+
remediation: 'Continue monitoring as new connected apps are added.',
|
|
44
|
+
});
|
|
45
|
+
return { findings };
|
|
46
|
+
}
|
|
47
|
+
const fullScopeApps = [];
|
|
48
|
+
const infiniteTokenApps = [];
|
|
49
|
+
for (const app of apps) {
|
|
50
|
+
const scopes = app.Metadata?.oauthConfig?.scopes ?? [];
|
|
51
|
+
if (scopes.some((s) => OVERLY_BROAD_SCOPES.has(s))) {
|
|
52
|
+
fullScopeApps.push(app);
|
|
53
|
+
}
|
|
54
|
+
// Only flag infinite refresh tokens if the app has at least one scope
|
|
55
|
+
// (apps with no scopes are non-OAuth apps and don't issue tokens)
|
|
56
|
+
if (scopes.length > 0 && isInfiniteRefreshToken(app)) {
|
|
57
|
+
infiniteTokenApps.push(app);
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
if (fullScopeApps.length > 0) {
|
|
61
|
+
findings.push({
|
|
62
|
+
id: 'connected-app-full-scope',
|
|
63
|
+
category: this.category,
|
|
64
|
+
riskLevel: 'HIGH',
|
|
65
|
+
title: `${fullScopeApps.length} connected app(s) grant the "Full" OAuth scope`,
|
|
66
|
+
detail: 'The Full OAuth scope gives a connected app the same access rights as the authorising user — including Modify All Data if the user is an admin. A stolen access or refresh token from a Full-scope app can be used to read, write, and delete any record the user could access. Full scope is almost never necessary; specific scopes (Api, Web, CustomPermissions) should be used instead.',
|
|
67
|
+
remediation: 'Edit each connected app in Setup → Connected Apps → OAuth Policies and replace "Full" scope with the minimum scopes the integration actually requires. Common replacements: "Api" for REST API access, "Web" for web-based flows, "OpenID" + "Profile" for identity only. Rotating client secrets after scope changes is also recommended.',
|
|
68
|
+
affectedItems: fullScopeApps.map((app) => ({
|
|
69
|
+
label: app.Name,
|
|
70
|
+
url: setupUrl,
|
|
71
|
+
note: `Scopes: ${(app.Metadata?.oauthConfig?.scopes ?? []).join(', ')}`,
|
|
72
|
+
})),
|
|
73
|
+
});
|
|
74
|
+
}
|
|
75
|
+
if (infiniteTokenApps.length > 0) {
|
|
76
|
+
// Exclude apps already flagged for Full scope from the infinite-token list to avoid double-counting
|
|
77
|
+
const infiniteOnlyApps = infiniteTokenApps.filter((app) => !fullScopeApps.some((fa) => fa.Id === app.Id));
|
|
78
|
+
if (infiniteOnlyApps.length > 0) {
|
|
79
|
+
findings.push({
|
|
80
|
+
id: 'connected-app-infinite-refresh-token',
|
|
81
|
+
category: this.category,
|
|
82
|
+
riskLevel: 'MEDIUM',
|
|
83
|
+
title: `${infiniteOnlyApps.length} connected app(s) issue refresh tokens with no expiry`,
|
|
84
|
+
detail: 'Connected apps with an infinite or org-default refresh token policy (refreshTokenValidityPeriod = -1 or policy = "infinite") issue tokens that never expire unless manually revoked. A stolen refresh token provides indefinite access to the org as the authorising user. SBS-DEP-006 requires access token lifetimes of 15 minutes or less; refresh token lifetimes should also be bounded.',
|
|
85
|
+
remediation: 'Set an explicit refresh token validity period in Setup → Connected Apps → OAuth Policies. For machine-to-machine integrations, consider using the Client Credentials flow (which does not issue refresh tokens) instead of the Authorization Code flow. For user-facing apps, a 90-day refresh token limit is a reasonable starting point.',
|
|
86
|
+
affectedItems: infiniteOnlyApps.map((app) => ({
|
|
87
|
+
label: app.Name,
|
|
88
|
+
url: setupUrl,
|
|
89
|
+
note: `RefreshTokenPolicy: ${app.Metadata?.oauthPolicy?.refreshTokenPolicy ?? 'unset'}, ValidityPeriod: ${app.Metadata?.oauthConfig?.refreshTokenValidityPeriod ?? 'unset'}`,
|
|
90
|
+
})),
|
|
91
|
+
});
|
|
92
|
+
}
|
|
93
|
+
// Also flag Full-scope apps that ALSO have infinite refresh tokens as a compound risk note
|
|
94
|
+
const fullAndInfinite = fullScopeApps.filter((app) => infiniteTokenApps.some((ia) => ia.Id === app.Id));
|
|
95
|
+
if (fullAndInfinite.length > 0) {
|
|
96
|
+
findings.push({
|
|
97
|
+
id: 'connected-app-full-scope-infinite-token',
|
|
98
|
+
category: this.category,
|
|
99
|
+
riskLevel: 'CRITICAL',
|
|
100
|
+
title: `${fullAndInfinite.length} connected app(s) combine Full scope with an infinite refresh token — stolen token = permanent full access`,
|
|
101
|
+
detail: 'These apps issue never-expiring tokens that grant complete access to the org as the authorising user. A single leaked token is equivalent to a permanent credential with admin-level reach if the user is an admin. This is the highest-risk connected app configuration.',
|
|
102
|
+
remediation: 'Immediately restrict scopes to the minimum required and set an explicit refresh token expiry. If Full scope cannot be removed, at minimum set a refresh token validity period of 90 days or less and enable refresh token rotation.',
|
|
103
|
+
affectedItems: fullAndInfinite.map((app) => ({
|
|
104
|
+
label: app.Name,
|
|
105
|
+
url: setupUrl,
|
|
106
|
+
note: `Full scope + infinite refresh token — highest risk combination`,
|
|
107
|
+
})),
|
|
108
|
+
});
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
if (fullScopeApps.length === 0 && infiniteTokenApps.length === 0) {
|
|
112
|
+
findings.push({
|
|
113
|
+
id: 'connected-app-scope-ok',
|
|
114
|
+
category: this.category,
|
|
115
|
+
riskLevel: 'LOW',
|
|
116
|
+
passed: true,
|
|
117
|
+
title: 'No connected apps grant Full scope or use infinite refresh tokens',
|
|
118
|
+
detail: `All ${apps.length} connected app(s) use scoped OAuth permissions and bounded token lifetimes.`,
|
|
119
|
+
remediation: 'Periodically review connected app OAuth scopes and token policies as new apps are added.',
|
|
120
|
+
});
|
|
121
|
+
}
|
|
122
|
+
return { findings };
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
//# sourceMappingURL=ConnectedAppScopeCheck.js.map
|
|
@@ -5,6 +5,7 @@ export declare class ConnectedAppsCheck implements SecurityCheck {
|
|
|
5
5
|
readonly name = "Connected Apps";
|
|
6
6
|
readonly category = "App Security";
|
|
7
7
|
readonly description = "Flags connected apps not restricted to admin-approved users";
|
|
8
|
+
readonly populatesCache: readonly ["connectedAppNames"];
|
|
8
9
|
run(ctx: AuditContext): Promise<CheckResult>;
|
|
9
10
|
}
|
|
10
11
|
//# sourceMappingURL=ConnectedAppsCheck.d.ts.map
|