@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,59 @@
|
|
|
1
|
+
// src/commands/audit/history.ts
|
|
2
|
+
import * as fs from 'node:fs';
|
|
3
|
+
import * as path from 'node:path';
|
|
4
|
+
import { SfCommand, Flags } from '@salesforce/sf-plugins-core';
|
|
5
|
+
import { HistoryStore } from '../../history/HistoryStore.js';
|
|
6
|
+
import { HistoryRenderer } from '../../renderers/HistoryRenderer.js';
|
|
7
|
+
export default class AuditHistoryCommand extends SfCommand {
|
|
8
|
+
static summary = 'Show audit history for an org';
|
|
9
|
+
static description = 'Scans archived audit reports for the target org, prints a terminal table, and writes an HTML timeline.';
|
|
10
|
+
static examples = [
|
|
11
|
+
'<%= config.bin %> <%= command.id %> --target-org myOrg',
|
|
12
|
+
'<%= config.bin %> <%= command.id %> --target-org myOrg --reports-dir ./reports --limit 10',
|
|
13
|
+
];
|
|
14
|
+
static flags = {
|
|
15
|
+
'target-org': Flags.requiredOrg(),
|
|
16
|
+
'reports-dir': Flags.string({
|
|
17
|
+
summary: 'Directory containing archived report files. Defaults to ~/.sf/audit-history/{orgId}.',
|
|
18
|
+
helpValue: './reports',
|
|
19
|
+
}),
|
|
20
|
+
output: Flags.string({
|
|
21
|
+
char: 'o',
|
|
22
|
+
summary: 'Directory to write the HTML timeline. Defaults to current directory.',
|
|
23
|
+
default: '.',
|
|
24
|
+
}),
|
|
25
|
+
limit: Flags.integer({
|
|
26
|
+
summary: 'Maximum number of most-recent runs to include.',
|
|
27
|
+
helpValue: '20',
|
|
28
|
+
}),
|
|
29
|
+
};
|
|
30
|
+
async run() {
|
|
31
|
+
const { flags } = await this.parse(AuditHistoryCommand);
|
|
32
|
+
const orgId = flags['target-org'].getOrgId();
|
|
33
|
+
const store = new HistoryStore();
|
|
34
|
+
const reportsDir = flags['reports-dir'];
|
|
35
|
+
let results = store.list(orgId, reportsDir);
|
|
36
|
+
if (results.length < 2) {
|
|
37
|
+
if (results.length === 0) {
|
|
38
|
+
this.log(`No audit history found for org ${orgId}.`);
|
|
39
|
+
this.log(`Run 'sf audit security --target-org <alias>' to create the first report.`);
|
|
40
|
+
}
|
|
41
|
+
else {
|
|
42
|
+
this.log(`Only 1 audit run found for org ${orgId}. Run at least 2 audits to see trends.`);
|
|
43
|
+
}
|
|
44
|
+
return results;
|
|
45
|
+
}
|
|
46
|
+
if (flags.limit !== undefined) {
|
|
47
|
+
results = results.slice(-flags.limit);
|
|
48
|
+
}
|
|
49
|
+
const renderer = new HistoryRenderer();
|
|
50
|
+
this.log(renderer.renderTable(results));
|
|
51
|
+
const filename = `sf-audit-history-${orgId}-${Date.now()}.html`;
|
|
52
|
+
const outputPath = path.join(flags.output, filename);
|
|
53
|
+
fs.mkdirSync(flags.output, { recursive: true });
|
|
54
|
+
fs.writeFileSync(outputPath, renderer.renderHtml(results), 'utf-8');
|
|
55
|
+
this.log(`\nHistory report written: ${outputPath}`);
|
|
56
|
+
return results;
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
//# sourceMappingURL=history.js.map
|
|
@@ -1,8 +1,6 @@
|
|
|
1
1
|
import * as fs from 'node:fs';
|
|
2
2
|
import * as path from 'node:path';
|
|
3
|
-
import { fileURLToPath } from 'node:url';
|
|
4
3
|
import { SfCommand, Flags } from '@salesforce/sf-plugins-core';
|
|
5
|
-
import { QueryRegistry } from '../../queries/QueryRegistry.js';
|
|
6
4
|
import { CheckEngine } from '../../checks/CheckEngine.js';
|
|
7
5
|
import { CHECKS } from '../../checks/registry.js';
|
|
8
6
|
import { JsonRenderer } from '../../renderers/JsonRenderer.js';
|
|
@@ -10,6 +8,7 @@ import { HtmlRenderer } from '../../renderers/HtmlRenderer.js';
|
|
|
10
8
|
import { MarkdownRenderer } from '../../renderers/MarkdownRenderer.js';
|
|
11
9
|
import { buildAuditContext, resolveOrgInfo } from '../../lib/wire.js';
|
|
12
10
|
import { loadScoringConfig } from '../../findings/loadScoringConfig.js';
|
|
11
|
+
import { HistoryStore } from '../../history/HistoryStore.js';
|
|
13
12
|
const RENDERERS = {
|
|
14
13
|
html: new HtmlRenderer(),
|
|
15
14
|
md: new MarkdownRenderer(),
|
|
@@ -51,11 +50,8 @@ export default class SecurityAuditCommand extends SfCommand {
|
|
|
51
50
|
async run() {
|
|
52
51
|
const { flags } = await this.parse(SecurityAuditCommand);
|
|
53
52
|
const conn = flags['target-org'].getConnection('62.0');
|
|
54
|
-
// Resolve plugin root from compiled file location (lib/commands/audit/security.js → 3 levels up)
|
|
55
|
-
const pluginRoot = path.resolve(path.dirname(fileURLToPath(import.meta.url)), '../../..');
|
|
56
|
-
const queries = QueryRegistry.load(pluginRoot);
|
|
57
53
|
const orgInfo = await resolveOrgInfo(conn);
|
|
58
|
-
const ctx = buildAuditContext(conn,
|
|
54
|
+
const ctx = buildAuditContext(conn, orgInfo);
|
|
59
55
|
const checksToRun = flags.checks
|
|
60
56
|
? (() => {
|
|
61
57
|
const ids = new Set(flags.checks.split(',').map((s) => s.trim()));
|
|
@@ -76,6 +72,7 @@ export default class SecurityAuditCommand extends SfCommand {
|
|
|
76
72
|
this.log(`[${String(current).padStart(2)}/${total}] ${checkName}`);
|
|
77
73
|
});
|
|
78
74
|
const formats = flags.format.split(',').map((f) => f.trim());
|
|
75
|
+
fs.mkdirSync(flags.output, { recursive: true });
|
|
79
76
|
for (const format of formats) {
|
|
80
77
|
const renderer = RENDERERS[format];
|
|
81
78
|
if (!renderer) {
|
|
@@ -88,6 +85,9 @@ export default class SecurityAuditCommand extends SfCommand {
|
|
|
88
85
|
fs.writeFileSync(outputPath, output, 'utf-8');
|
|
89
86
|
this.log(`\nReport written: ${outputPath}`);
|
|
90
87
|
}
|
|
88
|
+
// Auto-archive: silently save a copy for history tracking
|
|
89
|
+
const store = new HistoryStore();
|
|
90
|
+
store.archive(result);
|
|
91
91
|
this.log('');
|
|
92
92
|
this.printSummary(result);
|
|
93
93
|
if (flags['fail-on']) {
|
|
@@ -8,11 +8,31 @@ export interface ApexClassBody {
|
|
|
8
8
|
name: string;
|
|
9
9
|
body: string;
|
|
10
10
|
}
|
|
11
|
+
export interface VfPageBody {
|
|
12
|
+
name: string;
|
|
13
|
+
markup: string;
|
|
14
|
+
}
|
|
15
|
+
export interface EventLogSummary {
|
|
16
|
+
earliestDate: string | null;
|
|
17
|
+
totalFiles: number;
|
|
18
|
+
eventTypes: string[];
|
|
19
|
+
}
|
|
20
|
+
export interface MfaRegistration {
|
|
21
|
+
userId: string;
|
|
22
|
+
username: string;
|
|
23
|
+
profileName: string;
|
|
24
|
+
methods: string[];
|
|
25
|
+
}
|
|
11
26
|
export interface AuditCache {
|
|
12
27
|
healthCheckRisks?: HealthCheckRisk[];
|
|
13
28
|
apexBodies?: ApexClassBody[];
|
|
14
29
|
namedCredentialEndpoints?: string[];
|
|
15
30
|
remoteSiteUrls?: string[];
|
|
16
31
|
healthCloudInstalled?: boolean;
|
|
32
|
+
connectedAppNames?: string[];
|
|
33
|
+
scheduledApexClassNames?: string[];
|
|
34
|
+
eventLogSummary?: EventLogSummary;
|
|
35
|
+
mfaRegistrations?: MfaRegistration[];
|
|
36
|
+
vfPageBodies?: VfPageBody[];
|
|
17
37
|
}
|
|
18
38
|
//# sourceMappingURL=AuditCache.d.ts.map
|
|
@@ -1,14 +1,12 @@
|
|
|
1
1
|
import type { SoqlClient } from '../api/SoqlClient.js';
|
|
2
2
|
import type { ToolingClient } from '../api/ToolingClient.js';
|
|
3
3
|
import type { RestClient } from '../api/RestClient.js';
|
|
4
|
-
import type { QueryRegistry } from '../queries/QueryRegistry.js';
|
|
5
4
|
import type { OrgInfo } from './OrgInfo.js';
|
|
6
5
|
import type { AuditCache } from './AuditCache.js';
|
|
7
6
|
export interface AuditContext {
|
|
8
7
|
readonly soql: SoqlClient;
|
|
9
8
|
readonly tooling: ToolingClient;
|
|
10
9
|
readonly rest: RestClient;
|
|
11
|
-
readonly queries: QueryRegistry;
|
|
12
10
|
readonly orgInfo: OrgInfo;
|
|
13
11
|
cache: AuditCache;
|
|
14
12
|
}
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import type { Finding } from './Finding.js';
|
|
2
2
|
import type { OrgMetrics } from '../context/OrgMetrics.js';
|
|
3
|
+
import type { AttackChain } from '../chains/AttackChain.js';
|
|
3
4
|
export interface AuditResult {
|
|
4
5
|
generatedAt: Date;
|
|
5
6
|
orgId: string;
|
|
@@ -7,9 +8,11 @@ export interface AuditResult {
|
|
|
7
8
|
orgType: string;
|
|
8
9
|
isSandbox: boolean;
|
|
9
10
|
instance: string;
|
|
11
|
+
instanceUrl: string;
|
|
10
12
|
findings: Finding[];
|
|
11
13
|
metrics: OrgMetrics;
|
|
12
14
|
healthScore: number;
|
|
13
15
|
grade: 'A' | 'B' | 'C' | 'D' | 'F';
|
|
16
|
+
attackChains?: AttackChain[];
|
|
14
17
|
}
|
|
15
18
|
//# sourceMappingURL=AuditResult.d.ts.map
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
// Maps each SecurityCheck `id` to its compliance framework references.
|
|
2
|
+
// Tags use the format: <Framework>-<Control> e.g. OWASP-A01, SOC2-CC6.1, ISO-A.9.2, SBS-<domain>-<num>
|
|
3
|
+
export const COMPLIANCE_MAP = {
|
|
4
|
+
'users-and-admins': ['OWASP-A01', 'SOC2-CC6.1', 'ISO-A.9.2', 'HIPAA-164.312a', 'GDPR-Art.32', 'SBS-ACS-004'],
|
|
5
|
+
'permissions': ['OWASP-A01', 'SOC2-CC6.1', 'ISO-A.9.2', 'GDPR-Art.32', 'SBS-ACS-002', 'SBS-ACS-005'],
|
|
6
|
+
'inactive-users': ['OWASP-A01', 'SOC2-CC6.2', 'ISO-A.9.2', 'HIPAA-164.312a', 'GDPR-Art.5', 'SBS-ACS-007'],
|
|
7
|
+
'login-session': ['OWASP-A07', 'SOC2-CC6.1', 'ISO-A.9.4', 'HIPAA-164.312a', 'GDPR-Art.32'],
|
|
8
|
+
'ip-restrictions': ['OWASP-A07', 'SOC2-CC6.1', 'ISO-A.9.4', 'HIPAA-164.312a', 'GDPR-Art.32', 'SBS-AUTH-003'],
|
|
9
|
+
'password-session-policy': ['OWASP-A07', 'SOC2-CC6.1', 'ISO-A.9.4', 'HIPAA-164.312d', 'GDPR-Art.32'],
|
|
10
|
+
'field-level-security': ['OWASP-A01', 'SOC2-CC6.1', 'ISO-A.9.4', 'HIPAA-164.312a', 'GDPR-Art.5'],
|
|
11
|
+
'sharing-model': ['OWASP-A01', 'SOC2-CC6.1', 'ISO-A.9.4', 'HIPAA-164.312a', 'GDPR-Art.32'],
|
|
12
|
+
'public-group-sharing': ['OWASP-A01', 'SOC2-CC6.1', 'ISO-A.9.4', 'HIPAA-164.312a', 'GDPR-Art.32'],
|
|
13
|
+
'guest-user-access': ['OWASP-A01', 'SOC2-CC6.1', 'ISO-A.9.2', 'GDPR-Art.32', 'SBS-CPORTAL-002'],
|
|
14
|
+
'apex-sharing': ['OWASP-A01', 'SOC2-CC6.1', 'ISO-A.9.4', 'GDPR-Art.32', 'SBS-CPORTAL-001'],
|
|
15
|
+
'flows-without-sharing': ['OWASP-A01', 'SOC2-CC6.1', 'ISO-A.9.4', 'GDPR-Art.32', 'SBS-CPORTAL-004'],
|
|
16
|
+
'connected-apps': ['OWASP-A05', 'SOC2-CC6.6', 'ISO-A.9.4', 'GDPR-Art.32', 'SBS-OAUTH-001', 'SBS-OAUTH-002', 'SBS-DEP-006'],
|
|
17
|
+
'remote-sites': ['OWASP-A05', 'SOC2-CC6.4', 'ISO-A.14.1', 'GDPR-Art.32', 'SBS-INT-002'],
|
|
18
|
+
'csp-trusted-sites': ['OWASP-A05', 'SOC2-CC6.4', 'ISO-A.14.1', 'GDPR-Art.32'],
|
|
19
|
+
'named-credentials': ['OWASP-A02', 'SOC2-CC6.7', 'ISO-A.9.4', 'GDPR-Art.32', 'SBS-INT-003'],
|
|
20
|
+
'hardcoded-credentials': ['OWASP-A02', 'SOC2-CC6.7', 'ISO-A.9.4', 'HIPAA-164.312d', 'GDPR-Art.32', 'SBS-DEP-005'],
|
|
21
|
+
'custom-settings': ['OWASP-A02', 'SOC2-CC6.7', 'ISO-A.9.4', 'GDPR-Art.32'],
|
|
22
|
+
'health-check': ['OWASP-A05', 'SOC2-CC7.1', 'ISO-A.12.6', 'GDPR-Art.32', 'SBS-SECCONF-001', 'SBS-SECCONF-002'],
|
|
23
|
+
'audit-trail': ['OWASP-A09', 'SOC2-CC7.2', 'ISO-A.12.4', 'HIPAA-164.312b', 'GDPR-Art.32', 'SBS-MON-002'],
|
|
24
|
+
'code-security': ['OWASP-A03', 'OWASP-A05', 'SOC2-CC7.2', 'ISO-A.14.2', 'GDPR-Art.32', 'SBS-CODE-002'],
|
|
25
|
+
'api-limits': ['OWASP-A05', 'SOC2-CC9.1', 'ISO-A.12.6', 'GDPR-Art.32', 'SBS-MON-005'],
|
|
26
|
+
'scheduled-apex': ['OWASP-A05', 'SOC2-CC7.2', 'ISO-A.12.1', 'GDPR-Art.32'],
|
|
27
|
+
// Net-new SBS checks
|
|
28
|
+
'standard-profiles': ['OWASP-A01', 'SOC2-CC6.3', 'ISO-A.9.2', 'GDPR-Art.32', 'SBS-ACS-005'],
|
|
29
|
+
'sso-enforcement': ['OWASP-A07', 'SOC2-CC6.1', 'ISO-A.9.4', 'HIPAA-164.312d', 'GDPR-Art.32', 'SBS-AUTH-001', 'SBS-AUTH-002'],
|
|
30
|
+
'mfa-enforcement': ['OWASP-A07', 'SOC2-CC6.1', 'ISO-A.9.4', 'HIPAA-164.312d', 'GDPR-Art.32', 'SBS-AUTH-004'],
|
|
31
|
+
'api-client-permission': ['OWASP-A01', 'SOC2-CC6.3', 'ISO-A.9.4', 'GDPR-Art.32', 'SBS-ACS-006'],
|
|
32
|
+
'integration-users': ['OWASP-A01', 'SOC2-CC6.1', 'ISO-A.9.2', 'GDPR-Art.32', 'SBS-ACS-007', 'SBS-ACS-008', 'SBS-ACS-009'],
|
|
33
|
+
'content-links': ['OWASP-A01', 'SOC2-CC6.1', 'ISO-A.13.2', 'GDPR-Art.32', 'SBS-FILE-001', 'SBS-FILE-002', 'SBS-FILE-003'],
|
|
34
|
+
'field-history-tracking': ['OWASP-A09', 'SOC2-CC7.2', 'ISO-A.12.4', 'HIPAA-164.312b', 'GDPR-Art.32', 'SBS-DATA-004'],
|
|
35
|
+
'data-classification': ['OWASP-A01', 'SOC2-CC6.1', 'ISO-A.8.2', 'HIPAA-164.514', 'GDPR-Art.30', 'SBS-DATA-001', 'SBS-DATA-002', 'SBS-DATA-003'],
|
|
36
|
+
'deployment-identity': ['OWASP-A05', 'SOC2-CC8.1', 'ISO-A.12.1', 'GDPR-Art.32', 'SBS-DEP-001', 'SBS-DEP-003'],
|
|
37
|
+
'apex-logging': ['OWASP-A09', 'SOC2-CC7.2', 'ISO-A.12.4', 'GDPR-Art.32', 'SBS-CODE-003', 'SBS-CODE-004'],
|
|
38
|
+
'event-monitoring': ['OWASP-A09', 'SOC2-CC7.2', 'ISO-A.12.4', 'HIPAA-164.312b', 'GDPR-Art.32', 'SBS-MON-001', 'SBS-INT-004'],
|
|
39
|
+
'siem-integration': ['OWASP-A09', 'SOC2-CC7.2', 'ISO-A.12.4', 'HIPAA-164.312b', 'GDPR-Art.32', 'SBS-MON-003', 'SBS-MON-004'],
|
|
40
|
+
// Additional security checks
|
|
41
|
+
'apex-crud-fls': ['OWASP-A01', 'SOC2-CC6.1', 'ISO-A.9.4', 'HIPAA-164.312a', 'GDPR-Art.32'],
|
|
42
|
+
'apex-rest-endpoint': ['OWASP-A01', 'OWASP-A07', 'SOC2-CC6.1', 'ISO-A.9.4', 'GDPR-Art.32'],
|
|
43
|
+
'visualforce-xss': ['OWASP-A03', 'SOC2-CC6.1', 'ISO-A.14.2', 'GDPR-Art.32'],
|
|
44
|
+
'certificate-expiry': ['OWASP-A02', 'SOC2-CC6.7', 'ISO-A.10.1', 'HIPAA-164.312e', 'GDPR-Art.32'],
|
|
45
|
+
'installed-packages': ['OWASP-A06', 'SOC2-CC9.2', 'ISO-A.14.2', 'GDPR-Art.32'],
|
|
46
|
+
'trusted-ip-ranges': ['OWASP-A07', 'SOC2-CC6.1', 'ISO-A.9.4', 'HIPAA-164.312d', 'GDPR-Art.32', 'SBS-AUTH-003'],
|
|
47
|
+
'anonymous-apex-audit': ['OWASP-A09', 'SOC2-CC7.2', 'ISO-A.12.4', 'GDPR-Art.32'],
|
|
48
|
+
'debug-log-access': ['OWASP-A09', 'SOC2-CC7.2', 'ISO-A.12.4', 'HIPAA-164.312b', 'GDPR-Art.32'],
|
|
49
|
+
'connected-app-inactivity': ['OWASP-A05', 'SOC2-CC6.6', 'ISO-A.9.2', 'GDPR-Art.32'],
|
|
50
|
+
'my-domain-login-policy': ['OWASP-A07', 'SOC2-CC6.1', 'ISO-A.9.4', 'HIPAA-164.312d', 'GDPR-Art.32', 'SBS-AUTH-001'],
|
|
51
|
+
'high-assurance-session': ['OWASP-A07', 'SOC2-CC6.1', 'ISO-A.9.4', 'HIPAA-164.312d', 'GDPR-Art.32'],
|
|
52
|
+
'enhanced-domains': ['OWASP-A05', 'SOC2-CC6.1', 'ISO-A.14.1', 'GDPR-Art.32'],
|
|
53
|
+
// Recent Salesforce MFA improvements
|
|
54
|
+
'internal-user-mfa': ['OWASP-A07', 'SOC2-CC6.1', 'ISO-A.9.4', 'HIPAA-164.312d', 'GDPR-Art.32', 'SBS-AUTH-004'],
|
|
55
|
+
'mfa-registration': ['OWASP-A07', 'SOC2-CC6.1', 'ISO-A.9.4', 'HIPAA-164.312d', 'GDPR-Art.32'],
|
|
56
|
+
'mfa-method-strength': ['OWASP-A07', 'SOC2-CC6.1', 'ISO-A.9.4', 'HIPAA-164.312d', 'GDPR-Art.32'],
|
|
57
|
+
// Platform hygiene + API security
|
|
58
|
+
'release-updates': ['OWASP-A06', 'SOC2-CC7.1', 'ISO-A.12.6', 'GDPR-Art.32'],
|
|
59
|
+
'legacy-api-version': ['OWASP-A06', 'SOC2-CC6.4', 'ISO-A.12.6', 'GDPR-Art.32'],
|
|
60
|
+
'connected-app-scope': ['OWASP-A01', 'OWASP-A05', 'SOC2-CC6.6', 'ISO-A.9.4', 'GDPR-Art.32', 'SBS-OAUTH-002'],
|
|
61
|
+
// Threat detection + hacker attack surface coverage
|
|
62
|
+
'transaction-security-policy': ['OWASP-A09', 'SOC2-CC7.2', 'ISO-A.12.4', 'HIPAA-164.312b', 'GDPR-Art.32', 'SBS-MON-003'],
|
|
63
|
+
'failed-login-detection': ['OWASP-A07', 'SOC2-CC7.2', 'ISO-A.12.4', 'HIPAA-164.312b', 'GDPR-Art.32', 'SBS-MON-003'],
|
|
64
|
+
'experience-cloud-site': ['OWASP-A01', 'SOC2-CC6.1', 'ISO-A.9.4', 'GDPR-Art.32', 'SBS-CPORTAL-003'],
|
|
65
|
+
'custom-labels-credential': ['OWASP-A02', 'SOC2-CC6.7', 'ISO-A.9.4', 'HIPAA-164.312d', 'GDPR-Art.32'],
|
|
66
|
+
'report-folder-access': ['OWASP-A01', 'SOC2-CC6.1', 'ISO-A.9.4', 'HIPAA-164.312a', 'GDPR-Art.32'],
|
|
67
|
+
// Attack-chain ingredient checks
|
|
68
|
+
'escalation-perms': ['OWASP-A01', 'SOC2-CC6.3', 'ISO-A.9.2', 'HIPAA-164.312a', 'GDPR-Art.32', 'SBS-ACS-004'],
|
|
69
|
+
'cors-allowlist': ['OWASP-A05', 'SOC2-CC6.4', 'ISO-A.14.1', 'GDPR-Art.32'],
|
|
70
|
+
'guest-executable-apex': ['OWASP-A01', 'SOC2-CC6.1', 'ISO-A.9.4', 'GDPR-Art.32', 'SBS-CPORTAL-001', 'SBS-CPORTAL-002'],
|
|
71
|
+
};
|
|
72
|
+
export function getComplianceTags(checkId) {
|
|
73
|
+
return COMPLIANCE_MAP[checkId] ?? [];
|
|
74
|
+
}
|
|
75
|
+
//# sourceMappingURL=ComplianceMapping.js.map
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import type { RiskLevel } from './RiskLevel.js';
|
|
2
|
+
import type { Capability } from '../chains/Capability.js';
|
|
2
3
|
export interface AffectedItem {
|
|
3
4
|
label: string;
|
|
4
5
|
url?: string;
|
|
@@ -24,5 +25,24 @@ export interface Finding {
|
|
|
24
25
|
affectedItems?: AffectedItem[];
|
|
25
26
|
/** True when the finding represents a passing check (everything is correctly configured). */
|
|
26
27
|
passed?: boolean;
|
|
28
|
+
/**
|
|
29
|
+
* Compliance framework tags, e.g. ['OWASP-A01', 'SOC2-CC6.1'].
|
|
30
|
+
* Populated by CheckEngine from ComplianceMapping after each check runs.
|
|
31
|
+
*/
|
|
32
|
+
complianceTags?: string[];
|
|
33
|
+
/**
|
|
34
|
+
* True when the check could not gather evidence due to insufficient permissions.
|
|
35
|
+
* Scored as INFO (no impact on health score) but displayed distinctly.
|
|
36
|
+
*/
|
|
37
|
+
inconclusive?: boolean;
|
|
38
|
+
/**
|
|
39
|
+
* Optional inline attacker-capability declaration for findings produced by
|
|
40
|
+
* chain-aware checks. When present, it overrides the central CapabilityRegistry
|
|
41
|
+
* entry for this finding id. Only honoured for active (non-passed, non-inconclusive) findings.
|
|
42
|
+
*/
|
|
43
|
+
capabilities?: {
|
|
44
|
+
grants?: Capability[];
|
|
45
|
+
requires?: Capability[];
|
|
46
|
+
};
|
|
27
47
|
}
|
|
28
48
|
//# sourceMappingURL=Finding.d.ts.map
|
|
@@ -10,11 +10,18 @@ export function loadScoringConfig(filePath, knownCheckIds, warn) {
|
|
|
10
10
|
catch (err) {
|
|
11
11
|
throw new Error(`Cannot read scoring config file '${filePath}': ${err instanceof Error ? err.message : String(err)}`);
|
|
12
12
|
}
|
|
13
|
-
|
|
13
|
+
let parsed;
|
|
14
|
+
try {
|
|
15
|
+
parsed = JSON.parse(raw);
|
|
16
|
+
}
|
|
17
|
+
catch (err) {
|
|
18
|
+
throw new Error(`Invalid JSON in scoring config '${filePath}': ${err instanceof Error ? err.message : String(err)}`);
|
|
19
|
+
}
|
|
14
20
|
const validated = scoringConfigSchema.parse(parsed); // throws ZodError on failure
|
|
15
21
|
// Warn on unknown check IDs and drop them
|
|
16
22
|
const safeCheckWeights = {};
|
|
17
|
-
|
|
23
|
+
const rawWeights = validated.checkWeights ?? {};
|
|
24
|
+
for (const [id, weight] of Object.entries(rawWeights)) {
|
|
18
25
|
if (!knownCheckIds.has(id)) {
|
|
19
26
|
warn(`Unknown check ID in --scoring-config checkWeights: '${id}'. Run 'sf audit list' to see valid IDs. Skipping.`);
|
|
20
27
|
}
|
|
@@ -3,5 +3,6 @@ import type { OrgMetrics } from '../context/OrgMetrics.js';
|
|
|
3
3
|
import type { AuditResult } from './AuditResult.js';
|
|
4
4
|
import type { AuditContext } from '../context/AuditContext.js';
|
|
5
5
|
import type { ScoringConfig } from './ScoringConfig.js';
|
|
6
|
-
|
|
6
|
+
import type { AttackChain } from '../chains/AttackChain.js';
|
|
7
|
+
export declare function buildAuditResult(ctx: AuditContext, findings: Finding[], metrics: Partial<OrgMetrics>, config?: ScoringConfig, attackChains?: AttackChain[]): AuditResult;
|
|
7
8
|
//# sourceMappingURL=scoring.d.ts.map
|
package/lib/findings/scoring.js
CHANGED
|
@@ -11,13 +11,24 @@ function meetsConditions(conditions, healthScore, criticalCount, highCount, medi
|
|
|
11
11
|
return false;
|
|
12
12
|
return true;
|
|
13
13
|
}
|
|
14
|
-
export function buildAuditResult(ctx, findings, metrics, config = DEFAULT_SCORING_CONFIG) {
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
const
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
14
|
+
export function buildAuditResult(ctx, findings, metrics, config = DEFAULT_SCORING_CONFIG, attackChains = []) {
|
|
15
|
+
// Passed and inconclusive findings carry no penalty — exclude from numerator.
|
|
16
|
+
// They remain in maxPossible so a broad passing audit still dilutes real failures.
|
|
17
|
+
const totalScore = findings.reduce((sum, f) => {
|
|
18
|
+
if (f.passed || f.inconclusive)
|
|
19
|
+
return sum;
|
|
20
|
+
return sum + (f.checkId !== undefined ? (config.checkWeights[f.checkId] ?? config.riskScores[f.riskLevel]) : config.riskScores[f.riskLevel]);
|
|
21
|
+
}, 0);
|
|
22
|
+
const chainScore = attackChains.reduce((sum, c) => sum + config.riskScores[c.severity], 0);
|
|
23
|
+
const totalWithChains = totalScore + chainScore;
|
|
24
|
+
const maxPossible = (findings.length + attackChains.length) * 10;
|
|
25
|
+
const healthScore = Math.max(0, 100 - Math.round((totalWithChains / Math.max(maxPossible, 1)) * 100));
|
|
26
|
+
const chainCrit = attackChains.filter((c) => c.severity === 'CRITICAL').length;
|
|
27
|
+
const chainHigh = attackChains.filter((c) => c.severity === 'HIGH').length;
|
|
28
|
+
const chainMed = attackChains.filter((c) => c.severity === 'MEDIUM').length;
|
|
29
|
+
const criticalCount = findings.filter((f) => f.riskLevel === 'CRITICAL').length + chainCrit;
|
|
30
|
+
const highCount = findings.filter((f) => f.riskLevel === 'HIGH').length + chainHigh;
|
|
31
|
+
const mediumCount = findings.filter((f) => f.riskLevel === 'MEDIUM').length + chainMed;
|
|
21
32
|
const grades = ['A', 'B', 'C', 'D'];
|
|
22
33
|
let grade = 'F';
|
|
23
34
|
for (const g of grades) {
|
|
@@ -33,10 +44,12 @@ export function buildAuditResult(ctx, findings, metrics, config = DEFAULT_SCORIN
|
|
|
33
44
|
orgType: ctx.orgInfo.type,
|
|
34
45
|
isSandbox: ctx.orgInfo.isSandbox,
|
|
35
46
|
instance: ctx.orgInfo.instance,
|
|
47
|
+
instanceUrl: ctx.orgInfo.instanceUrl,
|
|
36
48
|
findings,
|
|
37
49
|
metrics: { ...EMPTY_METRICS, ...metrics },
|
|
38
50
|
healthScore,
|
|
39
51
|
grade,
|
|
52
|
+
attackChains,
|
|
40
53
|
};
|
|
41
54
|
}
|
|
42
55
|
//# sourceMappingURL=scoring.js.map
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import type { Finding } from '../findings/Finding.js';
|
|
2
|
+
import type { OrgMetrics } from '../context/OrgMetrics.js';
|
|
3
|
+
import type { AuditResult } from '../findings/AuditResult.js';
|
|
4
|
+
export type FindingChangeType = 'new' | 'resolved' | 'severity-changed' | 'detail-changed' | 'unchanged';
|
|
5
|
+
export interface FindingChange {
|
|
6
|
+
type: FindingChangeType;
|
|
7
|
+
finding: Finding;
|
|
8
|
+
previous?: Finding;
|
|
9
|
+
}
|
|
10
|
+
export interface MetricDelta {
|
|
11
|
+
key: keyof OrgMetrics;
|
|
12
|
+
label: string;
|
|
13
|
+
before: number;
|
|
14
|
+
after: number;
|
|
15
|
+
delta: number;
|
|
16
|
+
direction: 'improved' | 'degraded' | 'neutral';
|
|
17
|
+
}
|
|
18
|
+
export interface AuditDiff {
|
|
19
|
+
baseline: AuditResult;
|
|
20
|
+
current: AuditResult;
|
|
21
|
+
findingChanges: FindingChange[];
|
|
22
|
+
metricDeltas: MetricDelta[];
|
|
23
|
+
scoreDelta: number;
|
|
24
|
+
gradeDelta: string;
|
|
25
|
+
}
|
|
26
|
+
//# sourceMappingURL=AuditDiff.d.ts.map
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
import { METRIC_META, metricDirection } from './metricMeta.js';
|
|
2
|
+
function detailChanged(a, b) {
|
|
3
|
+
return (a.detail !== b.detail ||
|
|
4
|
+
a.remediation !== b.remediation ||
|
|
5
|
+
JSON.stringify(a.affectedItems) !== JSON.stringify(b.affectedItems));
|
|
6
|
+
}
|
|
7
|
+
export function computeDiff(baseline, current) {
|
|
8
|
+
const baselineMap = new Map(baseline.findings.map((f) => [f.id, f]));
|
|
9
|
+
const currentMap = new Map(current.findings.map((f) => [f.id, f]));
|
|
10
|
+
const findingChanges = [];
|
|
11
|
+
// Walk current findings
|
|
12
|
+
for (const [id, cur] of currentMap) {
|
|
13
|
+
const prev = baselineMap.get(id);
|
|
14
|
+
if (!prev) {
|
|
15
|
+
findingChanges.push({ type: 'new', finding: cur });
|
|
16
|
+
}
|
|
17
|
+
else if (cur.riskLevel !== prev.riskLevel) {
|
|
18
|
+
findingChanges.push({ type: 'severity-changed', finding: cur, previous: prev });
|
|
19
|
+
}
|
|
20
|
+
else if (detailChanged(prev, cur)) {
|
|
21
|
+
findingChanges.push({ type: 'detail-changed', finding: cur, previous: prev });
|
|
22
|
+
}
|
|
23
|
+
else {
|
|
24
|
+
findingChanges.push({ type: 'unchanged', finding: cur });
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
// Resolved: in baseline but not in current
|
|
28
|
+
for (const [id, prev] of baselineMap) {
|
|
29
|
+
if (!currentMap.has(id)) {
|
|
30
|
+
findingChanges.push({ type: 'resolved', finding: prev });
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
// Metric deltas — only emit when before !== after
|
|
34
|
+
const metricDeltas = [];
|
|
35
|
+
for (const key of Object.keys(METRIC_META)) {
|
|
36
|
+
const before = baseline.metrics[key];
|
|
37
|
+
const after = current.metrics[key];
|
|
38
|
+
if (before === after)
|
|
39
|
+
continue;
|
|
40
|
+
metricDeltas.push({
|
|
41
|
+
key,
|
|
42
|
+
label: METRIC_META[key].label,
|
|
43
|
+
before,
|
|
44
|
+
after,
|
|
45
|
+
delta: after - before,
|
|
46
|
+
direction: metricDirection(key, before, after),
|
|
47
|
+
});
|
|
48
|
+
}
|
|
49
|
+
const gradeDelta = baseline.grade === current.grade
|
|
50
|
+
? 'unchanged'
|
|
51
|
+
: `${baseline.grade} → ${current.grade}`;
|
|
52
|
+
return {
|
|
53
|
+
baseline,
|
|
54
|
+
current,
|
|
55
|
+
findingChanges,
|
|
56
|
+
metricDeltas,
|
|
57
|
+
scoreDelta: current.healthScore - baseline.healthScore,
|
|
58
|
+
gradeDelta,
|
|
59
|
+
};
|
|
60
|
+
}
|
|
61
|
+
//# sourceMappingURL=DiffEngine.js.map
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import type { AuditResult } from '../findings/AuditResult.js';
|
|
2
|
+
export declare class HistoryStore {
|
|
3
|
+
private readonly root;
|
|
4
|
+
constructor(root?: string);
|
|
5
|
+
static defaultRoot(): string;
|
|
6
|
+
archive(result: AuditResult): void;
|
|
7
|
+
list(orgId: string, dir?: string): AuditResult[];
|
|
8
|
+
latest(orgId: string, dir?: string): AuditResult | null;
|
|
9
|
+
load(filePath: string): AuditResult;
|
|
10
|
+
}
|
|
11
|
+
//# sourceMappingURL=HistoryStore.d.ts.map
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
// src/history/HistoryStore.ts
|
|
2
|
+
import * as fs from 'node:fs';
|
|
3
|
+
import * as os from 'node:os';
|
|
4
|
+
import * as path from 'node:path';
|
|
5
|
+
function parseResult(raw) {
|
|
6
|
+
const obj = JSON.parse(raw);
|
|
7
|
+
obj.generatedAt = new Date(obj.generatedAt);
|
|
8
|
+
return obj;
|
|
9
|
+
}
|
|
10
|
+
export class HistoryStore {
|
|
11
|
+
root;
|
|
12
|
+
constructor(root) {
|
|
13
|
+
this.root = root ?? HistoryStore.defaultRoot();
|
|
14
|
+
}
|
|
15
|
+
static defaultRoot() {
|
|
16
|
+
return path.join(os.homedir(), '.sf', 'audit-history');
|
|
17
|
+
}
|
|
18
|
+
archive(result) {
|
|
19
|
+
try {
|
|
20
|
+
const dir = path.join(this.root, result.orgId);
|
|
21
|
+
fs.mkdirSync(dir, { recursive: true });
|
|
22
|
+
const suffix = Math.random().toString(36).slice(2, 8);
|
|
23
|
+
const filename = `sf-audit-${result.orgId}-${Date.now()}-${suffix}.json`;
|
|
24
|
+
fs.writeFileSync(path.join(dir, filename), JSON.stringify(result, null, 2), 'utf-8');
|
|
25
|
+
}
|
|
26
|
+
catch (err) {
|
|
27
|
+
process.stderr.write(`[sf-audit] Warning: could not archive audit result: ${String(err)}\n`);
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
list(orgId, dir) {
|
|
31
|
+
const searchDir = dir ? path.join(dir, orgId) : path.join(this.root, orgId);
|
|
32
|
+
if (!fs.existsSync(searchDir))
|
|
33
|
+
return [];
|
|
34
|
+
const files = fs.readdirSync(searchDir)
|
|
35
|
+
.filter((f) => f.startsWith('sf-audit-') && f.endsWith('.json'))
|
|
36
|
+
.map((f) => path.join(searchDir, f));
|
|
37
|
+
const results = [];
|
|
38
|
+
for (const file of files) {
|
|
39
|
+
try {
|
|
40
|
+
results.push(parseResult(fs.readFileSync(file, 'utf-8')));
|
|
41
|
+
}
|
|
42
|
+
catch {
|
|
43
|
+
// skip unparseable files silently
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
return results.sort((a, b) => a.generatedAt.getTime() - b.generatedAt.getTime());
|
|
47
|
+
}
|
|
48
|
+
latest(orgId, dir) {
|
|
49
|
+
const all = this.list(orgId, dir);
|
|
50
|
+
return all.length > 0 ? all[all.length - 1] : null;
|
|
51
|
+
}
|
|
52
|
+
load(filePath) {
|
|
53
|
+
return parseResult(fs.readFileSync(filePath, 'utf-8'));
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
//# sourceMappingURL=HistoryStore.js.map
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import type { OrgMetrics } from '../context/OrgMetrics.js';
|
|
2
|
+
export interface MetricMeta {
|
|
3
|
+
label: string;
|
|
4
|
+
/** Which direction means "getting better"? */
|
|
5
|
+
improvedWhen: 'higher' | 'lower' | 'neutral';
|
|
6
|
+
}
|
|
7
|
+
export declare const METRIC_META: Record<keyof OrgMetrics, MetricMeta>;
|
|
8
|
+
export declare function metricDirection(key: keyof OrgMetrics, before: number, after: number): 'improved' | 'degraded' | 'neutral';
|
|
9
|
+
//# sourceMappingURL=metricMeta.d.ts.map
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
// Every key of OrgMetrics must have an entry here.
|
|
2
|
+
export const METRIC_META = {
|
|
3
|
+
totalActiveUsers: { label: 'Total Active Users', improvedWhen: 'neutral' },
|
|
4
|
+
modifyAllDataUsersCount: { label: 'Modify All Data Users', improvedWhen: 'lower' },
|
|
5
|
+
viewAllDataUsersCount: { label: 'View All Data Users', improvedWhen: 'lower' },
|
|
6
|
+
permissionSetCount: { label: 'Permission Sets', improvedWhen: 'neutral' },
|
|
7
|
+
profileCount: { label: 'Profiles', improvedWhen: 'neutral' },
|
|
8
|
+
apexClassCount: { label: 'Apex Classes', improvedWhen: 'neutral' },
|
|
9
|
+
apexTriggerCount: { label: 'Apex Triggers', improvedWhen: 'neutral' },
|
|
10
|
+
codeCoveragePercent: { label: 'Code Coverage %', improvedWhen: 'higher' },
|
|
11
|
+
failedLogins30d: { label: 'Failed Logins (30d)', improvedWhen: 'lower' },
|
|
12
|
+
inactiveUsers90d: { label: 'Inactive Users (90d)', improvedWhen: 'lower' },
|
|
13
|
+
connectedAppsCount: { label: 'Connected Apps', improvedWhen: 'neutral' },
|
|
14
|
+
remoteSitesCount: { label: 'Remote Site Settings', improvedWhen: 'neutral' },
|
|
15
|
+
insecureRemoteSitesCount: { label: 'Insecure Remote Sites', improvedWhen: 'lower' },
|
|
16
|
+
namedCredentialsCount: { label: 'Named Credentials', improvedWhen: 'neutral' },
|
|
17
|
+
unusedNamedCredentialsCount: { label: 'Unused Named Credentials', improvedWhen: 'lower' },
|
|
18
|
+
healthCheckScore: { label: 'Health Check Score', improvedWhen: 'higher' },
|
|
19
|
+
};
|
|
20
|
+
export function metricDirection(key, before, after) {
|
|
21
|
+
const meta = METRIC_META[key];
|
|
22
|
+
if (meta.improvedWhen === 'neutral' || before === after)
|
|
23
|
+
return 'neutral';
|
|
24
|
+
if (meta.improvedWhen === 'higher')
|
|
25
|
+
return after > before ? 'improved' : 'degraded';
|
|
26
|
+
return after < before ? 'improved' : 'degraded';
|
|
27
|
+
}
|
|
28
|
+
//# sourceMappingURL=metricMeta.js.map
|
package/lib/index.d.ts
CHANGED
|
@@ -1,2 +1,8 @@
|
|
|
1
|
-
export {};
|
|
1
|
+
export type { AuditResult } from './findings/AuditResult.js';
|
|
2
|
+
export type { Finding } from './findings/Finding.js';
|
|
3
|
+
export type { RiskLevel } from './findings/RiskLevel.js';
|
|
4
|
+
export type { OrgMetrics } from './context/OrgMetrics.js';
|
|
5
|
+
export type { AuditDiff, FindingChange, FindingChangeType, MetricDelta } from './history/AuditDiff.js';
|
|
6
|
+
export { HistoryStore } from './history/HistoryStore.js';
|
|
7
|
+
export { computeDiff } from './history/DiffEngine.js';
|
|
2
8
|
//# sourceMappingURL=index.d.ts.map
|
package/lib/index.js
CHANGED
package/lib/lib/wire.d.ts
CHANGED
|
@@ -4,12 +4,11 @@ import { ToolingClientImpl } from '../api/ToolingClientImpl.js';
|
|
|
4
4
|
import { RestClientImpl } from '../api/RestClientImpl.js';
|
|
5
5
|
import type { AuditContext } from '../context/AuditContext.js';
|
|
6
6
|
import type { OrgInfo } from '../context/OrgInfo.js';
|
|
7
|
-
import type { QueryRegistry } from '../queries/QueryRegistry.js';
|
|
8
7
|
export declare function buildApiClients(conn: Connection): {
|
|
9
8
|
soql: SoqlClientImpl;
|
|
10
9
|
tooling: ToolingClientImpl;
|
|
11
10
|
rest: RestClientImpl;
|
|
12
11
|
};
|
|
13
12
|
export declare function resolveOrgInfo(conn: Connection): Promise<OrgInfo>;
|
|
14
|
-
export declare function buildAuditContext(conn: Connection,
|
|
13
|
+
export declare function buildAuditContext(conn: Connection, orgInfo: OrgInfo): AuditContext;
|
|
15
14
|
//# sourceMappingURL=wire.d.ts.map
|
package/lib/lib/wire.js
CHANGED
|
@@ -22,13 +22,12 @@ export async function resolveOrgInfo(conn) {
|
|
|
22
22
|
instanceUrl: conn.instanceUrl,
|
|
23
23
|
};
|
|
24
24
|
}
|
|
25
|
-
export function buildAuditContext(conn,
|
|
25
|
+
export function buildAuditContext(conn, orgInfo) {
|
|
26
26
|
const clients = buildApiClients(conn);
|
|
27
27
|
return {
|
|
28
28
|
soql: clients.soql,
|
|
29
29
|
tooling: clients.tooling,
|
|
30
30
|
rest: clients.rest,
|
|
31
|
-
queries,
|
|
32
31
|
orgInfo,
|
|
33
32
|
cache: {},
|
|
34
33
|
};
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import type { AuditDiff } from '../history/AuditDiff.js';
|
|
2
|
+
import type { DiffRenderer } from './DiffRenderer.js';
|
|
3
|
+
export declare class DiffHtmlRenderer implements DiffRenderer {
|
|
4
|
+
readonly format = "html";
|
|
5
|
+
readonly fileExtension = ".html";
|
|
6
|
+
render(diff: AuditDiff): string;
|
|
7
|
+
}
|
|
8
|
+
//# sourceMappingURL=DiffHtmlRenderer.d.ts.map
|