diff --git a/tests/security.ts b/tests/security.ts index 500c9fc..8e7470c 100644 --- a/tests/security.ts +++ b/tests/security.ts @@ -1,20 +1,40 @@ import { readdir } from "node:fs/promises" const files = await readdir('./node_modules', { recursive: true }) -let findings: string[] = [] +let findings: Map = new Map() for (const directory of files) { const file = Bun.file('./node_modules/' + directory) - + if (file.type.startsWith('text/javascript')) { const content = await file.text().catch(err => { if (err.code === 'EISDIR') return else throw err }) + if (content) { + const lines = content.split('\n') + let matchingLines: string[] = [] + + for (let i = 0; i < lines.length; i++) { + const line = lines[i] + + if (line.includes('fetch') || line.includes('XMLHttpRequest') || line.includes('WebSocket')) { + matchingLines.push(`Line ${i + 1}: ${line.trim()}`) + } + } - if (content && (content.includes('fetch') || content.includes('XMLHttpRequest') || content.includes('WebSocket'))) findings.push(directory) + if (matchingLines.length > 0) { + findings.set(directory, matchingLines) + } + } } } -console.log(findings.join('\n')) \ No newline at end of file +for (const [ directory, lines ] of findings.entries()) { + console.log(`${directory}:`) + + for (const line of lines) { + console.log(`- ${line}`) + } +} \ No newline at end of file