Ruby
Completed
-
Section 1: Getting Started
-
Section 2: Core Syntax
-
Section 3: Methods and Blocks
-
Section 4: Object-Oriented Ruby
-
Section 5: Metaprogramming
-
Section 6: Working with Data and Files
-
Section 7: Ruby Frameworks Overview
-
Section 8: Ecosystem and Testing
-
Section 9: Practical Projects
-
Section 10: Interview Practice
-
Section 11: Data Structures and Algorithms in Ruby
-
Section 12: More Practice Exercises
-
Section 13: Enumerable and Functional Style
-
Section 14: More OOP Practice
-
Section 15: More Testing
-
Section 16: Enumerable and Comparable Modules In Depth
-
Section 17: Ruby Standard Library: Core Utilities
-
Section 18: Ruby Standard Library: Data and Security
-
Section 19: Ruby Standard Library: CLI and Text
-
Section 20: Ruby Networking
-
Section 21: Ruby on Rails Deep Dive
-
Section 22: Ruby Metaprogramming Deep Dive
-
Section 23: Ruby Design Patterns
-
Section 24: Ruby Concurrency
-
Section 25: Ruby Testing Deep Dive
-
Section 26: Ruby Gems and Packaging
-
Section 27: Ruby Performance
-
Section 28: More Practice Exercises
-
Section 29: More Interview Practice
-
Section 30: Rails API Development
-
Section 31: Rails Authentication and Authorization
-
Section 32: Rails Testing Deep Dive
-
Section 33: Rails Performance
-
Section 34: Rails Deployment
-
Section 35: Sinatra and Lightweight Ruby Web Apps
-
Section 36: More Ruby Language Deep Dive
-
Section 37: Ruby 3.x Modern Features
-
Section 38: More Data Structures in Ruby
-
Section 39: More Practical Projects
-
Section 40: Ruby Ecosystem Tools
-
Section 41: More Practice and Review
-
Section 42: Final Practice and Mastery
-
Section 43: Ruby Interview Deep Dive
-
Section 44: Ruby Background Processing Deep Dive
-
Section 45: Ruby GraphQL
-
Section 46: Ruby Object Model Deep Dive
-
Section 47: Ruby Hanami Framework Overview
-
Section 48: Ruby gRPC and Protocol Buffers
-
Section 49: Ruby Data Processing
-
Section 50: Ruby Search Integration
-
Section 51: Ruby File Upload and Media
-
Section 52: Ruby Email and Notifications
-
Section 53: Ruby Admin Panels
-
Section 54: Ruby Feature Flags and Experimentation
-
Section 55: Ruby Monitoring and Observability
-
Section 56: Ruby Docker and Deployment Deep Dive
-
Section 57: Ruby Security Deep Dive
-
Section 58: More Advanced Metaprogramming
-
Section 59: More Final Projects
235: Brakeman for Static Security Analysis
A few years ago, I was reviewing a PR for a teammate who had implemented a "dynamic filter" for a reporting dashboard. To keep the code dry, they used a pattern that looked like this: @records.send(params[:sort_method]). It was elegant, it was concise, and it worked perfectly in development. It also happened to be a catastrophic security hole. By passing a different method name in the URL, an attacker could have called internal Ruby methods to leak environment variables or even trigger unintended state changes in the database. We didn't catch it in code review because we were focused on the logic, not the attack surface. We only found it when I ran Brakeman on the branch before merging. That's the power of static analysis—it sees the patterns you're too close to the code to notice.
Scanning Your Rails Application
Brakeman is a static analysis security tool specifically designed for Ruby on Rails. Unlike a vulnerability scanner that attacks your running application from the outside, Brakeman looks at the source code itself. It parses your files into an Abstract Syntax Tree (AST) and traces the flow of data from "sources" (like params, cookies, or headers) to "sinks" (like SQL queries, HTML rendering, or system calls).
Getting started is straightforward. You add it to your Gemfile in the :development and :test groups, then run it from your terminal. You don't even need to have your database migrated or your server running to get a full report.
gem 'brakeman', require: false
bundle exec brakeman
When you run this, Brakeman will output a table of warnings categorized by confidence levels: High, Medium, and Weak. A "High" confidence warning usually means Brakeman is almost certain there's a vulnerability, like a raw string interpolation inside a where clause. A "Weak" warning might be a general suggestion, like an insecure cookie configuration that might not actually be a problem given your specific infrastructure.
Managing the Noise with Ignore Files
If you run Brakeman on a legacy project for the first time, you're probably going to be greeted by a wall of red text. It can be overwhelming. The first instinct for some developers is to ignore the tool entirely because "it's just giving me false positives," but that's a dangerous road. The reality is that static analysis isn't perfect; it can't always know that you've sanitized a variable in a helper method or that a certain route is protected by a hard-coded admin check.
Instead of ignoring the tool, you use the ignore configuration. Brakeman provides an interactive wizard that lets you go through each warning and decide if it's a real threat or a false positive. If it's a false positive, you can "ignore" it, which adds the specific fingerprint of that warning to a config/brakeman.ignore file.
bundle exec brakeman -I
I always recommend checking this file into version control. This way, your entire team agrees on which risks are acceptable. More importantly, if a developer introduces a new instance of that same vulnerability elsewhere in the code, Brakeman will still flag it because the fingerprint won't match the ignored one. It keeps your CI pipeline clean while ensuring you don't regress into old habits.
📋 Practical Task
Hunting SQL Injection in the Product Search Controller
You have been handed a small Rails project where a developer attempted to implement a flexible product search. However, they used raw string interpolation in the query, creating a classic SQL Injection vulnerability.
Your Task:
- Create a controller action
ProductsController#searchwith the following vulnerable code:def search @products = Product.where("name LIKE '%#{params[:query]}%'") end - Install the
brakemangem and run a scan on your application. - Locate the warning in the Brakeman report that identifies the "SQL Injection" in the
ProductsController. - Fix the vulnerability by using parameterized queries (the "array" or "hash" syntax provided by ActiveRecord).
- Run Brakeman again to verify that the warning has disappeared.
There are no comments for now.