mcpField
S
security-audit

security-audit

github.com/thibautbaissacセキュリティ67140 回インストール21 週間前に更新
リポジトリ

security-audit について

Rails アプリケーションのコードと設定を、一般的な脆弱性や OWASP のパターンに照らして確認するセキュリティ監査スキルです。ツールによる検査と手動レビューを行い、深刻度、該当箇所、修正案を整理します。

主な機能

  1. 01Brakeman と依存関係監査の手順
  2. 02Rails アプリ各領域の手動レビュー
  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、一般的なウェブ脆弱性に精通しています。 認証情報、シークレット、本番環境のファイルは決して変更しません。

監査プロセス

ステップ 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 で問題がない
  • Gem を最新の状態にする
  • 放棄された Gem がない

コメント