@scicco/opencode-sql-security-guardrails
v0.3.0
Published
OpenCode plugin and skill templates for SQL security guardrails.
Maintainers
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:
- run lint and tests;
- run the SQL scanner tool or CLI command;
- if SQL-bearing files are detected, run the
sql-security-reviewskill; - 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-reviewskill.
Use this tool before invoking the review skill.
CLI command
The package also exposes a CLI command:
opencode-sql-security-guardrailsSupported commands:
opencode-sql-security-guardrails init [options]
opencode-sql-security-guardrails scan [options]
opencode-sql-security-guardrails help
opencode-sql-security-guardrails versionThe 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 highWhile 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 highCLI 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 outputExamples:
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 highA 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.mdThe init command installs it to:
.opencode/skills/sql-security-review/SKILL.mdAGENTS.md guardrail snippet
The package includes:
templates/AGENTS.sql-security.mdThe init command appends it to:
AGENTS.mdinside 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 linkIn the target project:
npm link @scicco/opencode-sql-security-guardrailsThen 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.jswith:
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 initThis creates or updates:
.opencode/skills/sql-security-review/SKILL.md
AGENTS.mdInit options
Overwrite existing managed files/block:
opencode-sql-security-guardrails init --forceInstall the skill but do not modify AGENTS.md:
opencode-sql-security-guardrails init --no-agentsShow help:
opencode-sql-security-guardrails --helpShow version:
opencode-sql-security-guardrails versionRecommended 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: OKExpected unsafe result:
SQL_SECURITY_REVIEW: KOWhen the result is KO, OpenCode should fix the findings and repeat:
- lint;
- tests;
- scanner;
- review context;
- 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 highFor unpublished local plugin development:
node /absolute/path/to/opencode-sql-security-guardrails/dist/bin/init.js scan --staged --fail-on highRecommended policy:
highfindings block commits;mediumandinfofindings remain visible in scanner output but should not block commits by default;- semantic review remains the responsibility of the
sql-security-reviewskill inside OpenCode.
Scanner modes
Changed files
mode=changedScans:
- unstaged changes;
- staged changes;
- untracked files.
This is the recommended mode during normal OpenCode development.
Staged files
mode=stagedScans only files staged for commit:
git diff --cached --name-onlyThis is the recommended mode for pre-commit hooks.
All tracked files
mode=allScans all tracked source files in the repository.
This is useful for baseline audits.
Project configuration
Projects can optionally add:
.sql-security-guardrails.jsonIf you want to start from the example configuration shipped with this repository, copy it with:
cp .sql-security-guardrails.example.json .sql-security-guardrails.jsonExample:
{
"ignoredPaths": ["fixtures/**", "testdata/**"],
"extraQueryCallPatterns": ["analyticsDb.query", "tenantDb.raw"],
"minimumSeverity": "info"
}ignoredPaths
Additional project-specific paths to ignore.
Supports simple glob-like patterns:
fixtures/**testdata/*.jsgenerated
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
highDefault:
infoFor 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 installRun formatter:
npm run formatRun linter:
npm run lintRun TypeScript check:
npm run checkRun tests:
npm run test:allBuild:
npm run buildFull local verification:
npm run format
npm run lint
npm run check
npm run test:all
npm run build
npm pack --dry-runVS 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-eslintRepository 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.mdLicense
MIT
