shellward 0.6.5 → 0.6.7
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +21 -10
- package/dist/cli.js +2 -2
- package/dist/compliance/audit.d.ts +10 -1
- package/dist/compliance/audit.js +11 -4
- package/dist/compliance/project-scan.js +0 -0
- package/package.json +1 -1
- package/src/cli.ts +2 -2
- package/src/compliance/audit.ts +22 -4
- package/src/compliance/project-scan.ts +0 -0
package/README.md
CHANGED
|
@@ -4,41 +4,52 @@
|
|
|
4
4
|
|
|
5
5
|
# ShellWard
|
|
6
6
|
|
|
7
|
-
**AI
|
|
7
|
+
**AI 应用合规网关** — 为中国监管而生的 AI Agent 安全合规工具(网安法 2026 / PIPL / 等保2.0 / 数据出境 / AI标识)。先一行命令体检项目合规风险,再在运行时拦截提示注入、数据外泄与危险命令。中文威胁检测 + 中文 PII + 零依赖——英文工具不做的事。
|
|
8
8
|
|
|
9
9
|
[](https://www.npmjs.com/package/shellward)
|
|
10
10
|
[](./LICENSE)
|
|
11
|
-
[](#performance)
|
|
12
12
|
[](#performance)
|
|
13
13
|
|
|
14
|
-
**🌐
|
|
14
|
+
**🌐 官网: https://jnmetacode.github.io/shellward/**
|
|
15
15
|
|
|
16
|
-
[
|
|
16
|
+
[中文](#30-秒合规体检) | [English](#english)
|
|
17
17
|
|
|
18
|
-
## 30
|
|
18
|
+
## 30 秒合规体检
|
|
19
19
|
|
|
20
|
-
|
|
20
|
+
零安装、只读、不上传任何数据。一行命令,扫出你的 AI 项目踩了哪些合规红线:
|
|
21
21
|
|
|
22
22
|
```bash
|
|
23
23
|
npx shellward scan
|
|
24
24
|
```
|
|
25
25
|
|
|
26
|
-
|
|
26
|
+
输出一张映射到 **网安法 / PIPL / 等保2.0 / 数据出境 / AI标识** 的红黄绿评分卡,并精确到 `文件:行`:
|
|
27
27
|
|
|
28
28
|
```
|
|
29
29
|
## 🔍 项目实测风险
|
|
30
30
|
🌐 数据出境风险: 2 | 🔑 硬编码密钥: 3 | 🪪 个人信息暴露: 2 | 📂 .env 权限: 1
|
|
31
31
|
|
|
32
32
|
- .env:2 境外大模型端点: OpenAI — 向其发送个人信息即构成数据出境
|
|
33
|
+
- package.json:12 境外大模型 SDK 依赖: openai — 项目内含数据出境通道
|
|
33
34
|
- src/config.ts:3 硬编码 GitHub Token: ghp_12*** — 凭据不应写入源码
|
|
34
35
|
- customers.csv:2 手机号 13912*** — 个人信息出现在文件中,需评估脱敏
|
|
35
36
|
|
|
36
|
-
合规得分:
|
|
37
|
+
合规得分: 63/100 [C]
|
|
37
38
|
```
|
|
38
39
|
|
|
39
|
-
|
|
40
|
+
`--json` 供 CI · `--ci` 发现 critical 时让构建失败 · `--html report.html` 导出可打印成 PDF 的报告(备案/审计存档)· 也可作 [GitHub Action](#github-action-pr-compliance-gate) 接入 PR 门禁。
|
|
41
|
+
|
|
42
|
+
> 检测重点:**境外大模型端点与 SDK 依赖(数据出境——中国独有、英文工具没有的概念)**、硬编码密钥、文件中的中文 PII、`.env` 暴露。扫到境外模型(如 `openai` 依赖)时,**直接给出境内合规替代**(通义千问 / DeepSeek / Kimi / 智谱)及其 OpenAI 兼容 `base_url`——多数迁移只需改一个 `base_url`。
|
|
43
|
+
|
|
44
|
+
更多命令、运行时防护(MCP / 插件)、与英文文档见下方 [English](#english) 章节。
|
|
45
|
+
|
|
46
|
+
---
|
|
47
|
+
|
|
48
|
+
## English
|
|
49
|
+
|
|
50
|
+
**AI Agent Security & Compliance Gateway** — the AI agent security middleware built for **China's regulatory regime** (CSL / PIPL / MLPS 2.0 / cross-border data / AI labeling). Scan your project for compliance risks, then block prompt injection, data exfiltration, and dangerous commands at runtime. Chinese-language threat detection + Chinese PII + zero dependencies — things English tools don't do.
|
|
40
51
|
|
|
41
|
-
|
|
52
|
+
Quick start: `npx shellward scan` — zero install, read-only, nothing uploaded. Outputs a red/yellow/green scorecard mapped to Chinese regulations plus concrete `file:line` findings, and prescribes domestic compliant model alternatives for any overseas LLM it finds.
|
|
42
53
|
|
|
43
54
|
## Demo
|
|
44
55
|
|
package/dist/cli.js
CHANGED
|
@@ -95,8 +95,8 @@ function runScan(args) {
|
|
|
95
95
|
body,
|
|
96
96
|
'',
|
|
97
97
|
zh
|
|
98
|
-
? '💡
|
|
99
|
-
: '💡 Read-only scan, nothing uploaded.
|
|
98
|
+
? '💡 只读扫描、不上传任何数据。得分仅反映本次可静态观测的项目风险;⚪ 待确认项需把 ShellWard 作为 MCP/插件部署为运行时防护,或人工核验后才能满足。'
|
|
99
|
+
: '💡 Read-only scan, nothing uploaded. The score reflects only statically-observable project risk; ⚪ items require deploying ShellWard as a runtime guard (MCP/plugin) or manual review.',
|
|
100
100
|
];
|
|
101
101
|
process.stdout.write(out.join('\n') + '\n');
|
|
102
102
|
}
|
|
@@ -39,12 +39,21 @@ export interface ComplianceReport {
|
|
|
39
39
|
}
|
|
40
40
|
/** 采集真实环境事实(运行时调用;测试可绕过直接注入 EnvFacts) */
|
|
41
41
|
export declare function gatherEnvFacts(): EnvFacts;
|
|
42
|
+
export interface AuditOptions {
|
|
43
|
+
/**
|
|
44
|
+
* ShellWard 是否作为运行时防护已部署。
|
|
45
|
+
* - true(默认):MCP / 插件上下文,能力层确实在运行,如实评估
|
|
46
|
+
* - false:CLI 静态扫描,未部署运行时 —— 能力/审计类控制项标为顾问态,不虚报"已启用"
|
|
47
|
+
*/
|
|
48
|
+
deployed?: boolean;
|
|
49
|
+
}
|
|
42
50
|
/**
|
|
43
51
|
* 运行合规体检。
|
|
44
52
|
* @param config ShellWard 当前配置
|
|
45
53
|
* @param facts 环境事实;不传则从真实环境采集
|
|
54
|
+
* @param opts 评估上下文(是否已部署运行时)
|
|
46
55
|
*/
|
|
47
|
-
export declare function runComplianceAudit(config: ShellWardConfig, facts?: EnvFacts): ComplianceReport;
|
|
56
|
+
export declare function runComplianceAudit(config: ShellWardConfig, facts?: EnvFacts, opts?: AuditOptions): ComplianceReport;
|
|
48
57
|
export interface ProjectComplianceResult {
|
|
49
58
|
report: ComplianceReport;
|
|
50
59
|
scan: ProjectScanResult;
|
package/dist/compliance/audit.js
CHANGED
|
@@ -67,10 +67,12 @@ function extractTs(line) {
|
|
|
67
67
|
* 运行合规体检。
|
|
68
68
|
* @param config ShellWard 当前配置
|
|
69
69
|
* @param facts 环境事实;不传则从真实环境采集
|
|
70
|
+
* @param opts 评估上下文(是否已部署运行时)
|
|
70
71
|
*/
|
|
71
|
-
export function runComplianceAudit(config, facts) {
|
|
72
|
+
export function runComplianceAudit(config, facts, opts) {
|
|
72
73
|
const env = facts ?? gatherEnvFacts();
|
|
73
|
-
const
|
|
74
|
+
const deployed = opts?.deployed ?? true;
|
|
75
|
+
const results = COMPLIANCE_CONTROLS.map(c => checkControl(c, config, env, deployed));
|
|
74
76
|
let passed = 0, warned = 0, failed = 0, manual = 0;
|
|
75
77
|
for (const r of results) {
|
|
76
78
|
if (r.status === 'pass')
|
|
@@ -116,7 +118,8 @@ export function runProjectComplianceAudit(config, root) {
|
|
|
116
118
|
provider_en: f.provider_en,
|
|
117
119
|
});
|
|
118
120
|
}
|
|
119
|
-
|
|
121
|
+
// CLI 静态扫描:未部署运行时 → 能力/审计类不虚报"已启用",只如实评估项目证据
|
|
122
|
+
const report = runComplianceAudit(config, env, { deployed: false });
|
|
120
123
|
// 发现驱动评分:项目实测风险按严重度扣分(封顶 40),使分数反映"你的真实风险"
|
|
121
124
|
const penalty = computeProjectPenalty(scan);
|
|
122
125
|
if (penalty > 0) {
|
|
@@ -134,7 +137,11 @@ function computeProjectPenalty(scan) {
|
|
|
134
137
|
p += FINDING_PENALTY[f.severity];
|
|
135
138
|
return Math.min(MAX_PROJECT_PENALTY, p);
|
|
136
139
|
}
|
|
137
|
-
function checkControl(c, config, env) {
|
|
140
|
+
function checkControl(c, config, env, deployed) {
|
|
141
|
+
// 静态扫描(未部署运行时)下,能力层/审计日志类控制项无法验证 —— 标为顾问态,绝不虚报"已合规"
|
|
142
|
+
if (!deployed && (c.method === 'capability' || c.method === 'config' || c.method === 'audit')) {
|
|
143
|
+
return mk(c, 'manual', `ShellWard 运行时可提供此防护;当前为静态扫描、未部署,无法验证。整改:${c.remediation_zh}`, `Provided by ShellWard runtime; not verifiable in a static scan. ${c.remediation_en}`);
|
|
144
|
+
}
|
|
138
145
|
switch (c.method) {
|
|
139
146
|
case 'capability': return checkCapability(c, config);
|
|
140
147
|
case 'config': return checkConfig(c, config);
|
|
Binary file
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "shellward",
|
|
3
|
-
"version": "0.6.
|
|
3
|
+
"version": "0.6.7",
|
|
4
4
|
"mcpName": "io.github.jnMetaCode/shellward",
|
|
5
5
|
"description": "AI agent security & MCP security middleware — prompt injection detection, AI firewall, runtime guardrails & data-loss prevention for LLM tool calls. 8-layer defense against data exfiltration & dangerous commands. Zero dependencies. SDK + OpenClaw plugin. Supports LangChain, AutoGPT, Claude Code, Cursor, OpenAI Agents, Hermes Agent.",
|
|
6
6
|
"keywords": [
|
package/src/cli.ts
CHANGED
|
@@ -103,8 +103,8 @@ function runScan(args: string[]) {
|
|
|
103
103
|
body,
|
|
104
104
|
'',
|
|
105
105
|
zh
|
|
106
|
-
? '💡
|
|
107
|
-
: '💡 Read-only scan, nothing uploaded.
|
|
106
|
+
? '💡 只读扫描、不上传任何数据。得分仅反映本次可静态观测的项目风险;⚪ 待确认项需把 ShellWard 作为 MCP/插件部署为运行时防护,或人工核验后才能满足。'
|
|
107
|
+
: '💡 Read-only scan, nothing uploaded. The score reflects only statically-observable project risk; ⚪ items require deploying ShellWard as a runtime guard (MCP/plugin) or manual review.',
|
|
108
108
|
]
|
|
109
109
|
process.stdout.write(out.join('\n') + '\n')
|
|
110
110
|
}
|
package/src/compliance/audit.ts
CHANGED
|
@@ -113,14 +113,25 @@ function extractTs(line: string): string | undefined {
|
|
|
113
113
|
return m?.[1]
|
|
114
114
|
}
|
|
115
115
|
|
|
116
|
+
export interface AuditOptions {
|
|
117
|
+
/**
|
|
118
|
+
* ShellWard 是否作为运行时防护已部署。
|
|
119
|
+
* - true(默认):MCP / 插件上下文,能力层确实在运行,如实评估
|
|
120
|
+
* - false:CLI 静态扫描,未部署运行时 —— 能力/审计类控制项标为顾问态,不虚报"已启用"
|
|
121
|
+
*/
|
|
122
|
+
deployed?: boolean
|
|
123
|
+
}
|
|
124
|
+
|
|
116
125
|
/**
|
|
117
126
|
* 运行合规体检。
|
|
118
127
|
* @param config ShellWard 当前配置
|
|
119
128
|
* @param facts 环境事实;不传则从真实环境采集
|
|
129
|
+
* @param opts 评估上下文(是否已部署运行时)
|
|
120
130
|
*/
|
|
121
|
-
export function runComplianceAudit(config: ShellWardConfig, facts?: EnvFacts): ComplianceReport {
|
|
131
|
+
export function runComplianceAudit(config: ShellWardConfig, facts?: EnvFacts, opts?: AuditOptions): ComplianceReport {
|
|
122
132
|
const env = facts ?? gatherEnvFacts()
|
|
123
|
-
const
|
|
133
|
+
const deployed = opts?.deployed ?? true
|
|
134
|
+
const results: ControlResult[] = COMPLIANCE_CONTROLS.map(c => checkControl(c, config, env, deployed))
|
|
124
135
|
|
|
125
136
|
let passed = 0, warned = 0, failed = 0, manual = 0
|
|
126
137
|
for (const r of results) {
|
|
@@ -170,7 +181,8 @@ export function runProjectComplianceAudit(config: ShellWardConfig, root: string)
|
|
|
170
181
|
})
|
|
171
182
|
}
|
|
172
183
|
|
|
173
|
-
|
|
184
|
+
// CLI 静态扫描:未部署运行时 → 能力/审计类不虚报"已启用",只如实评估项目证据
|
|
185
|
+
const report = runComplianceAudit(config, env, { deployed: false })
|
|
174
186
|
|
|
175
187
|
// 发现驱动评分:项目实测风险按严重度扣分(封顶 40),使分数反映"你的真实风险"
|
|
176
188
|
const penalty = computeProjectPenalty(scan)
|
|
@@ -192,7 +204,13 @@ function computeProjectPenalty(scan: ProjectScanResult): number {
|
|
|
192
204
|
return Math.min(MAX_PROJECT_PENALTY, p)
|
|
193
205
|
}
|
|
194
206
|
|
|
195
|
-
function checkControl(c: ComplianceControl, config: ShellWardConfig, env: EnvFacts): ControlResult {
|
|
207
|
+
function checkControl(c: ComplianceControl, config: ShellWardConfig, env: EnvFacts, deployed: boolean): ControlResult {
|
|
208
|
+
// 静态扫描(未部署运行时)下,能力层/审计日志类控制项无法验证 —— 标为顾问态,绝不虚报"已合规"
|
|
209
|
+
if (!deployed && (c.method === 'capability' || c.method === 'config' || c.method === 'audit')) {
|
|
210
|
+
return mk(c, 'manual',
|
|
211
|
+
`ShellWard 运行时可提供此防护;当前为静态扫描、未部署,无法验证。整改:${c.remediation_zh}`,
|
|
212
|
+
`Provided by ShellWard runtime; not verifiable in a static scan. ${c.remediation_en}`)
|
|
213
|
+
}
|
|
196
214
|
switch (c.method) {
|
|
197
215
|
case 'capability': return checkCapability(c, config)
|
|
198
216
|
case 'config': return checkConfig(c, config)
|
|
Binary file
|