npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

@scicco/opencode-sql-security-guardrails

v0.3.0

Published

OpenCode plugin and skill templates for SQL security guardrails.

Readme

opencode-sql-security-guardrails

OpenCode plugin and skill templates for SQL security guardrails.

This package adds tools, CLI commands, and project instructions that help OpenCode detect and review SQL-bearing code changes for:

  • SQL injection;
  • unsafe dynamic identifiers;
  • unsafe raw SQL execution;
  • missing user/project scoping;
  • sensitive SQL logging and API error exposure.

The intended workflow is:

  1. run lint and tests;
  2. run the SQL scanner tool or CLI command;
  3. if SQL-bearing files are detected, run the sql-security-review skill;
  4. block task completion if the review returns SQL_SECURITY_REVIEW: KO.

What this package provides

OpenCode plugin tools

The plugin exposes these tools:

sql_raw_query_scanner

Scans changed, staged, or all project files and returns a JSON list of files that likely contain raw SQL, database query calls, SQL strings, or SQL-building patterns.

Example output:

{
  "mode": "changed",
  "count": 1,
  "files": [
    {
      "name": "example.js",
      "path": "src/example.js",
      "reasons": [
        "SQL-like template literal contains interpolation",
        "database query execution call"
      ],
      "locations": [
        {
          "line": 12,
          "kind": "sql-template-interpolation",
          "severity": "high",
          "preview": "return db.query(`SELECT * FROM users WHERE id = ${userId}`)"
        }
      ]
    }
  ]
}

sql_security_review_context

Builds a review context containing:

  • scanner output;
  • relevant git diff;
  • contents of detected files;
  • instructions for the sql-security-review skill.

Use this tool before invoking the review skill.

CLI command

The package also exposes a CLI command:

opencode-sql-security-guardrails

Supported commands:

opencode-sql-security-guardrails init [options]
opencode-sql-security-guardrails scan [options]
opencode-sql-security-guardrails help
opencode-sql-security-guardrails version

The scan command is intended for Git hooks, CI jobs, and local deterministic checks.

Recommended pre-commit usage:

opencode-sql-security-guardrails scan --staged --fail-on high

While developing from a local checkout before publishing the package, you can run the compiled CLI directly:

node /absolute/path/to/opencode-sql-security-guardrails/dist/bin/init.js scan --staged --fail-on high

CLI scan options

--changed          Scan staged, unstaged, and untracked files
--staged           Scan only staged files
--all              Scan all tracked files
--mode=<mode>      Alternative mode syntax: changed, staged, all
--fail-on <level>  Exit with code 1 when findings are at or above: info, low, medium, high
--json             Print machine-readable JSON output

Examples:

opencode-sql-security-guardrails scan --staged --fail-on high
opencode-sql-security-guardrails scan --changed --fail-on medium --json
opencode-sql-security-guardrails scan --all --fail-on high

A scan exits with code 1 when blocking findings are detected at or above the configured --fail-on severity. This makes it suitable for pre-commit hooks.

Skill template

The package includes:

templates/skills/sql-security-review/SKILL.md

The init command installs it to:

.opencode/skills/sql-security-review/SKILL.md

AGENTS.md guardrail snippet

The package includes:

templates/AGENTS.sql-security.md

The init command appends it to:

AGENTS.md

inside a managed block:

<!-- opencode-sql-security-guardrails:start -->

...
<!-- opencode-sql-security-guardrails:end -->

This makes the guardrail visible to OpenCode in future sessions.

Installation during local development

From this plugin repository:

npm install
npm run build
npm link

In the target project:

npm link @scicco/opencode-sql-security-guardrails

Then configure OpenCode.

If npm link is not available or the package has not been published yet, use the local proxy plugin approach described below.

Configure OpenCode

Option A: npm plugin configuration

Add this to the target project's root opencode.json:

{
  "$schema": "https://opencode.ai/config.json",
  "plugin": ["@scicco/opencode-sql-security-guardrails"]
}

Restart OpenCode after changing plugin configuration.

Option B: local proxy plugin for development

If OpenCode does not resolve the linked package during development, create:

.opencode/plugins/sql-security-guardrails.js

with:

export { default } from "/absolute/path/to/opencode-sql-security-guardrails/dist/src/index.js"

Then restart OpenCode.

This proxy approach is useful while developing the plugin locally.

Do not commit a proxy plugin that contains an absolute path to a local machine.

Install the skill and AGENTS.md guardrail

In the target project:

opencode-sql-security-guardrails init

This creates or updates:

.opencode/skills/sql-security-review/SKILL.md
AGENTS.md

Init options

Overwrite existing managed files/block:

opencode-sql-security-guardrails init --force

Install the skill but do not modify AGENTS.md:

opencode-sql-security-guardrails init --no-agents

Show help:

opencode-sql-security-guardrails --help

Show version:

opencode-sql-security-guardrails version

Recommended OpenCode workflow

After changing code that may contain SQL, ask OpenCode to run:

Use the sql_raw_query_scanner tool with mode changed. Then print the exact tool output verbatim, without summarizing it.

If the scanner returns one or more files, ask:

Use the sql_security_review_context tool with mode changed. Then invoke the sql-security-review skill using that context.

Expected safe result:

SQL_SECURITY_REVIEW: OK

Expected unsafe result:

SQL_SECURITY_REVIEW: KO

When the result is KO, OpenCode should fix the findings and repeat:

  1. lint;
  2. tests;
  3. scanner;
  4. review context;
  5. SQL security review.

Do not mark the task complete while SQL security review is KO.

Recommended Git hook workflow

The CLI scan command can be used in a pre-commit hook to block commits that contain high-severity SQL findings.

Recommended command:

opencode-sql-security-guardrails scan --staged --fail-on high

For unpublished local plugin development:

node /absolute/path/to/opencode-sql-security-guardrails/dist/bin/init.js scan --staged --fail-on high

Recommended policy:

  • high findings block commits;
  • medium and info findings remain visible in scanner output but should not block commits by default;
  • semantic review remains the responsibility of the sql-security-review skill inside OpenCode.

Scanner modes

Changed files

mode=changed

Scans:

  • unstaged changes;
  • staged changes;
  • untracked files.

This is the recommended mode during normal OpenCode development.

Staged files

mode=staged

Scans only files staged for commit:

git diff --cached --name-only

This is the recommended mode for pre-commit hooks.

All tracked files

mode=all

Scans all tracked source files in the repository.

This is useful for baseline audits.

Project configuration

Projects can optionally add:

.sql-security-guardrails.json

If you want to start from the example configuration shipped with this repository, copy it with:

cp .sql-security-guardrails.example.json .sql-security-guardrails.json

Example:

{
  "ignoredPaths": ["fixtures/**", "testdata/**"],
  "extraQueryCallPatterns": ["analyticsDb.query", "tenantDb.raw"],
  "minimumSeverity": "info"
}

ignoredPaths

Additional project-specific paths to ignore.

Supports simple glob-like patterns:

  • fixtures/**
  • testdata/*.js
  • generated

A pattern without * matches the exact path or anything below that directory. For example, generated matches both generated and generated/file.js.

extraQueryCallPatterns

Additional query execution call names to detect.

Example:

{
  "extraQueryCallPatterns": ["analyticsDb.query", "tenantDb.raw"]
}

A pattern such as analyticsDb.query detects calls like:

analyticsDb.query("SELECT * FROM events")

This is useful for project-specific database wrappers that are not covered by the default scanner rules.

minimumSeverity

Minimum finding severity to include in scanner output.

Allowed values:

info
low
medium
high

Default:

info

For example, this configuration reports only high-severity scanner findings:

{
  "minimumSeverity": "high"
}

Use this carefully. The scanner is a candidate detector, not the final security reviewer. Filtering out lower-severity findings can reduce noise, but it may also hide useful context from the sql-security-review skill.

Detection behavior

The scanner looks for patterns such as:

  • db.query(...);
  • client.query(...);
  • pool.query(...);
  • userDbPool.query(...);
  • copyFromStream(...);
  • knex.raw(...);
  • SQL template tags;
  • SQL keywords such as SELECT, INSERT INTO, UPDATE, DELETE FROM;
  • dynamic template interpolation inside SQL-like strings;
  • SQL-like string concatenation;
  • ORDER BY, LIMIT, OFFSET, RETURNING.

The scanner is intentionally conservative. It identifies candidate files for semantic review; it does not decide whether the code is safe.

The sql-security-review skill is responsible for deciding OK or KO.

Development

Install dependencies:

npm install

Run formatter:

npm run format

Run linter:

npm run lint

Run TypeScript check:

npm run check

Run tests:

npm run test:all

Build:

npm run build

Full local verification:

npm run format
npm run lint
npm run check
npm run test:all
npm run build
npm pack --dry-run

VS Code setup

This repository is intended to be used with:

  • Prettier for formatting;
  • ESLint for linting;
  • format on save enabled.

Recommended VS Code extensions:

esbenp.prettier-vscode
dbaeumer.vscode-eslint

Repository structure

opencode-sql-security-guardrails/
  bin/
    init.ts
  src/
    config.ts
    index.ts
    review-context.ts
    scanner.ts
    severity.ts
  templates/
    AGENTS.sql-security.md
    skills/
      sql-security-review/
        SKILL.md
  tests/
    config.test.ts
    init-cli.test.ts
    review-context.test.ts
    scanner.test.ts
  package.json
  tsconfig.json
  tsconfig.build.json
  eslint.config.js
  README.md

License

MIT