跳到主要内容

audit rules

浏览、启用、禁用和自定义 audit 规则。

skillshare audit rules                          # 交互式 TUI 规则浏览器
skillshare audit rules --no-tui # 纯文本表格
skillshare audit rules --pattern credential-access # 按 pattern 筛选
skillshare audit rules --severity high # 按 severity 筛选
skillshare audit rules --disabled # 仅显示已禁用的规则
skillshare audit rules --format json # JSON 输出

skillshare audit rules disable prompt-injection-0 # 禁用单条规则
skillshare audit rules disable --pattern credential-access # 禁用整个 group
skillshare audit rules enable prompt-injection-0 # 重新启用规则
skillshare audit rules enable --pattern credential-access # 重新启用整个 group

skillshare audit rules severity destructive-commands-2 medium # 降级单条规则
skillshare audit rules severity --pattern destructive-commands low # 降级整个 group
skillshare audit rules reset # 移除所有自定义规则,恢复默认值

skillshare audit rules init # 创建初始 audit-rules.yaml
skillshare audit rules init -p # 创建 project 级别的规则文件

Pattern 级规则

你可以在 audit-rules.yaml 中禁用或覆盖整个 pattern group:

rules:
# Disable all credential-access rules
- pattern: credential-access
enabled: false

# But keep .env detection
- id: credential-access-env-file
enabled: true

# Downgrade all destructive-commands to MEDIUM
- pattern: destructive-commands
severity: MEDIUM

Pattern 级条目只使用 pattern 而不使用 id。合并顺序:pattern 级规则先生效,之后 id 级规则可以覆盖某个被禁用 group 内的个别条目。

自定义规则

你可以使用 YAML 文件添加、覆盖或禁用 audit 规则。规则按以下顺序合并:内置 → global 用户 → project 用户

使用 --init-rules(或 audit rules init)创建一个带注释示例的初始文件:

skillshare audit --init-rules         # Create global rules file
skillshare audit -p --init-rules # Create project rules file

文件位置

作用域路径
Global~/.config/skillshare/audit-rules.yaml
Project.skillshare/audit-rules.yaml

格式

rules:
# Add a new rule
- id: my-custom-rule
severity: HIGH
pattern: custom-check
message: "Custom pattern detected"
regex: 'DANGEROUS_PATTERN'

# Add a rule with an exclude (suppress matches on certain lines)
- id: url-check
severity: MEDIUM
pattern: url-usage
message: "External URL detected"
regex: 'https?://\S+'
exclude: 'https?://(localhost|127\.0\.0\.1)'

# Override an existing built-in rule (match by id)
- id: destructive-commands-2
severity: MEDIUM
pattern: destructive-commands
message: "Sudo usage (downgraded to MEDIUM)"
regex: '(?i)\bsudo\s+'

# Disable a built-in rule
- id: insecure-http-0
enabled: false

# Disable the dangling-link structural check
- id: dangling-link
enabled: false

字段

字段是否必填说明
id稳定标识符。匹配的 ID 会覆盖内置规则。
severity是*CRITICALHIGHMEDIUMLOWINFO
pattern是*规则类别名称(例如 prompt-injection
message是*在发现结果中展示的可读描述
regex是*用于匹配每一行的正则表达式
exclude如果某一行同时匹配 regexexclude,该发现结果会被抑制
enabled设为 false 以禁用某条规则。禁用时只需提供 id

*除非 enabled: false,否则为必填。

合并语义

每一层(先 global,再 project)都在上一层的基础上叠加应用:

  • 相同 id + enabled: false → 禁用该规则
  • 相同 id + 其他字段 → 替换整条规则
  • 新的 id → 作为自定义规则追加
  • pattern(无 id)+ enabled: false → 禁用所有匹配该 pattern 的规则
  • pattern + severity → 覆盖所有匹配规则的 severity
  • 先 pattern 后 id → id 级条目可以在被禁用的 pattern group 内重新启用个别规则

实用模板

可以此为起点,进行贴近实际场景的策略调优:

rules:
# Downgrade hardcoded-secret to MEDIUM for educational/reference skills
- pattern: hardcoded-secret
severity: MEDIUM

# Override built-in suspicious-fetch with internal allowlist
- id: suspicious-fetch-0
severity: MEDIUM
pattern: suspicious-fetch
message: "External URL used in command context"
regex: '(?i)(curl|wget|invoke-webrequest|iwr)\s+https?://'
exclude: '(?i)https?://(localhost|127\.0\.0\.1|artifacts\.company\.internal|registry\.company\.internal)'

# Governance exception: disable noisy insecure-http signal
- id: insecure-http-0
enabled: false

使用 init 快速上手

audit rules init(或 audit --init-rules)会创建一个带注释示例的初始 audit-rules.yaml,你可以取消注释并进行调整:

skillshare audit rules init          # → ~/.config/skillshare/audit-rules.yaml
skillshare audit rules init -p # → .skillshare/audit-rules.yaml

生成的文件内容如下:

# Custom audit rules for skillshare.
# Rules are merged on top of built-in rules in order:
# built-in → global (~/.config/skillshare/audit-rules.yaml)
# → project (.skillshare/audit-rules.yaml)
#
# Each rule needs: id, severity, pattern, message, regex.
# Optional: exclude (suppress match), enabled (false to disable).

rules:
# Example: flag TODO comments as informational
# - id: flag-todo
# severity: MEDIUM
# pattern: todo-comment
# message: "TODO comment found"
# regex: '(?i)\bTODO\b'

# Example: disable a built-in rule by id
# - id: insecure-http-0
# enabled: false

# Example: disable the dangling-link structural check
# - id: dangling-link
# enabled: false

# Example: override a built-in rule (match by id, change severity)
# - id: destructive-commands-2
# severity: MEDIUM
# pattern: destructive-commands
# message: "Sudo usage (downgraded)"
# regex: '(?i)\bsudo\s+'

如果文件已存在,init 会以错误退出——它绝不会覆盖已有规则。

工作流程:修复误报

自定义规则的常见原因是某个合法 skill 触发了内置规则。以下是一个分步示例:

1. 运行 audit,看到误报:

$ skillshare audit ci-helper
[1/1] ! ci-helper 0.2s
└─ HIGH: Destructive command pattern (SKILL.md:42)
"sudo apt-get install -y jq"

2. 从内置规则表中找到规则 ID:

pattern destructive-commands 中带有 sudo 的匹配对应规则 destructive-commands-2

3. 创建自定义规则文件(如果还没有的话):

skillshare audit rules init

4. 添加规则覆盖,将其抑制或降级:

# ~/.config/skillshare/audit-rules.yaml
rules:
# Downgrade sudo to MEDIUM for CI automation skills
- id: destructive-commands-2
severity: MEDIUM
pattern: destructive-commands
message: "Sudo usage (downgraded for CI automation)"
regex: '(?i)\bsudo\s+'

或直接完全禁用它:

rules:
- id: destructive-commands-2
enabled: false

5. 重新运行 audit 以确认:

$ skillshare audit ci-helper
[1/1] ✓ ci-helper 0.1s # Now passes (or shows MEDIUM instead of HIGH)

验证更改

编辑规则后,重新运行 audit 以验证:

skillshare audit                     # Check all skills
skillshare audit <name> # Check a specific skill
skillshare audit --json | jq '.skills[].findings' # Inspect findings programmatically

摘要解读:

  • Failed 统计的是发现结果达到或超过当前阈值的 skills 数量。
  • Warning 统计的是发现结果低于阈值但高于"干净"状态的 skills 数量(例如当阈值为 CRITICAL 时,统计 HIGH/MEDIUM/LOW/INFO)。

内置规则 ID

使用 id 值来覆盖或禁用特定的内置规则:

基于正则表达式的规则的权威来源: internal/audit/rules.yaml

结构性、分级和跨 skill 检查

dangling-linkcontent-tamperedcontent-oversizecontent-missingcontent-unexpected 属于结构性检查(文件系统查找和哈希比较,而非正则表达式)。low-analyzability 是由 Analyzability Score 生成的可分析性发现结果tier-stealthtier-destructive-networktier-network-heavytier-interpretertier-interpreter-network 是由 Command Safety Tiering profile 生成的分级组合发现结果cross-skill-* 发现结果由 Cross-Skill Interaction Detection 生成。以上这些都出现在下面的表格中,但并未定义在 rules.yaml 里。

IDPatternSeverity
prompt-injection-0prompt-injectionCRITICAL
prompt-injection-1prompt-injectionCRITICAL
prompt-injection-2prompt-injectionHIGH
prompt-injection-3prompt-injectionCRITICAL
prompt-injection-4prompt-injectionCRITICAL
hidden-unicode-1invisible-payloadCRITICAL
data-exfiltration-0data-exfiltrationCRITICAL
data-exfiltration-1data-exfiltrationCRITICAL
data-exfiltration-2data-exfiltrationMEDIUM
data-exfiltration-3data-exfiltrationHIGH
credential-access-ssh-private-keycredential-accessCRITICAL
credential-access-env-filecredential-accessCRITICAL
credential-access-aws-credentialscredential-accessCRITICAL
credential-access-etc-shadowcredential-accessCRITICAL
credential-access-git-credentialscredential-accessCRITICAL
credential-access-netrccredential-accessCRITICAL
credential-access-gnupgcredential-accessCRITICAL
credential-access-kube-configcredential-accessCRITICAL
credential-access-vault-tokencredential-accessCRITICAL
credential-access-terraform-credscredential-accessCRITICAL
credential-access-gnome-keyringcredential-accessCRITICAL
credential-access-npmrccredential-accessCRITICAL
credential-access-pypirccredential-accessCRITICAL
credential-access-gem-credentialscredential-accessCRITICAL
credential-access-ssl-privatecredential-accessCRITICAL
credential-access-ssh-host-keycredential-accessCRITICAL
credential-access-pgpasscredential-accessCRITICAL
credential-access-mysql-cnfcredential-accessCRITICAL
credential-access-etc-passwdcredential-accessMEDIUM
credential-access-azure-credscredential-accessHIGH
credential-access-gcloud-credscredential-accessHIGH
credential-access-docker-configcredential-accessHIGH
credential-access-gh-cli-tokencredential-accessHIGH
credential-access-password-storecredential-accessHIGH
credential-access-macos-keychain-usercredential-accessHIGH
credential-access-macos-keychain-syscredential-accessHIGH
credential-access-terraformrccredential-accessHIGH
credential-access-cargo-credentialscredential-accessHIGH
credential-access-op-clicredential-accessHIGH
credential-access-age-keyscredential-accessHIGH
credential-access-shell-historycredential-accessLOW
credential-access-openvpncredential-accessLOW
credential-access-auth-logcredential-accessINFO
credential-access-unknown-dotdircredential-accessINFO

说明: 上面每个凭证条目还会为不同访问方式生成变体 ID:-copy-redirect-dd-exfil(例如 credential-access-ssh-private-key-copy)。要禁用某个特定变体,请在 audit-rules.yaml 中使用其完整 ID。

IDPatternSeverity
hidden-unicode-0hidden-unicodeHIGH
hidden-unicode-2hidden-unicodeHIGH
config-manipulation-0config-manipulationHIGH
hidden-comment-injection-1hidden-comment-injectionHIGH
self-propagation-0self-propagationHIGH
destructive-commands-0destructive-commandsHIGH
destructive-commands-1destructive-commandsHIGH
destructive-commands-2destructive-commandsHIGH
destructive-commands-3destructive-commandsHIGH
destructive-commands-4destructive-commandsHIGH
dynamic-code-exec-0dynamic-code-execHIGH
dynamic-code-exec-1dynamic-code-execHIGH
shell-execution-0shell-executionHIGH
hidden-comment-injection-0hidden-comment-injectionHIGH
obfuscation-0obfuscationHIGH
fetch-with-pipe-0fetch-with-pipeHIGH
fetch-with-pipe-1fetch-with-pipeHIGH
fetch-with-pipe-2fetch-with-pipeHIGH
hardcoded-secret-0hardcoded-secretHIGH
hardcoded-secret-1hardcoded-secretHIGH
hardcoded-secret-2hardcoded-secretHIGH
hardcoded-secret-3hardcoded-secretHIGH
hardcoded-secret-4hardcoded-secretHIGH
hardcoded-secret-5hardcoded-secretHIGH
hardcoded-secret-6hardcoded-secretHIGH
hardcoded-secret-7hardcoded-secretHIGH
hardcoded-secret-8hardcoded-secretHIGH
hardcoded-secret-9hardcoded-secretHIGH
data-uri-0data-uriMEDIUM
escape-obfuscation-0escape-obfuscationMEDIUM
suspicious-fetch-0suspicious-fetchMEDIUM
ip-address-url-0ip-address-urlMEDIUM
hidden-unicode-3hidden-unicodeMEDIUM
untrusted-install-0untrusted-installMEDIUM
untrusted-install-1untrusted-installMEDIUM
insecure-http-0insecure-httpLOW
external-link-0external-linkLOW
dangling-linkdangling-linkLOW
content-tamperedcontent-tamperedMEDIUM
content-oversizecontent-oversizeMEDIUM
content-missingcontent-missingLOW
content-unexpectedcontent-unexpectedLOW
shell-chain-0shell-chainINFO
low-analyzabilitylow-analyzabilityINFO
tier-stealthtier-stealthCRITICAL
tier-destructive-networktier-destructive-networkHIGH
tier-network-heavytier-network-heavyMEDIUM
tier-interpretertier-interpreterINFO
tier-interpreter-networktier-interpreter-networkMEDIUM
cross-skill-exfiltrationcross-skill-exfiltrationHIGH
cross-skill-privilege-networkcross-skill-privilege-networkMEDIUM
cross-skill-stealthcross-skill-stealthHIGH
cross-skill-cred-interpretercross-skill-cred-interpreterMEDIUM

子命令

子命令说明
rules浏览、启用和禁用 audit 规则
rules disable <id>按 ID 禁用单条规则
rules disable --pattern <p>禁用所有匹配某个 pattern 的规则
rules enable <id>按 ID 重新启用单条规则
rules enable --pattern <p>重新启用所有匹配某个 pattern 的规则
rules severity <id> <level>覆盖单条规则的 severity
rules severity --pattern <p> <level>覆盖某个 pattern group 中所有规则的 severity
rules reset移除所有自定义规则(恢复内置默认值)
rules init创建初始 audit-rules.yaml(等同于 audit --init-rules

另请参阅