@cclabsnz/sf-audit 1.0.0 → 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 +35 -2
- package/package.json +12 -3
|
@@ -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
|
|
@@ -3,13 +3,16 @@ export class ConnectedAppsCheck {
|
|
|
3
3
|
name = 'Connected Apps';
|
|
4
4
|
category = 'App Security';
|
|
5
5
|
description = 'Flags connected apps not restricted to admin-approved users';
|
|
6
|
+
populatesCache = ['connectedAppNames'];
|
|
6
7
|
async run(ctx) {
|
|
7
8
|
const findings = [];
|
|
8
9
|
const baseUrl = ctx.orgInfo.instanceUrl;
|
|
9
|
-
//
|
|
10
|
-
const connectedApps = await ctx.soql.queryAll(`SELECT Id, Name, OptionsAllowAdminApprovedUsersOnly
|
|
10
|
+
// Single query fetches both access-control and session-timeout fields — no N+1 calls needed.
|
|
11
|
+
const connectedApps = await ctx.soql.queryAll(`SELECT Id, Name, OptionsAllowAdminApprovedUsersOnly, SessionTimeout
|
|
11
12
|
FROM ConnectedApplication`);
|
|
12
13
|
const count = connectedApps.length;
|
|
14
|
+
// Cache app names for DeploymentIdentityCheck and SiemIntegrationCheck — no extra query
|
|
15
|
+
ctx.cache.connectedAppNames = connectedApps.map((a) => a.Name);
|
|
13
16
|
// Check for apps with unrestricted user access
|
|
14
17
|
const unrestrictedApps = connectedApps.filter((app) => !app.OptionsAllowAdminApprovedUsersOnly);
|
|
15
18
|
if (unrestrictedApps.length > 0) {
|
|
@@ -38,6 +41,38 @@ export class ConnectedAppsCheck {
|
|
|
38
41
|
remediation: 'Continue monitoring as new connected apps are added.',
|
|
39
42
|
});
|
|
40
43
|
}
|
|
44
|
+
// SBS-DEP-006: access token (session) timeout must be ≤ 15 minutes for CLI/integration apps.
|
|
45
|
+
// SessionTimeout = 0 means the app inherits the org-level session timeout (often 2–8 hours),
|
|
46
|
+
// which exceeds the 15-minute SBS requirement. Flag null/0 and values > 15 minutes.
|
|
47
|
+
const longSessionApps = connectedApps.filter((app) => app.SessionTimeout === null || app.SessionTimeout === 0 || app.SessionTimeout > 15);
|
|
48
|
+
if (longSessionApps.length > 0) {
|
|
49
|
+
findings.push({
|
|
50
|
+
id: 'connected-apps-long-session-timeout',
|
|
51
|
+
category: this.category,
|
|
52
|
+
riskLevel: 'MEDIUM',
|
|
53
|
+
title: `${longSessionApps.length} connected app(s) do not enforce a short session timeout (SBS-DEP-006: ≤ 15 min)`,
|
|
54
|
+
detail: 'SBS-DEP-006 requires connected apps used for CLI or CI/CD to enforce access token timeouts of 15 minutes or less. Apps set to "0" inherit the org session timeout (commonly 2–8 hours), leaving stolen tokens valid far longer than necessary.',
|
|
55
|
+
remediation: 'Set SessionTimeout to 15 minutes or less on each connected app in Setup → Connected Apps → OAuth Policies. For CLI tools, also configure a refresh token validity period of 90 days or less.',
|
|
56
|
+
affectedItems: longSessionApps.map((app) => ({
|
|
57
|
+
label: app.Name,
|
|
58
|
+
url: `${baseUrl}/${app.Id}`,
|
|
59
|
+
note: app.SessionTimeout === null || app.SessionTimeout === 0
|
|
60
|
+
? 'No explicit timeout — inherits org default (likely > 15 min)'
|
|
61
|
+
: `Session timeout: ${app.SessionTimeout} min — reduce to ≤ 15`,
|
|
62
|
+
})),
|
|
63
|
+
});
|
|
64
|
+
}
|
|
65
|
+
else if (count > 0) {
|
|
66
|
+
findings.push({
|
|
67
|
+
id: 'connected-apps-session-timeout-ok',
|
|
68
|
+
category: this.category,
|
|
69
|
+
riskLevel: 'LOW',
|
|
70
|
+
passed: true,
|
|
71
|
+
title: 'All connected apps enforce session timeouts of 15 minutes or less',
|
|
72
|
+
detail: `All ${count} connected app(s) have SessionTimeout ≤ 15 minutes, meeting the SBS-DEP-006 requirement.`,
|
|
73
|
+
remediation: 'Continue monitoring as new connected apps are added.',
|
|
74
|
+
});
|
|
75
|
+
}
|
|
41
76
|
return {
|
|
42
77
|
findings,
|
|
43
78
|
metrics: {
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import type { AuditContext } from '../../context/AuditContext.js';
|
|
2
|
+
import type { SecurityCheck, CheckResult } from '../SecurityCheck.js';
|
|
3
|
+
export declare class ContentLinksCheck implements SecurityCheck {
|
|
4
|
+
readonly id = "content-links";
|
|
5
|
+
readonly name = "Content Distribution Links";
|
|
6
|
+
readonly category = "File Security";
|
|
7
|
+
readonly description = "SBS-FILE-001/002/003: audits public content links for missing expiry, missing passwords, and stale records";
|
|
8
|
+
run(ctx: AuditContext): Promise<CheckResult>;
|
|
9
|
+
}
|
|
10
|
+
//# sourceMappingURL=ContentLinksCheck.d.ts.map
|