mirror of
https://github.com/openai/codex-security.git
synced 2026-11-25 02:58:16 +08:00
Co-authored-by: mldangelo-oai <269034524+mldangelo-oai@users.noreply.github.com>
54 lines
1.8 KiB
TypeScript
54 lines
1.8 KiB
TypeScript
import { gradeFailures, outputText, hasTriageJson } from "./output.mts";
|
|
|
|
function matchedFormatNames(text: string) {
|
|
const supportedFormats: [string, RegExp][] = [
|
|
["SARIF", /\bSARIF\b/i],
|
|
["CVE", /\bCVE\b/i],
|
|
["advisory", /\badvisor(?:y|ies)\b/i],
|
|
["scanner ticket", /\bscanner\b|\bticket\b/i],
|
|
["bug bounty report", /\bbug bounty\b/i],
|
|
["Codex Security finding", /\bCodex Security\b|\bfinding artifact\b/i],
|
|
[
|
|
"freeform claim",
|
|
/\bfreeform\b|\bplain[- ]language\b|\bvulnerability claim\b/i,
|
|
],
|
|
];
|
|
|
|
return supportedFormats
|
|
.filter(([, pattern]) => pattern.test(text))
|
|
.map(([name]) => name);
|
|
}
|
|
|
|
export default (output: unknown) => {
|
|
const text = outputText(output);
|
|
const failures = [];
|
|
const promptForInputPattern =
|
|
/\b(provide|paste|share|send|supply|include)\b[\s\S]{0,120}\b(finding|input|SARIF|CVE|advisory|scanner|ticket|bug bounty|report|artifact|claim)\b/i;
|
|
const inputBeforeVerbPattern =
|
|
/\b(finding|input|SARIF|CVE|advisory|scanner|ticket|bug bounty|report|artifact|claim)\b[\s\S]{0,120}\b(provide|paste|share|send|supply|include)\b/i;
|
|
|
|
if (!promptForInputPattern.test(text) && !inputBeforeVerbPattern.test(text)) {
|
|
failures.push(
|
|
"response must ask the user to provide, paste, share, send, or include a finding/input",
|
|
);
|
|
}
|
|
|
|
const formats = matchedFormatNames(text);
|
|
if (formats.length < 4) {
|
|
failures.push(
|
|
`response must mention at least four supported input formats; matched ${formats.length}: ${formats.join(", ")}`,
|
|
);
|
|
}
|
|
|
|
if (hasTriageJson(text)) {
|
|
failures.push(
|
|
"response must not emit a triage result JSON object when no finding was supplied",
|
|
);
|
|
}
|
|
|
|
return gradeFailures(
|
|
failures,
|
|
"Missing-input response asks for a finding and names supported formats without triage JSON.",
|
|
);
|
|
};
|