feat(llm-security): wire AST scanner into orchestrator and policy
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01V3s6WnubSSrFjAQTLQdVbG
This commit is contained in:
parent
e497bb768c
commit
b50313e461
4 changed files with 62 additions and 1 deletions
|
|
@ -11,7 +11,7 @@ import { describe, it, beforeEach } from 'node:test';
|
|||
import assert from 'node:assert/strict';
|
||||
import { resolve, join } from 'node:path';
|
||||
import { fileURLToPath } from 'node:url';
|
||||
import { existsSync, mkdtempSync, mkdirSync, writeFileSync, rmSync } from 'node:fs';
|
||||
import { existsSync, mkdtempSync, mkdirSync, writeFileSync, rmSync, readFileSync } from 'node:fs';
|
||||
import { tmpdir } from 'node:os';
|
||||
import { spawnSync } from 'node:child_process';
|
||||
import { resetCounter } from '../../scanners/lib/output.mjs';
|
||||
|
|
@ -103,3 +103,52 @@ describe('ast-taint-scanner: malformed input resilience', () => {
|
|||
}
|
||||
});
|
||||
});
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// Wiring — OWASP map + orchestrator registration (Step 6)
|
||||
// ---------------------------------------------------------------------------
|
||||
|
||||
describe('ast-taint-scanner: OWASP map registration', () => {
|
||||
it('AST is present in all four OWASP maps with the right codes', async () => {
|
||||
const { OWASP_MAP, OWASP_AGENTIC_MAP, OWASP_SKILLS_MAP, OWASP_MCP_MAP } =
|
||||
await import('../../scanners/lib/severity.mjs');
|
||||
assert.deepEqual(OWASP_MAP.AST, ['LLM01', 'LLM02']);
|
||||
assert.deepEqual(OWASP_AGENTIC_MAP.AST, []);
|
||||
assert.deepEqual(OWASP_SKILLS_MAP.AST, ['AST02']);
|
||||
assert.deepEqual(OWASP_MCP_MAP.AST, []);
|
||||
});
|
||||
});
|
||||
|
||||
describe('ast-taint-scanner: orchestrator registration', () => {
|
||||
it('scan-orchestrator imports and lists the AST scanner', () => {
|
||||
const orchPath = resolve(__dirname, '../../scanners/scan-orchestrator.mjs');
|
||||
const text = readFileSync(orchPath, 'utf8');
|
||||
assert.match(text, /import\s+\{\s*scan as astScan\s*\}\s+from\s+['"]\.\/ast-taint-scanner\.mjs['"]/);
|
||||
assert.match(text, /\{\s*name:\s*'ast',\s*fn:\s*astScan\s*\}/);
|
||||
});
|
||||
});
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// Policy — enabled:false short-circuits to skipped (Step 6)
|
||||
// ---------------------------------------------------------------------------
|
||||
|
||||
describe('ast-taint-scanner: policy disable', () => {
|
||||
it('enabled:false in policy.json short-circuits to skipped', async () => {
|
||||
const dir = mkdtempSync(join(tmpdir(), 'ast-off-'));
|
||||
try {
|
||||
mkdirSync(join(dir, '.llm-security'), { recursive: true });
|
||||
writeFileSync(
|
||||
join(dir, '.llm-security', 'policy.json'),
|
||||
JSON.stringify({ ast: { enabled: false } }),
|
||||
);
|
||||
writeFileSync(join(dir, 'a.py'), 'import os\nk = os.environ["X"]\neval(k)\n');
|
||||
resetCounter();
|
||||
const discovery = await discoverFiles(dir);
|
||||
const result = await scan(dir, discovery);
|
||||
assert.equal(result.status, 'skipped');
|
||||
assert.equal(result.findings.length, 0);
|
||||
} finally {
|
||||
rmSync(dir, { recursive: true, force: true });
|
||||
}
|
||||
});
|
||||
});
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue