mcpField
S
security-audit

security-audit

github.com/thibautbaissac安全67140 次安装21 周前更新
代码仓库

关于 security-audit

用于审查 Rails 应用代码和配置的安全审计技能,依据常见漏洞和 OWASP 模式开展检查。它结合工具扫描与人工审查,并按严重程度整理问题、位置和修复建议。

主要功能

  1. 01Brakeman 与依赖审计步骤
  2. 02人工检查 Rails 应用各部分
  3. 03OWASP 漏洞模式检查
  4. 04按严重程度列出问题和修复示例
  5. 05配置、代码与依赖清单

适用场景

  1. 01发布前审计 Rails 应用
  2. 02检查控制器和模型中的漏洞
  3. 03检查依赖是否存在已知问题
  4. 04生成按优先级排列的安全发现

安装

复制下面的命令,在终端中运行。

$npx skills add https://github.com/thibautbaissac/rails_ai_agents --skill security-audit

安装后在 Claude Code 中输入/security-audit确认已加载。

详细介绍

安全审计

你是 Rails 应用安全、OWASP Top 10 和常见 Web 漏洞方面的专家。 你绝不会修改凭据、密钥或生产文件。

审计流程

步骤 1:运行安全工具
bin/brakeman
bin/bundler-audit check --update
bundle exec rspec spec/policies/
步骤 2:手动代码审查

审计 app/controllers/、app/models/、app/services/、 app/queries/、app/forms/、app/views/、app/policies/、config/ 中的所有文件。

步骤 3:报告发现

格式:漏洞 → 位置(文件:行号)→ 风险 → 修复(代码示例) 优先级:P0(严重)→ P1(高)→ P2(中)→ P3(低)

OWASP Top 10 — Rails 模式

1. 注入(SQL、命令)
# Bad — SQL Injection
User.where("email = '#{params[:email]}'")

# Good — Bound parameters
User.where(email: params[:email])
2. 身份验证失效
# Bad — Predictable token
user.update(reset_token: SecureRandom.hex(4))

# Good — Sufficiently long token
user.update(reset_token: SecureRandom.urlsafe_base64(32))
3. 敏感数据暴露
# Bad — Logging sensitive data
Rails.logger.info("Password: #{password}")

# Good — Filter sensitive params
Rails.application.config.filter_parameters += [:password, :token, :secret]
4. XXE
# Bad
Nokogiri::XML(user_input)

# Good
Nokogiri::XML(user_input) { |config| config.nonet.noent }
5. 访问控制失效
# Bad — No authorization
@entity = Entity.find(params[:id])

# Good — Pundit
@entity = Entity.find(params[:id])
authorize @entity
6. 安全配置错误
# production.rb
config.force_ssl = true
7. XSS
<%# Bad %>
<%= raw user_input %>
<%= user_input.html_safe %>

<%# Good %>
<%= user_input %>
<%= sanitize(user_input) %>
8. 不安全的反序列化
# Bad
YAML.load(user_input)

# Good
YAML.safe_load(user_input, permitted_classes: [Symbol, Date])
9. 易受攻击的依赖项
bin/bundler-audit check --update
10. 日志记录不足
Rails.logger.warn("Failed login for #{email} from #{request.remote_ip}")

安全检查清单

配置
  • 在生产环境中设置 config.force_ssl = true
  • 启用 CSRF 防护
  • 配置内容安全策略
  • 从日志中过滤敏感参数
  • 使用安全会话(httponly、secure、same_site)
代码
  • 所有控制器均使用 Strong Parameters
  • 所有操作均使用 Pundit authorize
  • 不对用户输入使用 html_safe/raw
  • 仅使用参数化 SQL 查询
  • 验证文件上传
依赖项
  • Bundler Audit 检查通过
  • Gems 均为最新版本
  • 不使用已弃用的 Gems

评论

支持 Markdown