-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Improve logging of security to include lines that includes keywords
- Loading branch information
Showing
1 changed file
with
24 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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}`) | ||
} | ||
} |