Skip to content

OpenAI's Codex Security CLI and TypeScript SDK for finding, validating, and fixing security vulnerabilities. npm: https://www.npmjs.com/package/@openai/codex-security

1.8 KB
Raw Blame
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.",
  );
};