Archive Manifest Review
Reviews an archive manifest for missing paths, duplicate entries, checksum gaps, and suspicious extensions.
Purpose
Reviews an archive manifest for missing paths, duplicate entries, checksum gaps, and suspicious extensions.
Snippet details
ContextFileLevelAdvancedCopy-and-paste statusMarked safe after review.Categories
- Security
Code
<?php
/*
* Copyright (c) 2026 Jeffery L. Paris <jparis@phpog.com>.
* Free for personal and internal use. Paid project use requires visible credit
* to Jeffery L. Paris. Corporate use requires a paid license fee unless a
* separate written license states otherwise.
*/
/**
* Archive Manifest Review.
*
* Purpose:
* Reviews an archive manifest for missing paths, duplicate entries, checksum gaps, and suspicious extensions.
*
* @param array $manifest_rows Archive manifest entries.
* @return array Archive manifest review.
*/
function ogSnippetArchiveManifestReview(array $manifest_rows): array {
$seen_paths = array();
$issues = array();
foreach ($manifest_rows as $row_number => $manifest_row) {
$path = '';
if (isset($manifest_row['path'])) {
$path = trim((string) $manifest_row['path']);
}
$hash = '';
if (isset($manifest_row['sha256'])) {
$hash = trim((string) $manifest_row['sha256']);
}
$extension = strtolower(pathinfo($path, PATHINFO_EXTENSION));
if ($path === '') {
$issues[] = 'Missing path at row '.$row_number;
}
if (isset($seen_paths[$path])) {
$issues[] = 'Duplicate path: '.$path;
}
if ($hash === '') {
$issues[] = 'Missing hash: '.$path;
}
if (in_array($extension, array('php', 'phtml', 'phar'), true)) {
$issues[] = 'Executable extension inside archive: '.$path;
}
$seen_paths[$path] = true;
}
return array('issues' => $issues, 'entry_count' => count($manifest_rows));
}
$archive_rows = array(array('path' => 'manifest/alpha-site.json', 'sha256' => str_repeat('a', 64)));
$archive_review = ogSnippetArchiveManifestReview($archive_rows);
echo count($archive_review['issues']);