Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
176 changes: 47 additions & 129 deletions website/src/plugin/cfi-pages/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,90 +3,6 @@ import path from 'path';
import type { LoadContext, Plugin } from '@docusaurus/types';
import { HomePageData, Configuration, ConfigurationPageData, RepositoryPageData, CFIConfigJson, TestResultItem, TestResultType, CFIRepository, ConfigurationResult, ConfigurationResultPageData, ConfigurationResultSummary } from '../../types/cfi';

function processOCSFResults(resultPath: string): TestResultItem[] {
if (!fs.existsSync(resultPath)) {
return [];
}

const result = fs.readFileSync(resultPath, 'utf8');
const parsed = JSON.parse(result) as any[];

console.log(`📊 Processing ${parsed.length} OCSF items from ${resultPath}`);

return parsed
.filter(item => {
// Only include items that have CCC in compliance
return item.unmapped?.compliance?.['CCC'] &&
Array.isArray(item.unmapped.compliance['CCC']) &&
item.unmapped.compliance['CCC'].length > 0;
})
.map((item, index) => {
const resource = item.resources?.[0] || {};

const testResult: TestResultItem = {
id: `${item.finding_info?.uid || 'unknown'}-${index}`,
test_requirements: item.unmapped.compliance['CCC'],
result: item.status_code === 'PASS' ? TestResultType.PASS :
item.status_code === 'FAIL' ? TestResultType.FAIL : TestResultType.NA,
name: item.finding_info?.title || 'Unknown Finding',
message: item.message || '',
test: item.metadata?.event_code || '',
timestamp: item.finding_info?.created_time || Date.now(),
further_info_url: item.unmapped?.related_url,
resources: [resource.name || resource.uid || 'Unknown Resource'],
// OCSF-specific fields
status_code: item.status_code || 'UNKNOWN',
status_detail: item.status_detail || '',
resource_name: resource.name || resource.uid || 'Unknown Resource',
resource_type: resource.type || 'Unknown Type',
resource_uid: resource.uid,
ccc_objects: item.unmapped.compliance['CCC'],
finding_title: item.finding_info?.title || 'Unknown Finding',
finding_uid: item.finding_info?.uid || ''
};

return testResult;
});
}

function processAllOCSFResults(resultPath: string): TestResultItem[] {
if (!fs.existsSync(resultPath)) {
return [];
}

const result = fs.readFileSync(resultPath, 'utf8');
const parsed = JSON.parse(result) as any[];

console.log(`📊 Processing ALL ${parsed.length} OCSF items from ${resultPath}`);

return parsed.map((item, index) => {
const resource = item.resources?.[0] || {};

const testResult: TestResultItem = {
id: `${item.finding_info?.uid || 'unknown'}-${index}`,
test_requirements: item.unmapped?.compliance?.['CCC'] || [],
result: item.status_code === 'PASS' ? TestResultType.PASS :
item.status_code === 'FAIL' ? TestResultType.FAIL : TestResultType.NA,
name: item.finding_info?.title || 'Unknown Finding',
message: item.message || '',
test: item.metadata?.event_code || '',
timestamp: item.finding_info?.created_time || Date.now(),
further_info_url: item.unmapped?.related_url,
resources: [resource.name || resource.uid || 'Unknown Resource'],
// OCSF-specific fields
status_code: item.status_code || 'UNKNOWN',
status_detail: item.status_detail || '',
resource_name: resource.name || resource.uid || 'Unknown Resource',
resource_type: resource.type || 'Unknown Type',
resource_uid: resource.uid,
ccc_objects: item.unmapped?.compliance?.['CCC'] || [],
finding_title: item.finding_info?.title || 'Unknown Finding',
finding_uid: item.finding_info?.uid || ''
};

return testResult;
});
}

/**
* Process all OCSF results and partition them by product, vendor, and version
Expand All @@ -106,52 +22,54 @@ function partitionOCSFResultsByMetadata(resultsDir: string): Map<string, Configu
const result = fs.readFileSync(resultPath, 'utf8');
const parsed = JSON.parse(result) as any[];

console.log(`📊 Partitioning ${parsed.length} OCSF items from ${resultFile}`);

parsed.forEach((item, index) => {
// Extract metadata
const product = item.metadata?.product?.name || 'Unknown Product';
const vendor = item.metadata?.product?.vendor_name || 'Unknown Vendor';
const version = item.metadata?.product?.version || 'Unknown Version';

// Create unique key for this combination
const key = `${vendor}::${product}::${version}`;

// Initialize partition if it doesn't exist
if (!partitionMap.has(key)) {
partitionMap.set(key, {
product,
vendor,
version,
test_results: []
});
}

// Convert OCSF item to TestResultItem
const resource = item.resources?.[0] || {};
const testResult: TestResultItem = {
id: `${item.finding_info?.uid || 'unknown'}-${index}`,
test_requirements: item.unmapped?.compliance?.['CCC'] || [],
result: item.status_code === 'PASS' ? TestResultType.PASS :
item.status_code === 'FAIL' ? TestResultType.FAIL : TestResultType.NA,
name: item.finding_info?.title || 'Unknown Finding',
message: item.message || '',
test: item.metadata?.event_code || '',
timestamp: item.finding_info?.created_time || Date.now(),
further_info_url: item.unmapped?.related_url,
resources: [resource.name || resource.uid || 'Unknown Resource'],
status_code: item.status_code || 'UNKNOWN',
status_detail: item.status_detail || '',
resource_name: resource.name || resource.uid || 'Unknown Resource',
resource_type: resource.type || 'Unknown Type',
resource_uid: resource.uid,
ccc_objects: item.unmapped?.compliance?.['CCC'] || [],
finding_title: item.finding_info?.title || 'Unknown Finding',
finding_uid: item.finding_info?.uid || ''
};
if (parsed != null) {
console.log(`📊 Partitioning ${parsed.length} OCSF items from ${resultFile}`);

parsed.forEach((item, index) => {
// Extract metadata
const product = item.metadata?.product?.name || 'Unknown Product';
const vendor = item.metadata?.product?.vendor_name || 'Unknown Vendor';
const version = item.metadata?.product?.version || 'Unknown Version';

// Create unique key for this combination
const key = `${vendor}::${product}::${version}`;

// Initialize partition if it doesn't exist
if (!partitionMap.has(key)) {
partitionMap.set(key, {
product,
vendor,
version,
test_results: []
});
}

partitionMap.get(key)!.test_results.push(testResult);
});
// Convert OCSF item to TestResultItem
const resource = item.resources?.[0] || {};
const testResult: TestResultItem = {
id: `${item.finding_info?.uid || 'unknown'}-${index}`,
test_requirements: item.unmapped?.compliance?.['CCC'] || [],
result: item.status_code === 'PASS' ? TestResultType.PASS :
item.status_code === 'FAIL' ? TestResultType.FAIL : TestResultType.NA,
name: item.finding_info?.title || 'Unknown Finding',
message: item.message || '',
test: item.metadata?.event_code || '',
timestamp: item.finding_info?.created_time || Date.now(),
further_info_url: item.unmapped?.related_url,
resources: [resource.name || resource.uid || 'Unknown Resource'],
status_code: item.status_code || 'UNKNOWN',
status_detail: item.status_detail || '',
resource_name: resource.name || resource.uid || 'Unknown Resource',
resource_type: resource.type || 'Unknown Type',
resource_uid: resource.uid,
ccc_objects: item.unmapped?.compliance?.['CCC'] || [],
finding_title: item.finding_info?.title || 'Unknown Finding',
finding_uid: item.finding_info?.uid || ''
};

partitionMap.get(key)!.test_results.push(testResult);
});
}
}

return partitionMap;
Expand Down
Loading