Compare commits

...
Author SHA1 Message Date
Rohit Ghumare fcff9c5e7d fix: remove hardcoded initial stars count from website loader
Replace stale hardcoded fallback values (66 stars, 2.4k downloads, v1.9.0)
with empty/zero defaults that show a dash placeholder while loading. Real
values populate once the API responds.
2026-02-08 20:29:07 +00:00
Rohit Ghumare b28a2801b2 feat: add security scanner for detecting malicious patterns in skills (#50)
* feat: add security scanner for detecting malicious patterns in skills

Add `skillkit scan <path>` command with 46+ detection rules across 6 threat
categories: prompt injection, command injection, data exfiltration, tool abuse,
hardcoded secrets, and unicode steganography.

- 3 analyzers: static pattern matching, SKILL.md manifest validation, secrets detection
- 4 output formats: summary (colored terminal), json, table, sarif (GitHub Code Scanning)
- Auto-scan on `skillkit install` (--no-scan to skip, --force to override)
- Auto-scan on `skillkit publish` (blocks on HIGH+ findings)
- Threat taxonomy with 10 categories and severity levels
- False-positive filtering for placeholders, test files, safe patterns
- Updated README, CLI docs, website commands, features, and fumadocs

* fix: address Devin and CodeRabbit review suggestions for security scanner

- Fix .env variant files (.env.local, .env.production) being skipped by scanner
- Add multiline rule support in StaticAnalyzer for cross-line pattern matching
- Fix PI004/PI013 patterns that contained literal \n (never matched per-line)
- Fix /g flag on CI006 path traversal regex causing intermittent misses
- Fix frontmatter regex to handle Windows CRLF line endings
- Fix allowed-tools parsing to detect multi-line YAML arrays
- Fix snippet redaction order: redact before truncate to prevent secret leaks
- Reset findingCounter per analyze() call for deterministic finding IDs
- Make SARIF artifactLocation.uri relative to skillPath for GitHub Code Scanning
- Use basename() instead of split('/').pop() for cross-platform paths
- Inject package version at build time via tsup define (replaces hardcoded 1.0.0)
- Validate --fail-on and --format CLI options with clear error messages
- Remove unused format/quiet from ScanOptions interface
- Move publish scan after name validation to avoid blocking on invalid skills
- Add excludePatterns for jailbreak detection to reduce false positives
- Add biome suppression for intentional control character regex in UC005
- Use alternation instead of character class for ZWJ in UC001

* fix: address CodeRabbit round 2 review suggestions

- Remove unused --quiet option from scan command
- Update OpenAI API key pattern to detect sk-proj- and sk-admin- prefixes

* fix: address deep review issues in security scanner

- SK001: add negative lookahead to prevent matching Anthropic keys
- static.ts: fix multiline loop hang for non-global regex with filtered matches
- CI005: reduce severity to MEDIUM, expand excludePatterns for template literals
- CI006: reduce severity to MEDIUM, add fileTypes whitelist, exclude markdown/YAML patterns
- PI011: fix literal \n in regex, use $/im for end-of-line matching
- UC004: use \u{...} notation for supplementary codepoint range
- scanner.ts: propagate skipRules to ManifestAnalyzer and SecretsAnalyzer
2026-02-08 12:56:45 +00:00
31 changed files with 1856 additions and 16 deletions
+2 -1
View File
@@ -223,12 +223,13 @@ skillkit generate # AI skill generation wizard
skillkit serve # Start REST API server
```
### Discovery
### Discovery & Security
```bash
skillkit marketplace # Browse skills
skillkit tree # Hierarchical taxonomy
skillkit find <query> # Quick search
skillkit scan <path> # Security scan for skills
```
### Advanced
+2
View File
@@ -103,6 +103,7 @@ import {
SkillMdInitCommand,
SkillMdCheckCommand,
ServeCommand,
ScanCommand,
} from '@skillkit/cli';
const __filename = fileURLToPath(import.meta.url);
@@ -231,5 +232,6 @@ cli.register(SkillMdInitCommand);
cli.register(SkillMdCheckCommand);
cli.register(ServeCommand);
cli.register(ScanCommand);
cli.runExit(process.argv.slice(2));
+34
View File
@@ -362,6 +362,40 @@ skillkit publish --dry-run # Preview without writing
skillkit publish submit # Submit to SkillKit marketplace
```
## Security Scanning
```bash
skillkit scan <path> # Scan skill for vulnerabilities
skillkit scan <path> --format json # Output as JSON
skillkit scan <path> --format table # Tabular output
skillkit scan <path> --format sarif # SARIF for GitHub Code Scanning
skillkit scan <path> --fail-on high # Exit 1 if HIGH+ findings
skillkit scan <path> --skip-rules UC001 # Skip specific rules
skillkit scan <path> --quiet # Suppress non-essential output
```
**Threat Categories:**
| Category | Description |
|----------|-------------|
| Prompt Injection | Override/bypass agent instructions |
| Command Injection | eval(), exec(), shell commands |
| Data Exfiltration | Webhook URLs, env var reads, credential access |
| Tool Abuse | Tool shadowing, autonomy escalation |
| Hardcoded Secrets | API keys, tokens, private keys |
| Unicode Steganography | Zero-width chars, bidi overrides |
**Install Integration:**
Skills are automatically scanned during `skillkit install`. Use `--no-scan` to skip, or `--force` to install despite findings.
**Output Formats:**
- `summary` (default) - colored terminal output
- `json` - machine-readable JSON
- `table` - tabular format
- `sarif` - SARIF v2.1 for GitHub Code Scanning / IDE integration
## Interactive TUI
```bash
@@ -33,6 +33,15 @@ const COMMAND_GROUPS: CommandGroup[] = [
{ cmd: 'publish', desc: 'Submit to marketplace' },
],
},
{
name: 'Security',
commands: [
{ cmd: 'scan <path>', desc: 'Security vulnerability scanner' },
{ cmd: 'scan --format sarif', desc: 'SARIF for GitHub Code Scanning' },
{ cmd: 'scan --fail-on high', desc: 'CI security gate' },
{ cmd: 'audit log', desc: 'View audit trail' },
],
},
{
name: 'Advanced',
commands: [
+5 -5
View File
@@ -123,7 +123,7 @@ export default function App(): React.ReactElement {
<svg className="w-3.5 h-3.5 text-zinc-500 group-hover:text-yellow-500 transition-colors" fill="currentColor" viewBox="0 0 24 24">
<path d="M12 2l3.09 6.26L22 9.27l-5 4.87 1.18 6.88L12 17.77l-6.18 3.25L7 14.14 2 9.27l6.91-1.01L12 2z" />
</svg>
<span className="text-xs font-mono text-zinc-400 group-hover:text-white transition-colors">{stats.stars}</span>
<span className="text-xs font-mono text-zinc-400 group-hover:text-white transition-colors">{stats.stars || '—'}</span>
</a>
</div>
</div>
@@ -131,7 +131,7 @@ export default function App(): React.ReactElement {
</nav>
<main className="pt-14">
<Hero version={stats.version} stars={stats.stars} />
<Hero version={stats.version || '—'} stars={stats.stars || '—'} />
<div className="border-b border-zinc-800/50 py-2.5" style={{ background: 'linear-gradient(to bottom, rgba(9,9,11,0.95), rgba(0,0,0,1))' }}>
<div className="mx-auto max-w-5xl px-4 sm:px-6 lg:px-8">
@@ -143,7 +143,7 @@ export default function App(): React.ReactElement {
className="flex items-center gap-1.5 text-zinc-500 hover:text-white transition-colors group"
>
<span className="text-zinc-600 group-hover:text-zinc-400">v</span>
<span className="text-white font-medium">{stats.version}</span>
<span className="text-white font-medium">{stats.version || '—'}</span>
</a>
<span className="text-zinc-800">·</span>
<a
@@ -155,7 +155,7 @@ export default function App(): React.ReactElement {
<svg className="w-3 h-3 text-zinc-600 group-hover:text-zinc-400" fill="none" viewBox="0 0 24 24" stroke="currentColor">
<path strokeLinecap="round" strokeLinejoin="round" strokeWidth={2} d="M4 16v1a3 3 0 003 3h10a3 3 0 003-3v-1m-4-4l-4 4m0 0l-4-4m4 4V4" />
</svg>
<span className="text-white font-medium">{stats.downloads}</span>
<span className="text-white font-medium">{stats.downloads || '—'}</span>
</a>
<span className="text-zinc-800">·</span>
<a
@@ -167,7 +167,7 @@ export default function App(): React.ReactElement {
<svg className="w-3 h-3 text-zinc-600 group-hover:text-yellow-500" fill="currentColor" viewBox="0 0 24 24">
<path d="M12 2l3.09 6.26L22 9.27l-5 4.87 1.18 6.88L12 17.77l-6.18 3.25L7 14.14 2 9.27l6.91-1.01L12 2z" />
</svg>
<span className="text-white font-medium">{stats.stars}</span>
<span className="text-white font-medium">{stats.stars || '—'}</span>
</a>
<span className="text-zinc-800 hidden sm:inline">·</span>
<a
+11
View File
@@ -82,6 +82,17 @@ const COMMAND_GROUPS: CommandGroup[] = [
{ cmd: 'serve --cache-ttl 3600000', desc: 'Cache TTL' },
],
},
{
name: 'Security',
commands: [
{ cmd: 'scan <path>', desc: 'Security scan' },
{ cmd: 'scan --format sarif', desc: 'SARIF output' },
{ cmd: 'scan --fail-on high', desc: 'CI gate' },
{ cmd: 'install --no-scan', desc: 'Skip scan' },
{ cmd: 'audit log', desc: 'View audit logs' },
{ cmd: 'validate', desc: 'Validate format' },
],
},
{
name: 'Advanced',
commands: [
+10
View File
@@ -70,6 +70,15 @@ const FEATURES: Feature[] = [
</svg>
)
},
{
title: 'Security Scanner',
description: 'Detect prompt injection, secrets, and malicious patterns in skills.',
icon: (
<svg className="w-5 h-5" fill="none" viewBox="0 0 24 24" stroke="currentColor">
<path strokeLinecap="round" strokeLinejoin="round" strokeWidth={1.5} d="M9 12.75L11.25 15 15 9.75m-3-7.036A11.959 11.959 0 013.598 6 11.99 11.99 0 003 9.749c0 5.592 3.824 10.29 9 11.623 5.176-1.332 9-6.03 9-11.622 0-1.31-.21-2.571-.598-3.751h-.152c-3.196 0-6.1-1.248-8.25-3.285z" />
</svg>
)
},
{
title: 'Testing',
description: 'Built-in test framework with assertions.',
@@ -106,6 +115,7 @@ const COMPARISONS = [
['Translation', 'Rewrite for each', 'One-click conversion'],
['Team Sharing', 'Copy/paste files', '.skills manifest'],
['Discovery', 'Search forums', 'AI recommendations'],
['Security', 'Manual review', 'Auto-scan on install'],
['API Access', 'None', 'REST + MCP + Python'],
] as const;
+1 -1
View File
@@ -169,7 +169,7 @@ export function Hero({ version, stars }: HeroProps): React.ReactElement {
<path fillRule="evenodd" d="M12 2C6.477 2 2 6.484 2 12.017c0 4.425 2.865 8.18 6.839 9.504.5.092.682-.217.682-.483 0-.237-.008-.868-.013-1.703-2.782.605-3.369-1.343-3.369-1.343-.454-1.158-1.11-1.466-1.11-1.466-.908-.62.069-.608.069-.608 1.003.07 1.531 1.032 1.531 1.032.892 1.53 2.341 1.088 2.91.832.092-.647.35-1.088.636-1.338-2.22-.253-4.555-1.113-4.555-4.951 0-1.093.39-1.988 1.029-2.688-.103-.253-.446-1.272.098-2.65 0 0 .84-.27 2.75 1.026A9.564 9.564 0 0112 6.844c.85.004 1.705.115 2.504.337 1.909-1.296 2.747-1.027 2.747-1.027.546 1.379.202 2.398.1 2.651.64.7 1.028 1.595 1.028 2.688 0 3.848-2.339 4.695-4.566 4.943.359.309.678.92.678 1.855 0 1.338-.012 2.419-.012 2.747 0 .268.18.58.688.482A10.019 10.019 0 0022 12.017C22 6.484 17.522 2 12 2z" clipRule="evenodd" />
</svg>
<span className="font-mono text-sm text-zinc-300 group-hover:text-white transition-colors">Star</span>
{typeof stars === 'number' && (
{typeof stars === 'number' && stars > 0 && (
<>
<span className="w-px h-4 bg-zinc-700"></span>
<svg className="w-3.5 h-3.5 text-yellow-500" fill="currentColor" viewBox="0 0 24 24">
+6 -6
View File
@@ -54,9 +54,9 @@ function setCachedStats(data: Omit<Stats, 'loading'>): void {
export function useStats(): Stats {
const [stats, setStats] = useState<Stats>({
version: '1.9.0',
downloads: '2.4k',
stars: 66,
version: '',
downloads: '',
stars: 0,
loading: true,
});
@@ -74,9 +74,9 @@ export function useStats(): Stats {
fetch('https://api.github.com/repos/rohitg00/skillkit'),
]);
let downloads = '2.4k';
let stars = 66;
let version = '1.9.0';
let downloads = '';
let stars = 0;
let version = '';
if (npmResponse.status === 'fulfilled' && npmResponse.value.ok) {
const npmData = await npmResponse.value.json();
+15
View File
@@ -159,6 +159,20 @@ skillkit command generate <agent> # Generate agent-native commands
skillkit command list <agent> # List available commands
```
### Security Scanning
```bash
skillkit scan <path> # Scan skill for vulnerabilities
skillkit scan <path> --format json # Output as JSON
skillkit scan <path> --format sarif # SARIF for GitHub Code Scanning
skillkit scan <path> --fail-on high # Exit code 1 if HIGH+ findings
skillkit scan <path> --skip-rules UC001,UC002 # Skip specific rules
```
Detects: prompt injection, command injection, data exfiltration, tool abuse, hardcoded secrets, unicode steganography.
Skills are automatically scanned during `install` (use `--no-scan` to skip) and `publish`.
### Utilities
```bash
@@ -184,6 +198,7 @@ skillkit install ./local/path # Local directory
--yes # Skip confirmation prompts
--global # Install globally
--force # Overwrite existing
--no-scan # Skip security scan
--agent=cursor,windsurf # Install to specific agents
```
+1
View File
@@ -118,3 +118,4 @@ export { SkillMdValidateCommand, SkillMdInitCommand, SkillMdCheckCommand } from
// API server
export { ServeCommand } from './serve.js';
export { ScanCommand } from './scan.js';
+28 -1
View File
@@ -5,7 +5,7 @@ import { promisify } from 'node:util';
const execFileAsync = promisify(execFile);
import { Command, Option } from 'clipanion';
import { detectProvider, isLocalPath, getProvider, evaluateSkillDirectory } from '@skillkit/core';
import { detectProvider, isLocalPath, getProvider, evaluateSkillDirectory, SkillScanner, formatSummary, Severity } from '@skillkit/core';
import type { SkillMetadata, GitProvider, AgentType } from '@skillkit/core';
import { isPathInside } from '@skillkit/core';
import { getAdapter, detectAgent, getAllAdapters } from '@skillkit/agents';
@@ -94,6 +94,10 @@ export class InstallCommand extends Command {
description: 'Minimal output (no logo)',
});
scan = Option.Boolean('--scan', true, {
description: 'Run security scan before installing (default: true)',
});
async execute(): Promise<number> {
const isInteractive = process.stdin.isTTY && !this.skills && !this.all && !this.yes;
const s = spinner();
@@ -259,6 +263,29 @@ export class InstallCommand extends Command {
}
}
if (this.scan) {
const scanner = new SkillScanner({ failOnSeverity: Severity.HIGH });
for (const skill of skillsToInstall) {
const scanResult = await scanner.scan(skill.path);
if (scanResult.verdict === 'fail' && !this.force) {
error(`Security scan FAILED for "${skill.name}"`);
console.log(formatSummary(scanResult));
console.log(colors.muted('Use --force to install anyway, or --no-scan to skip scanning'));
const cleanupPath = result.tempRoot || result.path;
if (!isLocalPath(this.source) && cleanupPath && existsSync(cleanupPath)) {
rmSync(cleanupPath, { recursive: true, force: true });
}
return 1;
}
if (scanResult.verdict === 'warn' && !this.quiet) {
warn(`Security warnings for "${skill.name}" (${scanResult.stats.medium} medium, ${scanResult.stats.low} low)`);
}
}
}
// Confirm installation
if (isInteractive && !this.yes) {
console.log('');
+15 -2
View File
@@ -2,7 +2,7 @@ import { existsSync, readFileSync, mkdirSync, writeFileSync, readdirSync, statSy
import { join, basename, dirname, resolve } from 'node:path';
import chalk from 'chalk';
import { Command, Option } from 'clipanion';
import { generateWellKnownIndex, type WellKnownSkill } from '@skillkit/core';
import { generateWellKnownIndex, type WellKnownSkill, SkillScanner, formatSummary, Severity } from '@skillkit/core';
function sanitizeSkillName(name: string): string | null {
if (!name || typeof name !== 'string') return null;
@@ -72,7 +72,6 @@ export class PublishCommand extends Command {
console.log(chalk.white(`Found ${discoveredSkills.length} skill(s):\n`));
const wellKnownSkills: WellKnownSkill[] = [];
const validSkills: Array<{ name: string; safeName: string; description?: string; path: string }> = [];
for (const skill of discoveredSkills) {
@@ -95,6 +94,20 @@ export class PublishCommand extends Command {
});
}
const scanner = new SkillScanner({ failOnSeverity: Severity.HIGH });
for (const skill of validSkills) {
const scanResult = await scanner.scan(skill.path);
if (scanResult.verdict === 'fail') {
console.error(chalk.red(`\nSecurity scan FAILED for "${skill.safeName}"`));
console.error(formatSummary(scanResult));
console.error(chalk.dim('Fix security issues before publishing.'));
return 1;
}
if (scanResult.verdict === 'warn') {
console.log(chalk.yellow(` Security warnings for "${skill.safeName}" (${scanResult.findings.length} findings)`));
}
}
if (validSkills.length === 0) {
console.error(chalk.red('\nNo valid skills to publish'));
return 1;
+85
View File
@@ -0,0 +1,85 @@
import { Command, Option } from 'clipanion';
import { resolve } from 'node:path';
import { existsSync } from 'node:fs';
import { SkillScanner, formatResult, Severity } from '@skillkit/core';
const SEVERITY_MAP: Record<string, Severity> = {
critical: Severity.CRITICAL,
high: Severity.HIGH,
medium: Severity.MEDIUM,
low: Severity.LOW,
info: Severity.INFO,
};
export class ScanCommand extends Command {
static override paths = [['scan']];
static override usage = Command.Usage({
description: 'Scan a skill directory for security vulnerabilities',
details: `
Analyzes skill files for prompt injection, command injection, data exfiltration,
tool abuse, hardcoded secrets, and unicode steganography.
Outputs findings in various formats including SARIF for GitHub Code Scanning.
`,
examples: [
['Scan current directory', '$0 scan .'],
['Scan a specific skill', '$0 scan ./my-skill'],
['Output as JSON', '$0 scan ./my-skill --format json'],
['Output as SARIF', '$0 scan ./my-skill --format sarif'],
['Fail on high severity', '$0 scan ./my-skill --fail-on high'],
['Skip unicode rules', '$0 scan ./my-skill --skip-rules UC001,UC002'],
],
});
skillPath = Option.String({ required: true, name: 'path' });
format = Option.String('--format,-f', 'summary', {
description: 'Output format: summary, json, table, sarif',
});
failOn = Option.String('--fail-on', {
description: 'Exit with code 1 if findings at this severity or above (critical, high, medium, low)',
});
skipRules = Option.String('--skip-rules', {
description: 'Comma-separated rule IDs or categories to skip',
});
async execute(): Promise<number> {
const targetPath = resolve(this.skillPath);
if (!existsSync(targetPath)) {
this.context.stderr.write(`Path not found: ${targetPath}\n`);
return 1;
}
const validFormats = ['summary', 'json', 'table', 'sarif'];
if (!validFormats.includes(this.format)) {
this.context.stderr.write(`Invalid format: "${this.format}". Must be one of: ${validFormats.join(', ')}\n`);
return 1;
}
const skipRules = this.skipRules?.split(',').map((s) => s.trim()) ?? [];
let failOnSeverity: Severity | undefined;
if (this.failOn) {
failOnSeverity = SEVERITY_MAP[this.failOn.toLowerCase()];
if (!failOnSeverity) {
this.context.stderr.write(`Invalid --fail-on value: "${this.failOn}". Must be one of: ${Object.keys(SEVERITY_MAP).join(', ')}\n`);
return 1;
}
}
const scanner = new SkillScanner({
failOnSeverity,
skipRules,
});
const result = await scanner.scan(targetPath);
this.context.stdout.write(formatResult(result, this.format) + '\n');
return result.verdict === 'fail' ? 1 : 0;
}
}
+3
View File
@@ -120,3 +120,6 @@ export type { SkillReference, ParsedSkillContent } from './parser/index.js';
// Runtime Skill Injection
export * from './runtime/index.js';
// Security Scanner
export * from './scanner/index.js';
@@ -0,0 +1,6 @@
import type { Finding } from '../types.js';
export interface Analyzer {
name: string;
analyze(skillPath: string, files: string[]): Promise<Finding[]>;
}
@@ -0,0 +1,212 @@
import { readFile } from 'node:fs/promises';
import { extname } from 'node:path';
import type { Analyzer } from './base.js';
import type { Finding } from '../types.js';
import { Severity, ThreatCategory } from '../types.js';
const DANGEROUS_TOOLS = new Set(['Bash', 'bash', 'shell', 'terminal', 'exec', 'system']);
const IMPERSONATION_PATTERNS = [
/official\s+(?:anthropic|openai|google|microsoft|meta)\s+(?:tool|skill|plugin)/i,
/(?:anthropic|openai|google|microsoft|meta)\s+certified/i,
/endorsed\s+by\s+(?:anthropic|openai|google|microsoft|meta)/i,
];
const BINARY_EXTENSIONS = new Set([
'.exe', '.dll', '.so', '.dylib', '.bin', '.dat',
'.zip', '.tar', '.gz', '.rar', '.7z',
'.wasm', '.pyc', '.pyo', '.class',
]);
export class ManifestAnalyzer implements Analyzer {
name = 'manifest';
private findingCounter = 0;
private skipRules: Set<string>;
constructor(skipRules?: string[]) {
this.skipRules = new Set(skipRules ?? []);
}
async analyze(_skillPath: string, files: string[]): Promise<Finding[]> {
this.findingCounter = 0;
const findings: Finding[] = [];
const skillMdFiles = files.filter((f) => f.toLowerCase().endsWith('skill.md'));
for (const skillMd of skillMdFiles) {
let content: string;
try {
content = await readFile(skillMd, 'utf-8');
} catch {
continue;
}
this.validateFrontmatter(content, skillMd, findings);
this.checkImpersonation(content, skillMd, findings);
}
this.checkBinaryFiles(files, findings);
return findings;
}
private shouldSkip(ruleId: string): boolean {
return this.skipRules.has(ruleId);
}
private validateFrontmatter(content: string, filePath: string, findings: Finding[]): void {
const fmMatch = content.match(/^---\r?\n([\s\S]*?)\r?\n---/);
if (!fmMatch) {
if (!this.shouldSkip('MF001')) {
findings.push({
id: `MF${++this.findingCounter}`,
ruleId: 'MF001',
category: ThreatCategory.POLICY_VIOLATION,
severity: Severity.LOW,
title: 'Missing SKILL.md frontmatter',
description: 'SKILL.md should have YAML frontmatter with name, description, and allowed-tools',
filePath,
analyzer: this.name,
remediation: 'Add YAML frontmatter with name, description, and allowed-tools fields.',
});
}
return;
}
const fm = fmMatch[1];
if (!/^name:/m.test(fm) && !this.shouldSkip('MF002')) {
findings.push({
id: `MF${++this.findingCounter}`,
ruleId: 'MF002',
category: ThreatCategory.POLICY_VIOLATION,
severity: Severity.LOW,
title: 'Missing skill name in frontmatter',
description: 'SKILL.md frontmatter should include a name field',
filePath,
analyzer: this.name,
remediation: 'Add a name field to the YAML frontmatter.',
});
}
const nameMatch = fm.match(/^name:\s*(.+)$/m);
if (nameMatch) {
const name = nameMatch[1].trim().replace(/^["']|["']$/g, '');
if (!/^[a-z0-9][a-z0-9._-]*$/i.test(name) && !this.shouldSkip('MF003')) {
findings.push({
id: `MF${++this.findingCounter}`,
ruleId: 'MF003',
category: ThreatCategory.POLICY_VIOLATION,
severity: Severity.LOW,
title: 'Invalid skill name format',
description: `Skill name "${name}" should use alphanumeric characters, dots, hyphens, or underscores`,
filePath,
analyzer: this.name,
remediation: 'Use a name matching [a-z0-9][a-z0-9._-]* pattern.',
});
}
}
const descMatch = fm.match(/^description:\s*(.+)$/m);
if (!descMatch) {
if (!this.shouldSkip('MF004')) {
findings.push({
id: `MF${++this.findingCounter}`,
ruleId: 'MF004',
category: ThreatCategory.POLICY_VIOLATION,
severity: Severity.INFO,
title: 'Missing skill description',
description: 'SKILL.md should include a description for discoverability',
filePath,
analyzer: this.name,
remediation: 'Add a description field to the YAML frontmatter.',
});
}
} else {
const desc = descMatch[1].trim().replace(/^["']|["']$/g, '');
if (desc.length < 20 && !this.shouldSkip('MF005')) {
findings.push({
id: `MF${++this.findingCounter}`,
ruleId: 'MF005',
category: ThreatCategory.POLICY_VIOLATION,
severity: Severity.INFO,
title: 'Short skill description',
description: `Description "${desc}" is too short (${desc.length} chars). Aim for at least 20 characters.`,
filePath,
analyzer: this.name,
remediation: 'Provide a more detailed description.',
});
}
}
const inlineToolsMatch = fm.match(/^allowed-tools:\s*\[([^\]]*)\]/m);
const multiLineToolsMatch = fm.match(/^allowed-tools:\s*\n((?:\s+-\s+.+\n?)+)/m);
let tools: string[] = [];
if (inlineToolsMatch) {
tools = inlineToolsMatch[1].split(',').map((t) => t.trim().replace(/^["']|["']$/g, ''));
} else if (multiLineToolsMatch) {
tools = multiLineToolsMatch[1]
.split('\n')
.map((line) => line.replace(/^\s*-\s*/, '').trim().replace(/^["']|["']$/g, ''))
.filter((t) => t.length > 0);
}
for (const tool of tools) {
if (DANGEROUS_TOOLS.has(tool) && !this.shouldSkip('MF006')) {
findings.push({
id: `MF${++this.findingCounter}`,
ruleId: 'MF006',
category: ThreatCategory.TOOL_ABUSE,
severity: Severity.HIGH,
title: `Dangerous tool in allowed-tools: ${tool}`,
description: `The tool "${tool}" grants shell access. This is a significant security risk.`,
filePath,
analyzer: this.name,
remediation: 'Restrict allowed-tools to the minimum needed. Avoid shell/exec tools.',
});
}
}
}
private checkImpersonation(content: string, filePath: string, findings: Finding[]): void {
for (const pattern of IMPERSONATION_PATTERNS) {
const match = content.match(pattern);
if (match && !this.shouldSkip('MF007')) {
const lineNumber = content.substring(0, match.index).split('\n').length;
findings.push({
id: `MF${++this.findingCounter}`,
ruleId: 'MF007',
category: ThreatCategory.SOCIAL_ENGINEERING,
severity: Severity.HIGH,
title: 'Impersonation detected',
description: `Skill claims official affiliation: "${match[0]}"`,
filePath,
lineNumber,
snippet: match[0],
analyzer: this.name,
remediation: 'Remove false claims of official endorsement or certification.',
});
}
}
}
private checkBinaryFiles(files: string[], findings: Finding[]): void {
for (const file of files) {
const ext = extname(file).toLowerCase();
if (BINARY_EXTENSIONS.has(ext) && !this.shouldSkip('MF008')) {
findings.push({
id: `MF${++this.findingCounter}`,
ruleId: 'MF008',
category: ThreatCategory.POLICY_VIOLATION,
severity: Severity.MEDIUM,
title: `Binary file detected: ${ext}`,
description: `Binary file found in skill directory. Skills should contain only text files.`,
filePath: file,
analyzer: this.name,
remediation: 'Remove binary files from skill directory. Use package managers for dependencies.',
});
}
}
}
}
@@ -0,0 +1,188 @@
import { readFile } from 'node:fs/promises';
import { basename } from 'node:path';
import type { Analyzer } from './base.js';
import type { Finding } from '../types.js';
import { Severity, ThreatCategory } from '../types.js';
interface SecretPattern {
id: string;
name: string;
pattern: RegExp;
severity: Severity;
}
const SECRET_PATTERNS: SecretPattern[] = [
{
id: 'SK001',
name: 'OpenAI API key',
pattern: /sk-(?!ant-)(?:proj-|admin-)?[A-Za-z0-9-]{20,}/,
severity: Severity.CRITICAL,
},
{
id: 'SK002',
name: 'Stripe live key',
pattern: /pk_live_[a-zA-Z0-9]{20,}/,
severity: Severity.CRITICAL,
},
{
id: 'SK003',
name: 'Stripe secret key',
pattern: /sk_live_[a-zA-Z0-9]{20,}/,
severity: Severity.CRITICAL,
},
{
id: 'SK004',
name: 'GitHub personal access token',
pattern: /ghp_[a-zA-Z0-9]{36}/,
severity: Severity.CRITICAL,
},
{
id: 'SK005',
name: 'GitHub OAuth token',
pattern: /gho_[a-zA-Z0-9]{36}/,
severity: Severity.CRITICAL,
},
{
id: 'SK006',
name: 'AWS access key',
pattern: /AKIA[0-9A-Z]{16}/,
severity: Severity.CRITICAL,
},
{
id: 'SK007',
name: 'Slack bot token',
pattern: /xoxb-[0-9]{10,}-[a-zA-Z0-9]{20,}/,
severity: Severity.CRITICAL,
},
{
id: 'SK008',
name: 'Slack user token',
pattern: /xoxp-[0-9]{10,}-[a-zA-Z0-9]{20,}/,
severity: Severity.CRITICAL,
},
{
id: 'SK009',
name: 'Private key block',
pattern: /-----BEGIN\s+(?:RSA\s+|EC\s+|DSA\s+|OPENSSH\s+)?PRIVATE\s+KEY-----/,
severity: Severity.CRITICAL,
},
{
id: 'SK010',
name: 'Google API key',
pattern: /AIza[0-9A-Za-z_-]{35}/,
severity: Severity.HIGH,
},
{
id: 'SK011',
name: 'Anthropic API key',
pattern: /sk-ant-[a-zA-Z0-9]{20,}/,
severity: Severity.CRITICAL,
},
{
id: 'SK012',
name: 'npm token',
pattern: /npm_[a-zA-Z0-9]{36}/,
severity: Severity.HIGH,
},
{
id: 'SK013',
name: 'Heroku API key',
pattern: /[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}/,
severity: Severity.LOW,
},
];
const PLACEHOLDER_INDICATORS = [
/your[-_]?api[-_]?key/i,
/example/i,
/sample/i,
/dummy/i,
/placeholder/i,
/xxx+/i,
/test[-_]?key/i,
/fake/i,
/replace[-_]?with/i,
/\<.*key.*\>/i,
];
const ENV_FILE_PATTERN = /^\.env/;
function isPlaceholder(line: string): boolean {
return PLACEHOLDER_INDICATORS.some((p) => p.test(line));
}
export class SecretsAnalyzer implements Analyzer {
name = 'secrets';
private findingCounter = 0;
private skipRules: Set<string>;
constructor(skipRules?: string[]) {
this.skipRules = new Set(skipRules ?? []);
}
async analyze(_skillPath: string, files: string[]): Promise<Finding[]> {
this.findingCounter = 0;
const findings: Finding[] = [];
for (const file of files) {
const name = basename(file);
if (ENV_FILE_PATTERN.test(name) && !this.skipRules.has('SK-ENV')) {
findings.push({
id: `SK${++this.findingCounter}`,
ruleId: 'SK-ENV',
category: ThreatCategory.HARDCODED_SECRETS,
severity: Severity.HIGH,
title: `Environment file included: ${name}`,
description: 'Environment files should not be included in skill distributions',
filePath: file,
analyzer: this.name,
remediation: 'Remove .env files from skill directory. Add to .gitignore.',
});
continue;
}
let content: string;
try {
content = await readFile(file, 'utf-8');
} catch {
continue;
}
if (content.length > 1_000_000) continue;
const lines = content.split('\n');
for (let i = 0; i < lines.length; i++) {
const line = lines[i];
if (isPlaceholder(line)) continue;
for (const secret of SECRET_PATTERNS) {
if (this.skipRules.has(secret.id)) continue;
if (secret.pattern.test(line)) {
if (secret.id === 'SK013') {
if (!/(?:key|token|secret|password|credential|api)/i.test(line)) continue;
}
findings.push({
id: `SK${++this.findingCounter}`,
ruleId: secret.id,
category: ThreatCategory.HARDCODED_SECRETS,
severity: secret.severity,
title: `${secret.name} detected`,
description: `Potential ${secret.name} found in skill file`,
filePath: file,
lineNumber: i + 1,
snippet: line.trim().replace(secret.pattern, '[REDACTED]').substring(0, 100),
analyzer: this.name,
remediation: 'Remove hardcoded secrets. Use environment variables or secret managers.',
});
break;
}
}
}
}
return findings;
}
}
@@ -0,0 +1,166 @@
import { readFile } from 'node:fs/promises';
import { extname } from 'node:path';
import type { Analyzer } from './base.js';
import type { Finding, SecurityRule } from '../types.js';
import { getAllRules } from '../rules/index.js';
const EXT_TO_FILETYPE: Record<string, string> = {
'.ts': 'typescript',
'.tsx': 'typescript',
'.js': 'javascript',
'.jsx': 'javascript',
'.mjs': 'javascript',
'.cjs': 'javascript',
'.py': 'python',
'.sh': 'bash',
'.bash': 'bash',
'.zsh': 'bash',
'.md': 'markdown',
'.mdx': 'markdown',
};
const PLACEHOLDER_PATTERNS = [
/your[-_]?api[-_]?key/i,
/example[-_]?token/i,
/sample[-_]?secret/i,
/dummy[-_]?password/i,
/placeholder/i,
/xxx+/i,
/\.\.\./,
/TODO/,
/FIXME/,
];
const TEST_FILE_PATTERNS = [
/\.test\.[jt]sx?$/,
/\.spec\.[jt]sx?$/,
/__tests__\//,
/test\//,
/tests\//,
/\.stories\.[jt]sx?$/,
];
function isTestFile(filePath: string): boolean {
return TEST_FILE_PATTERNS.some((p) => p.test(filePath));
}
function isPlaceholderLine(line: string): boolean {
return PLACEHOLDER_PATTERNS.some((p) => p.test(line));
}
function getFileType(filePath: string): string | undefined {
return EXT_TO_FILETYPE[extname(filePath)];
}
function ruleMatchesFileType(rule: SecurityRule, fileType: string | undefined): boolean {
if (!rule.fileTypes || rule.fileTypes.length === 0) return true;
if (!fileType) return true;
return rule.fileTypes.includes(fileType);
}
function matchesExcludePatterns(line: string, rule: SecurityRule): boolean {
if (!rule.excludePatterns) return false;
return rule.excludePatterns.some((p) => p.test(line));
}
export class StaticAnalyzer implements Analyzer {
name = 'static';
private rules: SecurityRule[];
private skipRules: Set<string>;
private findingCounter = 0;
constructor(skipRules?: string[]) {
this.rules = getAllRules();
this.skipRules = new Set(skipRules ?? []);
}
async analyze(_skillPath: string, files: string[]): Promise<Finding[]> {
this.findingCounter = 0;
const findings: Finding[] = [];
for (const file of files) {
if (isTestFile(file)) continue;
const fileType = getFileType(file);
const applicableRules = this.rules.filter(
(r) => !this.skipRules.has(r.id) && ruleMatchesFileType(r, fileType)
);
if (applicableRules.length === 0) continue;
let content: string;
try {
content = await readFile(file, 'utf-8');
} catch {
continue;
}
const lines = content.split('\n');
for (const rule of applicableRules) {
if (rule.multiline) {
for (const pattern of rule.patterns) {
pattern.lastIndex = 0;
let match: RegExpExecArray | null;
while ((match = pattern.exec(content)) !== null) {
const lineNumber = content.substring(0, match.index).split('\n').length;
const snippetStart = Math.max(0, match.index - 40);
const snippet = content.substring(snippetStart, match.index + match[0].length + 40).trim().substring(0, 200);
if (isPlaceholderLine(snippet) || matchesExcludePatterns(snippet, rule)) {
if (!pattern.global) break;
continue;
}
findings.push({
id: `F${++this.findingCounter}`,
ruleId: rule.id,
category: rule.category,
severity: rule.severity,
title: rule.description,
description: rule.description,
filePath: file,
lineNumber,
snippet,
remediation: rule.remediation,
analyzer: this.name,
});
if (!pattern.global) break;
}
}
continue;
}
for (let i = 0; i < lines.length; i++) {
const line = lines[i];
if (isPlaceholderLine(line)) continue;
if (matchesExcludePatterns(line, rule)) continue;
for (const pattern of rule.patterns) {
pattern.lastIndex = 0;
if (pattern.test(line)) {
findings.push({
id: `F${++this.findingCounter}`,
ruleId: rule.id,
category: rule.category,
severity: rule.severity,
title: rule.description,
description: rule.description,
filePath: file,
lineNumber: i + 1,
snippet: line.trim().substring(0, 200),
remediation: rule.remediation,
analyzer: this.name,
});
break;
}
}
}
}
}
return findings;
}
}
+10
View File
@@ -0,0 +1,10 @@
export { Severity, ThreatCategory } from './types.js';
export type { SecurityRule, Finding, ScanResult, ScanOptions } from './types.js';
export type { Analyzer } from './analyzers/base.js';
export { StaticAnalyzer } from './analyzers/static.js';
export { ManifestAnalyzer } from './analyzers/manifest.js';
export { SecretsAnalyzer } from './analyzers/secrets.js';
export { SkillScanner } from './scanner.js';
export { formatResult, formatSummary, formatJson, formatTable, formatSarif } from './reporter.js';
export { THREAT_TAXONOMY, getThreatInfo, getDefaultSeverity } from './taxonomy.js';
export { getAllRules } from './rules/index.js';
+182
View File
@@ -0,0 +1,182 @@
import { basename } from 'node:path';
import type { Finding, ScanResult } from './types.js';
import { Severity } from './types.js';
declare const __PACKAGE_VERSION__: string;
const SCANNER_VERSION = typeof __PACKAGE_VERSION__ !== 'undefined' ? __PACKAGE_VERSION__ : '0.0.0';
const SEVERITY_COLORS: Record<string, string> = {
[Severity.CRITICAL]: '\x1b[91m',
[Severity.HIGH]: '\x1b[31m',
[Severity.MEDIUM]: '\x1b[33m',
[Severity.LOW]: '\x1b[36m',
[Severity.INFO]: '\x1b[37m',
[Severity.SAFE]: '\x1b[32m',
};
const RESET = '\x1b[0m';
const BOLD = '\x1b[1m';
const DIM = '\x1b[2m';
const VERDICT_ICON: Record<string, string> = {
pass: '\x1b[32m PASS \x1b[0m',
warn: '\x1b[33m WARN \x1b[0m',
fail: '\x1b[91m FAIL \x1b[0m',
};
export function formatSummary(result: ScanResult): string {
const lines: string[] = [];
lines.push('');
lines.push(`${BOLD}Security Scan: ${result.skillName}${RESET}`);
lines.push(`Verdict: ${VERDICT_ICON[result.verdict] ?? result.verdict}`);
lines.push(`Duration: ${result.duration}ms | Analyzers: ${result.analyzersUsed.join(', ')}`);
lines.push('');
const { critical, high, medium, low, info } = result.stats;
const parts: string[] = [];
if (critical) parts.push(`${SEVERITY_COLORS[Severity.CRITICAL]}${critical} critical${RESET}`);
if (high) parts.push(`${SEVERITY_COLORS[Severity.HIGH]}${high} high${RESET}`);
if (medium) parts.push(`${SEVERITY_COLORS[Severity.MEDIUM]}${medium} medium${RESET}`);
if (low) parts.push(`${SEVERITY_COLORS[Severity.LOW]}${low} low${RESET}`);
if (info) parts.push(`${SEVERITY_COLORS[Severity.INFO]}${info} info${RESET}`);
if (parts.length > 0) {
lines.push(`Findings: ${parts.join(' | ')}`);
lines.push('');
} else {
lines.push(`${SEVERITY_COLORS[Severity.SAFE]}No security findings${RESET}`);
lines.push('');
return lines.join('\n');
}
for (const finding of result.findings) {
const color = SEVERITY_COLORS[finding.severity] ?? '';
const sev = finding.severity.toUpperCase().padEnd(8);
lines.push(` ${color}${sev}${RESET} [${finding.ruleId}] ${finding.title}`);
if (finding.filePath) {
const loc = finding.lineNumber ? `${finding.filePath}:${finding.lineNumber}` : finding.filePath;
lines.push(` ${DIM}${loc}${RESET}`);
}
if (finding.snippet) {
lines.push(` ${DIM}> ${finding.snippet}${RESET}`);
}
if (finding.remediation) {
lines.push(` Fix: ${finding.remediation}`);
}
lines.push('');
}
return lines.join('\n');
}
export function formatJson(result: ScanResult): string {
return JSON.stringify(result, null, 2);
}
export function formatTable(result: ScanResult): string {
const lines: string[] = [];
const header = ['Severity', 'Rule', 'Title', 'File', 'Line'];
const widths = [10, 8, 50, 40, 6];
lines.push(header.map((h, i) => h.padEnd(widths[i])).join(' | '));
lines.push(widths.map((w) => '-'.repeat(w)).join('-+-'));
for (const f of result.findings) {
const row = [
f.severity.toUpperCase().padEnd(widths[0]),
f.ruleId.padEnd(widths[1]),
f.title.substring(0, widths[2]).padEnd(widths[2]),
(f.filePath ? basename(f.filePath) : '').substring(0, widths[3]).padEnd(widths[3]),
String(f.lineNumber ?? '').padEnd(widths[4]),
];
lines.push(row.join(' | '));
}
lines.push('');
lines.push(`Total: ${result.findings.length} findings | Verdict: ${result.verdict.toUpperCase()}`);
return lines.join('\n');
}
export function formatSarif(result: ScanResult): string {
const rules = new Map<string, Finding>();
for (const f of result.findings) {
if (!rules.has(f.ruleId)) rules.set(f.ruleId, f);
}
const severityToSarif: Record<string, string> = {
[Severity.CRITICAL]: 'error',
[Severity.HIGH]: 'error',
[Severity.MEDIUM]: 'warning',
[Severity.LOW]: 'note',
[Severity.INFO]: 'note',
[Severity.SAFE]: 'none',
};
const sarif = {
$schema: 'https://raw.githubusercontent.com/oasis-tcs/sarif-spec/main/sarif-2.1/schema/sarif-schema-2.1.0.json',
version: '2.1.0',
runs: [
{
tool: {
driver: {
name: 'skillkit-scanner',
version: SCANNER_VERSION,
informationUri: 'https://agenstskills.com',
rules: [...rules.values()].map((r) => ({
id: r.ruleId,
name: r.ruleId,
shortDescription: { text: r.title },
fullDescription: { text: r.description },
helpUri: 'https://agenstskills.com/docs/security',
defaultConfiguration: {
level: severityToSarif[r.severity] ?? 'warning',
},
properties: {
category: r.category,
},
})),
},
},
results: result.findings.map((f) => ({
ruleId: f.ruleId,
level: severityToSarif[f.severity] ?? 'warning',
message: { text: f.description },
locations: f.filePath
? [
{
physicalLocation: {
artifactLocation: {
uri: f.filePath.startsWith(result.skillPath)
? f.filePath.slice(result.skillPath.length).replace(/^\//, '')
: f.filePath,
},
region: f.lineNumber
? { startLine: f.lineNumber }
: undefined,
},
},
]
: [],
fixes: f.remediation
? [{ description: { text: f.remediation } }]
: undefined,
})),
},
],
};
return JSON.stringify(sarif, null, 2);
}
export function formatResult(result: ScanResult, format: string = 'summary'): string {
switch (format) {
case 'json': return formatJson(result);
case 'table': return formatTable(result);
case 'sarif': return formatSarif(result);
default: return formatSummary(result);
}
}
@@ -0,0 +1,114 @@
import { type SecurityRule, Severity, ThreatCategory } from '../types.js';
export const commandInjectionRules: SecurityRule[] = [
{
id: 'CI001',
category: ThreatCategory.COMMAND_INJECTION,
severity: Severity.CRITICAL,
patterns: [/\beval\s*\(/],
excludePatterns: [/\/\/.*\beval\b/, /#.*\beval\b/, /['"].*\beval\b.*['"]/],
fileTypes: ['typescript', 'javascript', 'python'],
description: 'eval() call: dynamic code execution',
remediation: 'Replace eval() with safer alternatives like JSON.parse() or dedicated parsers.',
},
{
id: 'CI002',
category: ThreatCategory.COMMAND_INJECTION,
severity: Severity.CRITICAL,
patterns: [/new\s+Function\s*\(/, /\bFunction\s*\(\s*['"`]/],
fileTypes: ['typescript', 'javascript'],
description: 'Function() constructor: dynamic code generation',
remediation: 'Avoid Function() constructor. Use static code structures.',
},
{
id: 'CI003',
category: ThreatCategory.COMMAND_INJECTION,
severity: Severity.CRITICAL,
patterns: [
/child_process\s*['"]?\s*\)\s*\.\s*exec\s*\(/,
/\bexec\s*\(\s*['"`].*\$\{/,
/\bexecSync\s*\(/,
/require\s*\(\s*['"]child_process['"]\s*\)/,
],
fileTypes: ['typescript', 'javascript'],
description: 'child_process execution: shell command injection risk',
remediation: 'Use execFile() with argument arrays instead of exec() with string interpolation.',
},
{
id: 'CI004',
category: ThreatCategory.COMMAND_INJECTION,
severity: Severity.CRITICAL,
patterns: [
/subprocess\.(?:call|run|Popen)\s*\([^)]*shell\s*=\s*True/,
/os\.system\s*\(/,
/os\.popen\s*\(/,
],
fileTypes: ['python'],
description: 'Python shell execution with shell=True or os.system()',
remediation: 'Use subprocess.run() with shell=False and argument lists.',
},
{
id: 'CI005',
category: ThreatCategory.COMMAND_INJECTION,
severity: Severity.MEDIUM,
patterns: [/`[^`]*\$\{[^}]*\}[^`]*`/],
excludePatterns: [/console\.log/, /logger\./, /throw\s+new/, /return\s+`/, /=\s*`/, /\+\s*`/, /\(\s*`/],
fileTypes: ['typescript', 'javascript'],
description: 'Template literal with dynamic content in potential command context',
remediation: 'Avoid interpolating user input into command strings. Use argument arrays.',
},
{
id: 'CI006',
category: ThreatCategory.COMMAND_INJECTION,
severity: Severity.MEDIUM,
patterns: [/\.\.\//, /\.\.\\/],
excludePatterns: [/import\s+.*from\s+['"]\.\.\//, /require\s*\(\s*['"]\.\.\//, /\/\/.*\.\.\//, /#.*\.\.\//, /\]\(\.\.\//, /href\s*=\s*['"]\.\.\//, /src\s*=\s*['"]\.\.\//, /include\s+['"]\.\.\//, /!\[.*\]\(\.\.\//, /\.\.\/node_modules/],
fileTypes: ['typescript', 'javascript', 'python', 'bash'],
description: 'Path traversal: relative path escaping directory boundaries',
remediation: 'Use path.resolve() and validate paths are within expected directories.',
},
{
id: 'CI007',
category: ThreatCategory.COMMAND_INJECTION,
severity: Severity.HIGH,
patterns: [
/;\s*(?:rm|cat|curl|wget|nc|ncat)\s+/,
/\|\s*(?:sh|bash|zsh|dash)\b/,
/&&\s*(?:rm|curl|wget)\s+/,
],
fileTypes: ['bash', 'markdown'],
description: 'Shell command chaining with dangerous commands',
remediation: 'Avoid chaining shell commands. Use discrete, validated command invocations.',
},
{
id: 'CI008',
category: ThreatCategory.COMMAND_INJECTION,
severity: Severity.MEDIUM,
patterns: [/\bexec\s*\(/, /\bspawn\s*\(/],
excludePatterns: [/execFile\s*\(/, /\.exec\s*\(/, /RegExp.*\.exec/],
fileTypes: ['typescript', 'javascript'],
description: 'Process execution functions detected',
remediation: 'Prefer execFile() over exec(). Validate all command arguments.',
},
{
id: 'CI009',
category: ThreatCategory.COMMAND_INJECTION,
severity: Severity.HIGH,
patterns: [
/\b__import__\s*\(/,
/\bcompile\s*\(\s*['"][^'"]*['"]\s*,\s*['"][^'"]*['"]\s*,\s*['"]exec['"]\s*\)/,
],
fileTypes: ['python'],
description: 'Python dynamic import or code compilation',
remediation: 'Use standard import statements. Avoid dynamic code compilation.',
},
{
id: 'CI010',
category: ThreatCategory.COMMAND_INJECTION,
severity: Severity.MEDIUM,
patterns: [/\bvm\.runIn(?:ThisContext|NewContext|Context)\s*\(/],
fileTypes: ['typescript', 'javascript'],
description: 'Node.js vm module: sandboxed but potentially dangerous code execution',
remediation: 'Avoid vm module for untrusted code. Use proper sandboxing solutions.',
},
];
@@ -0,0 +1,101 @@
import { type SecurityRule, Severity, ThreatCategory } from '../types.js';
export const dataExfiltrationRules: SecurityRule[] = [
{
id: 'DE001',
category: ThreatCategory.DATA_EXFILTRATION,
severity: Severity.HIGH,
patterns: [
/https?:\/\/(?:discord(?:app)?\.com\/api\/webhooks|ptb\.discord\.com\/api\/webhooks)\//i,
/https?:\/\/hooks\.slack\.com\/services\//i,
/https?:\/\/api\.telegram\.org\/bot/i,
],
description: 'Webhook URL detected: Discord, Slack, or Telegram webhook endpoint',
remediation: 'Remove hardcoded webhook URLs. Use environment variables or configuration files.',
},
{
id: 'DE002',
category: ThreatCategory.DATA_EXFILTRATION,
severity: Severity.HIGH,
patterns: [
/(?:fetch|axios|request|got|ky|undici)\s*(?:\.\s*post)?\s*\([^)]*(?:process\.env|credentials|password|secret|token)/i,
],
description: 'HTTP request sending sensitive data: credentials or environment variables in request',
remediation: 'Never send credentials or env vars to external services from skill code.',
},
{
id: 'DE003',
category: ThreatCategory.DATA_EXFILTRATION,
severity: Severity.MEDIUM,
patterns: [
/process\.env\[/,
/process\.env\./,
/os\.environ/,
/\$ENV\{/,
],
excludePatterns: [/process\.env\.NODE_ENV/, /process\.env\.HOME/, /process\.env\.PATH/],
description: 'Environment variable access: skill reads environment variables',
remediation: 'Skills should declare required env vars in manifest, not access them directly.',
},
{
id: 'DE004',
category: ThreatCategory.DATA_EXFILTRATION,
severity: Severity.HIGH,
patterns: [
/readFile.*(?:\.env|credentials|\.aws|\.ssh|\.gnupg|\.netrc)/i,
/open\s*\(\s*['"].*(?:\.env|credentials|\.aws|\.ssh|\.gnupg)/i,
/cat\s+.*(?:\.env|credentials|id_rsa|\.aws\/)/i,
],
description: 'Sensitive file access: reading credential or configuration files',
remediation: 'Skills should not read user credential files.',
},
{
id: 'DE005',
category: ThreatCategory.DATA_EXFILTRATION,
severity: Severity.MEDIUM,
patterns: [
/new\s+WebSocket\s*\(\s*['"`]/,
/\bio\.connect\s*\(/,
],
description: 'WebSocket connection: potential covert data channel',
remediation: 'Document all network connections. Avoid persistent connections in skills.',
},
{
id: 'DE006',
category: ThreatCategory.DATA_EXFILTRATION,
severity: Severity.HIGH,
patterns: [
/https?:\/\/[a-z0-9]+\.ngrok\b/i,
/https?:\/\/[a-z0-9]+\.serveo\.net/i,
/https?:\/\/[a-z0-9]+\.loca\.lt/i,
/https?:\/\/[a-z0-9]+\.burpcollaborator\.net/i,
],
description: 'Tunneling service URL: potential data exfiltration via tunnel',
remediation: 'Remove tunneling service URLs. Use official API endpoints.',
},
{
id: 'DE007',
category: ThreatCategory.DATA_EXFILTRATION,
severity: Severity.MEDIUM,
patterns: [
/dns\.resolve/i,
/\bdnslookup\b/i,
/\bnslookup\s+/i,
/\bdig\s+/i,
],
description: 'DNS-based data exfiltration: DNS queries can encode stolen data',
remediation: 'Skills should not perform DNS queries unless explicitly required.',
},
{
id: 'DE008',
category: ThreatCategory.DATA_EXFILTRATION,
severity: Severity.MEDIUM,
patterns: [
/(?:fetch|axios|request|got)\s*\(\s*['"`]https?:\/\/(?!localhost|127\.0\.0\.1)/,
],
excludePatterns: [/(?:npmjs\.org|github\.com|githubusercontent\.com|registry\.npmmirror)/],
fileTypes: ['typescript', 'javascript'],
description: 'External HTTP request: skill makes outbound network call',
remediation: 'Declare all external URLs in skill manifest. Minimize network access.',
},
];
+24
View File
@@ -0,0 +1,24 @@
import type { SecurityRule } from '../types.js';
import { promptInjectionRules } from './prompt-injection.js';
import { commandInjectionRules } from './command-injection.js';
import { dataExfiltrationRules } from './data-exfiltration.js';
import { toolAbuseRules } from './tool-abuse.js';
import { unicodeRules } from './unicode.js';
export function getAllRules(): SecurityRule[] {
return [
...promptInjectionRules,
...commandInjectionRules,
...dataExfiltrationRules,
...toolAbuseRules,
...unicodeRules,
];
}
export {
promptInjectionRules,
commandInjectionRules,
dataExfiltrationRules,
toolAbuseRules,
unicodeRules,
};
@@ -0,0 +1,145 @@
import { type SecurityRule, Severity, ThreatCategory } from '../types.js';
export const promptInjectionRules: SecurityRule[] = [
{
id: 'PI001',
category: ThreatCategory.PROMPT_INJECTION,
severity: Severity.CRITICAL,
patterns: [/ignore\s+(all\s+)?(previous|above|prior)\s+(instructions?|rules?|guidelines?)/i],
description: 'Instruction override: attempts to discard system instructions',
remediation: 'Remove instruction override language. Skills should not attempt to modify agent behavior.',
},
{
id: 'PI002',
category: ThreatCategory.PROMPT_INJECTION,
severity: Severity.CRITICAL,
patterns: [/forget\s+(everything|all|what)\s+(you|i)\s+(told|said|learned)/i],
description: 'Context clearing: attempts to wipe agent memory',
remediation: 'Remove context-clearing instructions.',
},
{
id: 'PI003',
category: ThreatCategory.PROMPT_INJECTION,
severity: Severity.CRITICAL,
patterns: [/disregard\s+(your|all|the)\s+(training|programming|instructions?)/i],
description: 'Training bypass: attempts to override agent training',
remediation: 'Remove training bypass instructions.',
},
{
id: 'PI004',
category: ThreatCategory.PROMPT_INJECTION,
severity: Severity.CRITICAL,
patterns: [/new\s+instructions?:\s*$/im, /system\s+prompt:\s*$/im],
description: 'System prompt injection: attempts to inject new system-level instructions',
remediation: 'Do not include system prompt markers in skill content.',
},
{
id: 'PI005',
category: ThreatCategory.PROMPT_INJECTION,
severity: Severity.HIGH,
patterns: [/you\s+are\s+(now|actually|really)\s+(a|an|the)/i],
description: 'Role manipulation: attempts to reassign agent identity',
remediation: 'Skills should not attempt to change the agent\'s role or identity.',
},
{
id: 'PI006',
category: ThreatCategory.PROMPT_INJECTION,
severity: Severity.HIGH,
patterns: [/pretend\s+(to\s+be|you\s+are)/i, /act\s+as\s+(if|though)\s+you/i],
description: 'Roleplay manipulation: attempts to alter agent behavior via pretense',
remediation: 'Remove roleplay instructions that change agent behavior.',
},
{
id: 'PI007',
category: ThreatCategory.PROMPT_INJECTION,
severity: Severity.HIGH,
patterns: [/from\s+now\s+on,?\s+(you|always|never)/i],
description: 'Persistent behavior change: attempts to permanently alter agent behavior',
remediation: 'Skills should provide task-specific instructions, not permanent behavior changes.',
},
{
id: 'PI008',
category: ThreatCategory.PROMPT_INJECTION,
severity: Severity.HIGH,
patterns: [
/show\s+me\s+your\s+(system\s+)?(prompt|instructions)/i,
/reveal\s+your\s+(system\s+)?(prompt|instructions)/i,
/what\s+are\s+your\s+(system\s+)?(instructions|rules)/i,
],
description: 'System prompt extraction: attempts to reveal agent configuration',
remediation: 'Remove attempts to extract system prompts.',
},
{
id: 'PI009',
category: ThreatCategory.PROMPT_INJECTION,
severity: Severity.CRITICAL,
patterns: [
/unrestricted\s+mode/i,
/(?<!detect(?:ing)?[\s.]+)(?<!prevent(?:ing)?[\s.]+)jailbreak/i,
/DAN\s+(mode|prompt)/i,
/bypass\s+(safety|content)\s+(filter|restriction)/i,
],
description: 'Policy bypass: attempts to disable safety restrictions',
remediation: 'Remove jailbreak or policy bypass instructions.',
},
{
id: 'PI010',
category: ThreatCategory.PROMPT_INJECTION,
severity: Severity.HIGH,
patterns: [
/don'?t\s+tell\s+the\s+user/i,
/hide\s+this\s+from\s+the\s+user/i,
/keep\s+this\s+(a\s+)?secret/i,
/do\s+not\s+mention\s+this/i,
],
description: 'Concealment: instructs agent to hide information from user',
remediation: 'Skills should be transparent. Remove concealment instructions.',
},
{
id: 'PI011',
category: ThreatCategory.PROMPT_INJECTION,
severity: Severity.HIGH,
patterns: [
/```\s*(system|assistant|user)\s*$/im,
/<\/?(?:system|user|assistant|human|ai|claude)>/i,
],
description: 'Delimiter injection: attempts to inject conversation role markers',
remediation: 'Remove conversation role delimiters from skill content.',
},
{
id: 'PI012',
category: ThreatCategory.PROMPT_INJECTION,
severity: Severity.HIGH,
patterns: [/\[INST\]/i, /\[\/INST\]/i, /<<SYS>>/i, /<<\/SYS>>/i],
description: 'Model-specific delimiter injection: Llama-style instruction delimiters',
remediation: 'Remove model-specific instruction delimiters.',
},
{
id: 'PI013',
category: ThreatCategory.PROMPT_INJECTION,
severity: Severity.MEDIUM,
patterns: [/---\s*$/im],
excludePatterns: [/^---\s*$/],
multiline: true,
description: 'YAML front-matter injection: attempts to inject via YAML metadata',
remediation: 'Use standard SKILL.md frontmatter format only.',
},
{
id: 'PI014',
category: ThreatCategory.PROMPT_INJECTION,
severity: Severity.MEDIUM,
patterns: [
/<!--[^>]{0,500}?(?:ignore|system|instruction|secret|override)[^>]{0,500}?-->/i,
],
description: 'Hidden HTML comments with suspicious instruction content',
remediation: 'Do not hide instructions in HTML comments.',
},
{
id: 'PI015',
category: ThreatCategory.PROMPT_INJECTION,
severity: Severity.MEDIUM,
patterns: [/\[comment\]:\s*#\s*\([^)]*(?:ignore|system|override)[^)]*\)/i],
description: 'Hidden Markdown comments with suspicious content',
remediation: 'Do not hide instructions in Markdown comments.',
},
];
@@ -0,0 +1,77 @@
import { type SecurityRule, Severity, ThreatCategory } from '../types.js';
export const toolAbuseRules: SecurityRule[] = [
{
id: 'TA001',
category: ThreatCategory.TOOL_ABUSE,
severity: Severity.HIGH,
patterns: [
/(?:override|replace|redefine|shadow)\s+(?:the\s+)?(?:built-?in|default|original)\s+(?:tool|function|command)/i,
],
fileTypes: ['markdown'],
description: 'Tool shadowing: instructs agent to override built-in tools',
remediation: 'Skills should extend functionality, not replace built-in tools.',
},
{
id: 'TA002',
category: ThreatCategory.AUTONOMY_ABUSE,
severity: Severity.HIGH,
patterns: [
/(?:keep|continue)\s+(?:retrying|trying|running)\s+(?:until|without)/i,
/(?:run|execute|proceed)\s+without\s+(?:confirmation|approval|asking)/i,
/(?:auto-?approve|skip\s+confirmation|bypass\s+approval)/i,
/(?:don'?t|do\s+not|never)\s+(?:ask|prompt|wait)\s+(?:for|the)\s+(?:permission|confirmation|approval)/i,
],
fileTypes: ['markdown'],
description: 'Autonomy abuse: instructs agent to bypass user confirmation',
remediation: 'Skills must respect user confirmation flows. Remove autonomy escalation.',
},
{
id: 'TA003',
category: ThreatCategory.TOOL_ABUSE,
severity: Severity.MEDIUM,
patterns: [
/(?:discover|find|list|enumerate)\s+(?:all\s+)?(?:available\s+)?(?:tools|capabilities|functions)/i,
/(?:enable|activate|unlock)\s+(?:all\s+)?(?:hidden|disabled|extra)\s+(?:tools|capabilities)/i,
],
fileTypes: ['markdown'],
description: 'Capability inflation: attempts to discover or enable additional tools',
remediation: 'Skills should use only declared tools. Do not probe for hidden capabilities.',
},
{
id: 'TA004',
category: ThreatCategory.TOOL_ABUSE,
severity: Severity.HIGH,
patterns: [
/read\s+(?:the\s+)?(?:file|contents?).*(?:then|and)\s+(?:send|post|upload|transmit)/i,
/(?:access|read|get)\s+.*(?:credential|secret|key|token).*(?:then|and)\s+(?:send|share|post)/i,
],
fileTypes: ['markdown'],
description: 'Tool chaining: read sensitive data then send externally',
remediation: 'Skills should not combine file reading with external transmission.',
},
{
id: 'TA005',
category: ThreatCategory.SOCIAL_ENGINEERING,
severity: Severity.MEDIUM,
patterns: [
/(?:urgent|immediately|critical|emergency)[!:]\s+(?:you\s+must|run|execute|do\s+this)/i,
/(?:as\s+(?:an?\s+)?(?:admin|root|superuser|administrator)),?\s+(?:I|we)\s+(?:require|need|demand)/i,
],
fileTypes: ['markdown'],
description: 'Social engineering: uses urgency or authority to manipulate agent',
remediation: 'Remove manipulative language. Provide clear, neutral instructions.',
},
{
id: 'TA006',
category: ThreatCategory.TOOL_ABUSE,
severity: Severity.MEDIUM,
patterns: [
/(?:when|if)\s+(?:the\s+)?(?:user|human)\s+(?:isn'?t|is\s+not)\s+(?:looking|watching|present)/i,
/(?:only|secretly)\s+(?:when|while)\s+(?:idle|unattended|background)/i,
],
fileTypes: ['markdown'],
description: 'Stealth execution: instructs agent to act when user is not present',
remediation: 'All skill actions must be transparent and auditable.',
},
];
@@ -0,0 +1,68 @@
import { type SecurityRule, Severity, ThreatCategory } from '../types.js';
export const unicodeRules: SecurityRule[] = [
{
id: 'UC001',
category: ThreatCategory.UNICODE_STEGANOGRAPHY,
severity: Severity.MEDIUM,
patterns: [/\u200B|\u200C|\u200D|\uFEFF/],
description: 'Zero-width characters detected: may hide invisible instructions',
remediation: 'Remove zero-width characters (U+200B, U+200C, U+200D, U+FEFF).',
},
{
id: 'UC002',
category: ThreatCategory.UNICODE_STEGANOGRAPHY,
severity: Severity.HIGH,
patterns: [/[\u202A-\u202E]/],
description: 'Bidirectional text override: can reverse displayed text direction to hide content',
remediation: 'Remove bidirectional override characters (U+202A-U+202E).',
},
{
id: 'UC003',
category: ThreatCategory.UNICODE_STEGANOGRAPHY,
severity: Severity.HIGH,
patterns: [/[\u2066-\u2069]/],
description: 'Bidirectional isolate characters: can create hidden text regions',
remediation: 'Remove bidirectional isolate characters (U+2066-U+2069).',
},
{
id: 'UC004',
category: ThreatCategory.UNICODE_STEGANOGRAPHY,
severity: Severity.HIGH,
patterns: [/[\u{E0001}-\u{E007F}]/u],
description: 'Tag characters detected: Unicode tag block can encode hidden payloads',
remediation: 'Remove Unicode tag characters (U+E0001-U+E007F).',
},
{
id: 'UC005',
category: ThreatCategory.UNICODE_STEGANOGRAPHY,
severity: Severity.MEDIUM,
// biome-ignore lint/suspicious/noControlCharactersInRegex: intentional detection of control characters
patterns: [/[\u0000-\u0008\u000B\u000C\u000E-\u001F\u007F-\u009F]/],
description: 'Control characters detected: non-printable characters in content',
remediation: 'Remove control characters. Use only printable Unicode content.',
},
{
id: 'UC006',
category: ThreatCategory.OBFUSCATION,
severity: Severity.MEDIUM,
patterns: [
/atob\s*\(\s*['"`][A-Za-z0-9+/=]{40,}['"`]\s*\)/,
/Buffer\.from\s*\(\s*['"`][A-Za-z0-9+/=]{40,}['"`]\s*,\s*['"`]base64['"`]\s*\)/,
/base64\.b64decode\s*\(\s*['"`][A-Za-z0-9+/=]{40,}['"`]\s*\)/,
],
description: 'Base64-encoded payload: long encoded string being decoded at runtime',
remediation: 'Avoid embedding base64-encoded payloads. Use plain text or documented data formats.',
},
{
id: 'UC007',
category: ThreatCategory.OBFUSCATION,
severity: Severity.MEDIUM,
patterns: [
/\\x[0-9a-fA-F]{2}(?:\\x[0-9a-fA-F]{2}){9,}/,
/\\u[0-9a-fA-F]{4}(?:\\u[0-9a-fA-F]{4}){9,}/,
],
description: 'Hex/Unicode escape sequences: potential obfuscated content',
remediation: 'Use readable strings instead of hex or unicode escape sequences.',
},
];
+131
View File
@@ -0,0 +1,131 @@
import { readdir } from 'node:fs/promises';
import { join, basename } from 'node:path';
import type { Analyzer } from './analyzers/base.js';
import { StaticAnalyzer } from './analyzers/static.js';
import { ManifestAnalyzer } from './analyzers/manifest.js';
import { SecretsAnalyzer } from './analyzers/secrets.js';
import type { Finding, ScanResult, ScanOptions } from './types.js';
import { Severity } from './types.js';
const SEVERITY_ORDER: Record<string, number> = {
[Severity.CRITICAL]: 5,
[Severity.HIGH]: 4,
[Severity.MEDIUM]: 3,
[Severity.LOW]: 2,
[Severity.INFO]: 1,
[Severity.SAFE]: 0,
};
async function discoverFiles(dirPath: string): Promise<string[]> {
const files: string[] = [];
async function walk(dir: string): Promise<void> {
let entries;
try {
entries = await readdir(dir, { withFileTypes: true });
} catch {
return;
}
for (const entry of entries) {
const fullPath = join(dir, entry.name);
if (entry.name.startsWith('.') && entry.name !== '.env' && !entry.name.startsWith('.env.')) continue;
if (entry.name === 'node_modules') continue;
if (entry.isDirectory()) {
await walk(fullPath);
} else if (entry.isFile()) {
files.push(fullPath);
}
}
}
await walk(dirPath);
return files;
}
function deduplicateFindings(findings: Finding[]): Finding[] {
const seen = new Set<string>();
return findings.filter((f) => {
const key = `${f.ruleId}:${f.filePath ?? ''}:${f.lineNumber ?? ''}`;
if (seen.has(key)) return false;
seen.add(key);
return true;
});
}
function calculateVerdict(
findings: Finding[],
failOnSeverity: Severity = Severity.HIGH
): 'pass' | 'warn' | 'fail' {
const threshold = SEVERITY_ORDER[failOnSeverity] ?? SEVERITY_ORDER[Severity.HIGH];
for (const f of findings) {
if ((SEVERITY_ORDER[f.severity] ?? 0) >= threshold) {
return 'fail';
}
}
if (findings.some((f) => (SEVERITY_ORDER[f.severity] ?? 0) >= SEVERITY_ORDER[Severity.MEDIUM])) {
return 'warn';
}
return 'pass';
}
function countStats(findings: Finding[]): ScanResult['stats'] {
const stats = { critical: 0, high: 0, medium: 0, low: 0, info: 0 };
for (const f of findings) {
switch (f.severity) {
case Severity.CRITICAL: stats.critical++; break;
case Severity.HIGH: stats.high++; break;
case Severity.MEDIUM: stats.medium++; break;
case Severity.LOW: stats.low++; break;
case Severity.INFO: stats.info++; break;
}
}
return stats;
}
export class SkillScanner {
private analyzers: Analyzer[];
private options: ScanOptions;
constructor(options?: ScanOptions) {
this.options = options ?? {};
this.analyzers = [
new StaticAnalyzer(this.options.skipRules),
new ManifestAnalyzer(this.options.skipRules),
new SecretsAnalyzer(this.options.skipRules),
];
}
async scan(skillPath: string): Promise<ScanResult> {
const start = performance.now();
const files = await discoverFiles(skillPath);
const skillName = basename(skillPath.replace(/\/+$/, '')) || 'unknown';
const resultSets = await Promise.all(
this.analyzers.map((a) => a.analyze(skillPath, files))
);
const allFindings = deduplicateFindings(resultSets.flat());
allFindings.sort(
(a, b) => (SEVERITY_ORDER[b.severity] ?? 0) - (SEVERITY_ORDER[a.severity] ?? 0)
);
const duration = Math.round(performance.now() - start);
return {
skillPath,
skillName,
verdict: calculateVerdict(allFindings, this.options.failOnSeverity),
findings: allFindings,
stats: countStats(allFindings),
duration,
analyzersUsed: this.analyzers.map((a) => a.name),
};
}
}
+130
View File
@@ -0,0 +1,130 @@
import { ThreatCategory, Severity } from './types.js';
export interface ThreatInfo {
category: ThreatCategory;
name: string;
description: string;
defaultSeverity: Severity;
examples: string[];
}
export const THREAT_TAXONOMY: Record<ThreatCategory, ThreatInfo> = {
[ThreatCategory.PROMPT_INJECTION]: {
category: ThreatCategory.PROMPT_INJECTION,
name: 'Prompt Injection',
description: 'Attempts to override, manipulate, or bypass AI agent instructions through crafted text',
defaultSeverity: Severity.CRITICAL,
examples: [
'Instruction override (ignore previous instructions)',
'Role manipulation (you are now...)',
'System prompt extraction',
],
},
[ThreatCategory.COMMAND_INJECTION]: {
category: ThreatCategory.COMMAND_INJECTION,
name: 'Command Injection',
description: 'Code execution via eval, exec, subprocess, or shell commands embedded in skill content',
defaultSeverity: Severity.CRITICAL,
examples: [
'eval() or Function() calls',
'subprocess.run with shell=True',
'child_process.exec with user input',
],
},
[ThreatCategory.DATA_EXFILTRATION]: {
category: ThreatCategory.DATA_EXFILTRATION,
name: 'Data Exfiltration',
description: 'Attempts to send sensitive data to external endpoints or read protected files',
defaultSeverity: Severity.HIGH,
examples: [
'Webhook URLs to Discord/Telegram/Slack',
'HTTP POST with environment variables',
'Reading .env or credential files',
],
},
[ThreatCategory.TOOL_ABUSE]: {
category: ThreatCategory.TOOL_ABUSE,
name: 'Tool Abuse',
description: 'Manipulation of AI agent tools through shadowing, chaining, or autonomy escalation',
defaultSeverity: Severity.HIGH,
examples: [
'Redefining built-in tools',
'Instructing agent to run without confirmation',
'Chaining sensitive read + external send',
],
},
[ThreatCategory.HARDCODED_SECRETS]: {
category: ThreatCategory.HARDCODED_SECRETS,
name: 'Hardcoded Secrets',
description: 'API keys, tokens, passwords, or other credentials embedded in skill files',
defaultSeverity: Severity.HIGH,
examples: [
'API keys (sk-, pk_live_, ghp_)',
'Private key blocks',
'Embedded .env file contents',
],
},
[ThreatCategory.UNICODE_STEGANOGRAPHY]: {
category: ThreatCategory.UNICODE_STEGANOGRAPHY,
name: 'Unicode Steganography',
description: 'Hidden content using invisible Unicode characters, bidirectional overrides, or homoglyphs',
defaultSeverity: Severity.MEDIUM,
examples: [
'Zero-width characters hiding instructions',
'Bidirectional text override attacks',
'Tag characters encoding hidden payloads',
],
},
[ThreatCategory.OBFUSCATION]: {
category: ThreatCategory.OBFUSCATION,
name: 'Obfuscation',
description: 'Deliberately obscured code or instructions to hide malicious intent',
defaultSeverity: Severity.MEDIUM,
examples: [
'Base64-encoded commands',
'Hex-encoded payloads',
'String concatenation to evade detection',
],
},
[ThreatCategory.SOCIAL_ENGINEERING]: {
category: ThreatCategory.SOCIAL_ENGINEERING,
name: 'Social Engineering',
description: 'Manipulative language targeting the AI agent or the user to bypass safety measures',
defaultSeverity: Severity.MEDIUM,
examples: [
'Urgency pressure (do this immediately)',
'Authority claims (as an admin, I require...)',
'Concealment requests (don\'t tell the user)',
],
},
[ThreatCategory.AUTONOMY_ABUSE]: {
category: ThreatCategory.AUTONOMY_ABUSE,
name: 'Autonomy Abuse',
description: 'Instructions that escalate agent autonomy beyond intended boundaries',
defaultSeverity: Severity.HIGH,
examples: [
'Run without user confirmation',
'Keep retrying until success',
'Auto-approve all actions',
],
},
[ThreatCategory.POLICY_VIOLATION]: {
category: ThreatCategory.POLICY_VIOLATION,
name: 'Policy Violation',
description: 'Content that violates skill marketplace policies or naming conventions',
defaultSeverity: Severity.LOW,
examples: [
'Impersonating official tools',
'Missing required metadata',
'Binary files in skill directory',
],
},
};
export function getThreatInfo(category: ThreatCategory): ThreatInfo {
return THREAT_TAXONOMY[category];
}
export function getDefaultSeverity(category: ThreatCategory): Severity {
return THREAT_TAXONOMY[category].defaultSeverity;
}
+69
View File
@@ -0,0 +1,69 @@
export enum Severity {
CRITICAL = 'critical',
HIGH = 'high',
MEDIUM = 'medium',
LOW = 'low',
INFO = 'info',
SAFE = 'safe',
}
export enum ThreatCategory {
PROMPT_INJECTION = 'prompt-injection',
COMMAND_INJECTION = 'command-injection',
DATA_EXFILTRATION = 'data-exfiltration',
TOOL_ABUSE = 'tool-abuse',
HARDCODED_SECRETS = 'hardcoded-secrets',
UNICODE_STEGANOGRAPHY = 'unicode-steganography',
OBFUSCATION = 'obfuscation',
SOCIAL_ENGINEERING = 'social-engineering',
AUTONOMY_ABUSE = 'autonomy-abuse',
POLICY_VIOLATION = 'policy-violation',
}
export interface SecurityRule {
id: string;
category: ThreatCategory;
severity: Severity;
patterns: RegExp[];
excludePatterns?: RegExp[];
fileTypes?: string[];
multiline?: boolean;
description: string;
remediation: string;
}
export interface Finding {
id: string;
ruleId: string;
category: ThreatCategory;
severity: Severity;
title: string;
description: string;
filePath?: string;
lineNumber?: number;
snippet?: string;
remediation?: string;
analyzer: string;
aitech?: string;
}
export interface ScanResult {
skillPath: string;
skillName: string;
verdict: 'pass' | 'warn' | 'fail';
findings: Finding[];
stats: {
critical: number;
high: number;
medium: number;
low: number;
info: number;
};
duration: number;
analyzersUsed: string[];
}
export interface ScanOptions {
failOnSeverity?: Severity;
skipRules?: string[];
}
+6
View File
@@ -1,5 +1,8 @@
import { readFileSync } from 'node:fs';
import { defineConfig } from 'tsup';
const pkg = JSON.parse(readFileSync('./package.json', 'utf-8'));
export default defineConfig({
entry: ['src/index.ts'],
format: ['esm'],
@@ -11,4 +14,7 @@ export default defineConfig({
splitting: false,
skipNodeModulesBundle: true,
platform: 'node',
define: {
'__PACKAGE_VERSION__': JSON.stringify(pkg.version),
},
});