Thanks for your interest in making AI agent security better! 🛡️
git clone https://github.com/elliotllliu/agent-shield.git
cd agent-shield
npm install
npm run build
npm test- Create
src/rules/your-rule.tsimplementing theRuleinterface:
import type { Rule, Finding, ScannedFile } from "../types.js";
export const yourRule: Rule = {
id: "your-rule",
name: "Human Readable Name",
description: "What this rule detects",
run(files: ScannedFile[]): Finding[] {
const findings: Finding[] = [];
// Your detection logic here
return findings;
},
};- Register it in
src/rules/index.ts:
import { yourRule } from "./your-rule.js";
export const rules: Rule[] = [
// ... existing rules
yourRule,
];- Add tests in
tests/rules/your-rule.test.ts:
import { describe, it } from "node:test";
import assert from "node:assert";
import { yourRule } from "../../src/rules/your-rule.js";
import { makeFile } from "../helpers.js";
describe("your-rule", () => {
it("should detect the vulnerability", () => {
const files = [makeFile("index.ts", `vulnerable code here`)];
const findings = yourRule.run(files);
assert.ok(findings.length > 0);
assert.strictEqual(findings[0].severity, "critical");
});
it("should not flag safe code", () => {
const files = [makeFile("index.ts", `safe code here`)];
const findings = yourRule.run(files);
assert.strictEqual(findings.length, 0);
});
});- Add test fixtures if needed in
tests/fixtures/
- Each rule should have at least 2 tests: one detecting the issue, one verifying no false positive
- Use
warningseverity for patterns that might be legitimate;criticalfor almost-certainly malicious - Keep false positive rates low — it's better to miss an edge case than to flood users with noise
- Add the rule to the README table
- TypeScript strict mode
- No
anytypes - Prefer
constoverlet - Functions should be small and focused
- Fork the repo
- Create a branch:
git checkout -b feat/your-feature - Make your changes
- Run
npm testto ensure all tests pass - Run
npm run buildto ensure TypeScript compiles - Commit with a descriptive message
- Open a PR
By contributing, you agree that your contributions will be licensed under the MIT License.