brakeman
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
ChineseBrakeman Security Scanner
Brakeman安全扫描器
Overview
概述
Brakeman is a static analysis tool that checks Ruby on Rails applications for security vulnerabilities without requiring a running application. It analyzes source code to detect common security issues including SQL injection, cross-site scripting (XSS), command injection, mass assignment, and many other vulnerability types.
Brakeman是一款静态分析工具,无需运行应用即可检查Ruby on Rails应用的安全漏洞。它通过分析源代码来检测常见的安全问题,包括SQL注入、跨站脚本(XSS)、命令注入、批量赋值等多种漏洞类型。
Installation
安装
Verify Brakeman is installed before running scans. If not present, install using one of these methods:
bash
undefined在运行扫描前请确认已安装Brakeman。若未安装,可通过以下方式之一进行安装:
bash
undefinedUsing RubyGems (recommended)
使用RubyGems(推荐)
gem install brakeman
gem install brakeman
Using Bundler (add to Gemfile)
使用Bundler(添加到Gemfile)
group :development do
gem 'brakeman', require: false
end
group :development do
gem 'brakeman', require: false
end
Using Docker
使用Docker
docker pull presidentbeef/brakeman
Brakeman requires Ruby 3.0.0+ to run, but can analyze code written with Ruby 2.0+ syntax. It works with Rails 2.3.x through 8.x.docker pull presidentbeef/brakeman
Brakeman运行需要Ruby 3.0.0+,但可以分析使用Ruby 2.0+语法编写的代码。它兼容Rails 2.3.x至8.x版本。Basic Usage
基础用法
Quick Scan
快速扫描
Run a basic security scan from the Rails application root:
bash
brakemanFrom outside the Rails root:
bash
brakeman /path/to/rails/application从Rails应用根目录运行基础安全扫描:
bash
brakeman从Rails根目录外部运行:
bash
brakeman /path/to/rails/applicationOutput Formats
输出格式
Generate reports in various formats:
bash
undefined生成多种格式的报告:
bash
undefinedHTML report
HTML报告
brakeman -o report.html
brakeman -o report.html
JSON report (useful for comparison and automation)
JSON报告(适用于对比和自动化场景)
brakeman -o report.json
brakeman -o report.json
Multiple output formats simultaneously
同时生成多种输出格式
brakeman -o report.html -o report.json
brakeman -o report.html -o report.json
Output to console with color and file
带颜色输出到控制台并保存到文件
brakeman --color -o /dev/stdout -o report.json
brakeman --color -o /dev/stdout -o report.json
Quiet mode (suppress informational messages)
静默模式(抑制信息性消息)
brakeman -q
Available output formats: `text`, `html`, `tabs`, `json`, `junit`, `markdown`, `csv`, `codeclimate`, `sonar`brakeman -q
支持的输出格式:`text`, `html`, `tabs`, `json`, `junit`, `markdown`, `csv`, `codeclimate`, `sonar`Workflow Decision Tree
工作流决策树
Is Brakeman already installed?
├─ No → Install using gem, bundler, or docker
└─ Yes → Continue
What is the goal?
├─ Initial security assessment → Run basic scan: `brakeman`
├─ Generate report for review → Choose format: `brakeman -o report.html`
├─ CI/CD integration → Use JSON output: `brakeman -o report.json`
├─ Too many warnings → Adjust confidence level or filter checks
├─ False positives → Use interactive ignore tool: `brakeman -I`
├─ Compare with previous scan → Use --compare flag
└─ Configuration needed → Create config/brakeman.yml是否已安装Brakeman?
├─ 否 → 使用gem、bundler或docker安装
└─ 是 → 继续
你的目标是什么?
├─ 初始安全评估 → 运行基础扫描:`brakeman`
├─ 生成供审核的报告 → 选择格式:`brakeman -o report.html`
├─ CI/CD集成 → 使用JSON输出:`brakeman -o report.json`
├─ 警告过多 → 调整置信度等级或过滤检查项
├─ 误报 → 使用交互式忽略工具:`brakeman -I`
├─ 与之前的扫描结果对比 → 使用--compare参数
└─ 需要配置 → 创建config/brakeman.ymlConfidence Levels
置信度等级
Brakeman assigns confidence levels to each warning:
- High: Simple warning or user input very likely being used unsafely
- Medium: Unsafe use of variable that may or may not be user input
- Weak: User input indirectly used in potentially unsafe manner
Filter warnings by confidence level:
bash
undefinedBrakeman会为每个警告分配置信度等级:
- 高:简单明确的警告,或用户输入极有可能被不安全使用
- 中:变量被不安全使用,但该变量可能是也可能不是用户输入
- 低:用户输入被间接用于潜在不安全的场景
按置信度等级过滤警告:
bash
undefinedOnly high confidence warnings
仅显示高置信度警告
brakeman -w3
brakeman -w3
High and medium confidence warnings
显示高和中置信度警告
brakeman -w2
brakeman -w2
All warnings (default)
显示所有警告(默认)
brakeman -w1
undefinedbrakeman -w1
undefinedManaging Warnings
警告管理
Filtering Checks
过滤检查项
Run only specific checks:
bash
undefined仅运行特定的检查项:
bash
undefinedRun only SQL and XSS checks
仅运行SQL和XSS检查
brakeman -t SQL,CrossSiteScripting
brakeman -t SQL,CrossSiteScripting
Skip specific checks
跳过特定检查项
brakeman -x DefaultRoutes,Redirect
brakeman -x DefaultRoutes,Redirect
Skip multiple checks
跳过多个检查项
brakeman -x DefaultRoutes,Redirect,SQL
Use `brakeman --checks` to list all available check names (case-sensitive).brakeman -x DefaultRoutes,Redirect,SQL
使用`brakeman --checks`查看所有可用的检查项名称(区分大小写)。Interactive Ignore Configuration
交互式忽略配置
Manage false positives interactively:
bash
brakeman -IThis launches an interactive tool that:
- Presents each warning with context
- Allows you to ignore, skip, or add notes
- Saves configuration to
config/brakeman.ignore
Options during interactive review:
- - Add warning to ignore list
i - - Add warning to ignore list with note (recommended)
n - - Skip this warning
s - - Remove from ignore list
u - - Ignore remaining warnings
a - - Skip remaining warnings
k - - Quit without saving
q
Always add notes when ignoring warnings to document why they're false positives.
以交互方式管理误报:
bash
brakeman -I这会启动一个交互式工具,功能如下:
- 展示每个警告及上下文信息
- 允许你忽略、跳过或添加备注
- 将配置保存到
config/brakeman.ignore
交互式审核中的操作选项:
- - 将警告添加到忽略列表
i - - 将警告添加到忽略列表并添加备注(推荐)
n - - 跳过此警告
s - - 从忽略列表中移除
u - - 忽略剩余所有警告
a - - 跳过剩余所有警告
k - - 不保存并退出
q
忽略警告时务必添加备注,说明标记为误报的原因。
Show Ignored Warnings
查看已忽略的警告
Temporarily view ignored warnings without affecting exit code:
bash
brakeman --show-ignored临时查看已忽略的警告,且不影响退出码:
bash
brakeman --show-ignoredComparing Scans
扫描结果对比
Track security improvements or regressions by comparing scans:
bash
undefined通过对比扫描结果来跟踪安全状况的改进或倒退:
bash
undefinedGenerate baseline report
生成基准报告
brakeman -o baseline.json
brakeman -o baseline.json
Run new scan and compare
运行新扫描并对比
brakeman --compare baseline.json
Output shows:
- Fixed warnings (resolved since baseline)
- New warnings (introduced since baseline)brakeman --compare baseline.json
输出内容包括:
- 已修复的警告(自基准扫描后解决的问题)
- 新增的警告(自基准扫描后出现的问题)Configuration
配置
Configuration Files
配置文件
Store Brakeman options in YAML configuration files. Default locations (checked in order):
./config/brakeman.yml~/.brakeman/config.yml/etc/brakeman/config.yml
Specify a custom configuration file:
bash
brakeman -c custom_config.yml可将Brakeman的选项存储在YAML配置文件中。默认检查顺序如下:
./config/brakeman.yml~/.brakeman/config.yml/etc/brakeman/config.yml
指定自定义配置文件:
bash
brakeman -c custom_config.ymlGenerate Configuration
生成配置
Output current options to create a configuration file:
bash
brakeman -C --skip-files plugins/ > config/brakeman.ymlCommand-line options override configuration file settings.
将当前选项输出到文件以创建配置文件:
bash
brakeman -C --skip-files plugins/ > config/brakeman.yml命令行选项会覆盖配置文件中的设置。
Example Configuration
配置示例
yaml
---
:skip_files:
- vendor/
- lib/legacy/
:confidence_level: 2
:output_files:
- reports/brakeman.html
- reports/brakeman.json
:quiet: trueyaml
---
:skip_files:
- vendor/
- lib/legacy/
:confidence_level: 2
:output_files:
- reports/brakeman.html
- reports/brakeman.json
:quiet: truePerformance Optimization
性能优化
Speed up scans with faster mode (skips some features):
bash
brakeman --fasterEquivalent to:
--skip-libs --no-branchingWarning: May miss some vulnerabilities. Use only when scan speed is critical.
Skip problematic files or directories:
bash
brakeman --skip-files file1.rb,vendor/,legacy/使用快速模式加速扫描(会跳过部分功能):
bash
brakeman --faster等效于:
--skip-libs --no-branching注意:可能会遗漏部分漏洞。仅在扫描速度至关重要时使用。
跳过有问题的文件或目录:
bash
brakeman --skip-files file1.rb,vendor/,legacy/Advanced Options
高级选项
Safe Methods
安全方法
Mark custom sanitizing methods as safe to reduce false positives:
bash
brakeman --safe-methods sanitize_input,clean_html将自定义的清理方法标记为安全,以减少误报:
bash
brakeman --safe-methods sanitize_input,clean_htmlExit Codes
退出码
Control exit code behavior:
bash
undefined控制退出码的行为:
bash
undefinedDon't exit with error on warnings
发现警告时不返回错误退出码
brakeman --no-exit-on-warn
brakeman --no-exit-on-warn
Don't exit with error on scanning errors
扫描出错时不返回错误退出码
brakeman --no-exit-on-error
brakeman --no-exit-on-error
Both
同时启用上述两项
brakeman --no-exit-on-warn --no-exit-on-error
Default behavior: Non-zero exit code if warnings found or errors encountered.brakeman --no-exit-on-warn --no-exit-on-error
默认行为:如果发现警告或遇到错误,返回非零退出码。Debugging
调试
Enable verbose debugging output:
bash
brakeman -d启用详细的调试输出:
bash
brakeman -dCI/CD Integration
CI/CD集成
GitHub Actions
GitHub Actions
Several Brakeman actions available on GitHub Marketplace. Search for "brakeman" in GitHub Actions.
GitHub Marketplace上有多个Brakeman相关的Action。在GitHub Actions中搜索“brakeman”即可找到。
Jenkins
Jenkins
Brakeman plugin available for Jenkins/Hudson integration. See documentation at brakemanscanner.org/docs/jenkins/
有适用于Jenkins/Hudson的Brakeman插件。请查看brakemanscanner.org/docs/jenkins/上的文档。
Guard
Guard
For continuous testing during development:
bash
gem install guard-brakeman用于开发过程中的持续测试:
bash
gem install guard-brakemanGeneric CI Integration
通用CI集成
bash
#!/bin/bashbash
#!/bin/bashExample CI script
CI脚本示例
Run Brakeman and save results
运行Brakeman并保存结果
brakeman -o brakeman-report.json -o brakeman-report.html --no-exit-on-warn
brakeman -o brakeman-report.json -o brakeman-report.html --no-exit-on-warn
Check if there are any high confidence warnings
检查是否存在高置信度警告
if brakeman -w3 --quiet; then
echo "No high confidence security warnings found"
exit 0
else
echo "High confidence security warnings detected!"
exit 1
fi
undefinedif brakeman -w3 --quiet; then
echo "未发现高置信度安全警告"
exit 0
else
echo "检测到高置信度安全警告!"
exit 1
fi
undefinedWarning Types Reference
警告类型参考
Brakeman detects 30+ vulnerability types. For detailed descriptions and remediation guidance, see .
references/warning_types.mdCommon warning types include:
- SQL Injection
- Cross-Site Scripting (XSS)
- Command Injection
- Mass Assignment
- Cross-Site Request Forgery (CSRF)
- Remote Code Execution
- Path Traversal
- Unsafe Redirects
- File Access
- Authentication Issues
- SSL Verification Bypass
- Unmaintained Dependencies
- And many more...
Brakeman可检测30多种漏洞类型。如需详细描述和修复指导,请查看。
references/warning_types.md常见的警告类型包括:
- SQL注入
- 跨站脚本(XSS)
- 命令注入
- 批量赋值
- 跨站请求伪造(CSRF)
- 远程代码执行
- 路径遍历
- 不安全重定向
- 文件访问
- 认证问题
- SSL验证绕过
- 未维护的依赖
- 以及更多...
Command Reference
命令参考
For comprehensive option reference including less common flags and detailed explanations, see .
references/command_options.md如需包含冷门参数和详细说明的完整选项参考,请查看。
references/command_options.mdBest Practices
最佳实践
- Run regularly: Integrate into development workflow and CI/CD pipeline
- Start with high confidence: Use initially to focus on critical issues
-w3 - Document ignored warnings: Always add notes explaining why warnings are ignored
- Compare scans: Use to track security posture over time
--compare - Review all warnings: Even weak warnings can indicate real vulnerabilities
- Keep Brakeman updated: Security checks improve with each release
- Don't ignore blindly: Investigate each warning before marking as false positive
- Use configuration files: Maintain consistent scan settings across team
- Generate multiple formats: HTML for review, JSON for automation
- Test ignored warnings periodically: Re-review with
--show-ignored
- 定期运行:集成到开发工作流和CI/CD流水线中
- 从高置信度开始:初始使用来聚焦关键问题
-w3 - 记录忽略的警告:始终添加备注说明忽略警告的原因
- 对比扫描结果:使用跟踪安全状况的变化
--compare - 审核所有警告:即使是低置信度警告也可能指向真实漏洞
- 保持Brakeman更新:每次版本更新都会优化安全检查能力
- 不要盲目忽略:在标记为误报前先调查每个警告
- 使用配置文件:在团队中保持一致的扫描设置
- 生成多种格式:HTML格式用于审核,JSON格式用于自动化
- 定期复查已忽略的警告:使用重新审核
--show-ignored
Common Workflows
常见工作流
Initial Security Audit
初始安全审计
bash
undefinedbash
undefined1. Run comprehensive scan
1. 运行全面扫描
brakeman -o initial-audit.html -o initial-audit.json
brakeman -o initial-audit.html -o initial-audit.json
2. Review high confidence warnings first
2. 先查看高置信度警告
brakeman -w3 -o high-confidence.html
brakeman -w3 -o high-confidence.html
3. Interactively manage false positives
3. 以交互方式管理误报
brakeman -I
brakeman -I
4. Save configuration for future scans
4. 保存配置供后续扫描使用
brakeman -C > config/brakeman.yml
undefinedbrakeman -C > config/brakeman.yml
undefinedCI/CD Security Gate
CI/CD安全门禁
bash
undefinedbash
undefinedFail build only on high confidence warnings
仅在发现高置信度警告时构建失败
brakeman -w3 --no-exit-on-error
undefinedbrakeman -w3 --no-exit-on-error
undefinedTracking Improvements
跟踪改进情况
bash
undefinedbash
undefinedBaseline scan
基准扫描
brakeman -o baseline.json
brakeman -o baseline.json
After fixes, compare
修复后进行对比
brakeman --compare baseline.json -o improvements.json
undefinedbrakeman --compare baseline.json -o improvements.json
undefinedReducing Noise
减少无效警告
bash
undefinedbash
undefinedFocus on specific vulnerability types
聚焦特定漏洞类型
brakeman -t SQL,CrossSiteScripting,CommandInjection -w2
brakeman -t SQL,CrossSiteScripting,CommandInjection -w2
Or exclude noisy checks
或排除易产生噪音的检查项
brakeman -x DefaultRoutes,Redirect -w2
undefinedbrakeman -x DefaultRoutes,Redirect -w2
undefinedTroubleshooting
故障排除
Problem: Too many weak confidence warnings
Solution: Use or to filter by confidence level
-w2-w3Problem: Scanning is very slow
Solution: Use flag or to exclude large directories
--faster--skip-filesProblem: False positives for custom sanitization
Solution: Use to mark methods as safe
--safe-methodsProblem: Warnings about database values
Solution: Consider if database values truly safe; if yes, adjust with or configuration
--interproceduralProblem: Can't parse certain files
Solution: Use to exclude problematic files
--skip-files问题:低置信度警告过多
解决方案:使用或按置信度等级过滤
-w2-w3问题:扫描速度极慢
解决方案:使用参数或排除大型目录
--faster--skip-files问题:自定义清理方法被误报
解决方案:使用将方法标记为安全
--safe-methods问题:出现关于数据库值的警告
解决方案:确认数据库值是否真的安全;若安全,可使用或配置文件调整
--interprocedural问题:无法解析某些文件
解决方案:使用排除有问题的文件
--skip-filesResources
资源
references/warning_types.md
references/warning_types.md
Comprehensive descriptions of all 30+ vulnerability types Brakeman can detect, including examples and remediation guidance.
包含Brakeman可检测的30多种漏洞类型的详细描述、示例和修复指导。
references/command_options.md
references/command_options.md
Complete command-line reference with detailed explanations of all available options and flags.
完整的命令行参考,包含所有可用参数和详细说明。
references/reducing_false_positives.md
references/reducing_false_positives.md
Strategies and techniques for minimizing false positives while maintaining security coverage.
减少误报的策略和技巧,同时保持安全覆盖范围。