Skip to content

Commit

Permalink
Improve logging of security to include lines that includes keywords
Browse files Browse the repository at this point in the history
  • Loading branch information
KaffinPX committed Jun 24, 2024
1 parent 35775c8 commit cc02454
Showing 1 changed file with 24 additions and 4 deletions.
28 changes: 24 additions & 4 deletions tests/security.ts
Original file line number Diff line number Diff line change
@@ -1,20 +1,40 @@
import { readdir } from "node:fs/promises"

const files = await readdir('./node_modules', { recursive: true })
let findings: string[] = []
let findings: Map<string, string[]> = 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'))
for (const [ directory, lines ] of findings.entries()) {
console.log(`${directory}:`)

for (const line of lines) {
console.log(`- ${line}`)
}
}

0 comments on commit cc02454

Please sign in to comment.