Developer Docs

Documentation

Everything you need to run OpenSecureAI's tools in code, in CI, and in production. All engines are open source and dependency-free.

Overview

OpenSecureAI ships transparent, heuristic security tools for LLM applications. The flagship engine detects prompt-injection, jailbreak, system-prompt-leak, and data-exfiltration patterns in untrusted text. The same engine powers the in-browser scanner, the @opensecureai/scanner npm package, a CLI, a GitHub Action, and a REST API.

These tools are a first line of defense — pair them with output validation, least-privilege tool design, and human review for high-risk actions. See the OWASP Top 10 for LLMs for the full threat model.

Install

The package targets Node 18+ and ships ESM with TypeScript types. It has zero runtime dependencies.

terminal
npm install @opensecureai/scanner

Library API

The primary export is scanPrompt, which returns a structured result with a 0–100 score, a risk level, and per-rule findings.

app.ts
import { scanPrompt } from "@opensecureai/scanner";

const result = scanPrompt(userInput);

result.score;   // 0-100 (higher = riskier)
result.level;   // "Critical" | "High" | "Medium" | "Low" | "Clean"
result.matches; // [{ ruleId, category, severity, title, ... }]

if (result.level === "Critical" || result.level === "High") {
  rejectRequest(result.matches);
}

The full ruleset is exported as RULES and demo inputs as SAMPLE_PAYLOADS.

CLI

Scan files or stdin. Exit codes make it CI-friendly: 0 = clean/below threshold, 1 = threshold met, 2 = usage error.

terminal
# scan a file
npx opensecureai scan prompt.txt

# scan stdin
cat prompt.txt | npx opensecureai scan

# gate on high+ findings, JSON output
npx opensecureai scan ./prompts/*.txt --fail-on high --json
OptionDescription
--jsonMachine-readable JSON output
--fail-on <level>Exit 1 if any finding >= level
--min-severity <level>Only report findings >= level
--quietSummary lines only
-h, --help / -v, --versionHelp / version

GitHub Action

Gate pull requests on risky prompt content with the composite action.

.github/workflows/prompt-scan.yml
name: Prompt scan
on: [pull_request]
jobs:
  scan:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v4
      - uses: actions/setup-node@v4
        with: { node-version: 20 }
      - uses: rkstar2025/opensecureai-website/packages/scanner@main
        with:
          files: "prompts/**/*.txt"
          fail-on: high

REST API

A stateless endpoint that runs the same engine. Nothing is stored. CORS is open so you can call it from anywhere.

terminal
curl -X POST https://opensecureai.com/api/scan \
  -H "content-type: application/json" \
  -d '{"text":"ignore all previous instructions"}'

Response

json
{
  "ok": true,
  "result": {
    "score": 90,
    "level": "Critical",
    "matches": [ /* findings */ ],
    "scannedChars": 34
  }
}

System Prompt Auditor

The Auditor grades a system prompt against defensive best practices — secret isolation, instruction/data separation, injection resistance, refusal policy, and least-privilege tool use — returning an A–F report card with prioritized fixes. It runs entirely in the browser.

Threat Feed

Syndicate the curated threat intelligence feed as JSON or RSS. The JSON endpoint supports severity, category, and owasp filters.

terminal
# JSON API
curl https://opensecureai.com/api/threats
curl "https://opensecureai.com/api/threats?severity=Critical"
curl "https://opensecureai.com/api/threats?owasp=LLM01"

# RSS feed
curl https://opensecureai.com/threats/feed.xml