ubon
Version:
Security scanner for AI-generated apps (Cursor, Lovable, Windsurf, v0). Catches hardcoded secrets, prompt injection, hallucinated imports, Server Actions / Edge runtime mistakes, and the vibe-coded vulnerabilities traditional linters miss.
52 lines • 1.83 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.FileSourceCache = exports.DEFAULT_MAX_FILE_SIZE = void 0;
/**
* In-memory file content cache shared across scanners during a single scan.
*
* Multiple scanners (security, AST, vibe, react, lovable, ...) traverse the
* same files and used to read each file independently. With ~10 scanners and
* a few thousand files this is the dominant source of I/O. The cache is
* scoped to a `directory` so concurrent scans on different roots don't
* collide, and is cleared at the end of `UbonScan.diagnose`.
*/
const fs_1 = require("fs");
exports.DEFAULT_MAX_FILE_SIZE = 1024 * 1024; // 1 MB
class FileSourceCache {
static cachesByDirectory = new Map();
cache = new Map();
static forDirectory(directory) {
let existing = FileSourceCache.cachesByDirectory.get(directory);
if (!existing) {
existing = new FileSourceCache();
FileSourceCache.cachesByDirectory.set(directory, existing);
}
return existing;
}
static clear(directory) {
if (directory) {
FileSourceCache.cachesByDirectory.delete(directory);
}
else {
FileSourceCache.cachesByDirectory.clear();
}
}
read(absolutePath) {
const cached = this.cache.get(absolutePath);
if (cached !== undefined)
return cached;
try {
const content = (0, fs_1.readFileSync)(absolutePath, 'utf-8');
this.cache.set(absolutePath, content);
return content;
}
catch {
return undefined;
}
}
set(absolutePath, content) {
this.cache.set(absolutePath, content);
}
}
exports.FileSourceCache = FileSourceCache;
//# sourceMappingURL=file-source-cache.js.map