MCPcopy Create free account
hub / github.com/ShipSecAI/studio / extractAndValidateZip

Function extractAndValidateZip

worker/src/components/security/nuclei.ts:657–727  ·  view source on GitHub ↗
(
  zipBuffer: Buffer,
  context: any,
)

Source from the content-addressed store, hash-verified

655}
656
657async function extractAndValidateZip(
658 zipBuffer: Buffer,
659 context: any,
660): Promise<Record<string, Buffer>> {
661 try {
662 const AdmZip = require('adm-zip');
663 const zip = new AdmZip(zipBuffer);
664 const zipEntries = zip.getEntries();
665
666 const files: Record<string, Buffer> = {};
667 let totalSize = 0;
668 const maxSingleFileSize = 1024 * 1024; // 1MB per file
669
670 for (const entry of zipEntries) {
671 if (entry.isDirectory) {
672 continue;
673 }
674
675 if (!entry.entryName.endsWith('.yaml') && !entry.entryName.endsWith('.yml')) {
676 context.logger.warn(`[Nuclei] Skipping non-YAML file: ${entry.entryName}`);
677 continue;
678 }
679
680 if (entry.entryName.includes('..') || entry.entryName.startsWith('/')) {
681 context.logger.warn(`[Nuclei] Skipping file with invalid path: ${entry.entryName}`);
682 continue;
683 }
684
685 const fileData = entry.getData();
686 if (fileData.length > maxSingleFileSize) {
687 context.logger.warn(
688 `[Nuclei] Skipping oversized file: ${entry.entryName} (${(fileData.length / 1024).toFixed(1)}KB)`,
689 );
690 continue;
691 }
692
693 totalSize += fileData.length;
694
695 try {
696 validateNucleiTemplate(fileData.toString('utf-8'));
697 files[entry.entryName] = fileData;
698 } catch (error) {
699 context.logger.warn(
700 `[Nuclei] Skipping invalid template ${entry.entryName}: ${error instanceof Error ? error.message : 'validation failed'}`,
701 );
702 }
703 }
704
705 if (Object.keys(files).length === 0) {
706 throw new ValidationError('No valid YAML templates found in archive', {
707 details: { archiveSizeBytes: zipBuffer.length },
708 });
709 }
710
711 context.logger.info(
712 `[Nuclei] Validated ${Object.keys(files).length} templates (${(totalSize / 1024).toFixed(1)}KB total)`,
713 );
714

Callers 1

executeFunction · 0.85

Calls 3

validateNucleiTemplateFunction · 0.85
warnMethod · 0.80
infoMethod · 0.80

Tested by

no test coverage detected