Skip to content

Add IDOR protection#262

Open
marksmith wants to merge 20 commits intomainfrom
idor-protection
Open

Add IDOR protection#262
marksmith wants to merge 20 commits intomainfrom
idor-protection

Conversation

@marksmith
Copy link
Copy Markdown
Collaborator

@marksmith marksmith commented Mar 31, 2026

This change provides IDOR protection during development, for the supported database drivers (currently mysql2, pg, sqlite3, and trilogy).

Some effort has been spent to add missing sink methods, however, the APIs are large and that effort was not exhaustive.

This change includes several cleanup commits at the start, collected during development, which were considered too small to justify a separate PR.

Summary by Aikido

Security Issues: 0 🔍 Quality Issues: 2 Resolved Issues: 0

🚀 New Features

  • Implemented IDOR protection with analysis, protector, and public API

⚡ Enhancements

  • Added SQL dialects module with placeholder resolvers for queries
  • Extended internals FFI with idor_analyze_sql and safe string handling
  • Added configuration options for IDOR protection and tenant column

🔧 Refactors

  • Updated database sinks to presafe hooks and integrated IDOR calls

More info

@marksmith marksmith requested a review from hansott March 31, 2026 16:01
Comment thread lib/aikido/zen/sql.rb Outdated
Comment thread lib/aikido/zen/sinks/mysql2.rb
Comment thread lib/aikido/zen/idor/protector.rb Outdated
@codecov
Copy link
Copy Markdown

codecov Bot commented Mar 31, 2026

Codecov Report

❌ Patch coverage is 98.92473% with 3 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
lib/aikido/zen/sql.rb 90.62% 1 Missing and 2 partials ⚠️

📢 Thoughts on this report? Let us know!

Comment thread lib/aikido/zen.rb
Comment thread lib/aikido/zen.rb Outdated
Comment thread lib/aikido/zen/idor/protector.rb Outdated
Comment thread test/aikido/zen/sinks/mysql2_test.rb
Comment thread lib/aikido/zen/internals.rb Outdated
The idor_protection_enabled configuration option must still be set.
By a complete example, in database drivers.
Comment thread lib/aikido/zen/sql.rb
In the context, if the idor_protection_enabled configuration option
is set to true.

Aikido::Zen.enable_idor_protection may be called as soon as there is
a context and may safely be called multiple times.
Comment thread lib/aikido/zen/rails_engine.rb
Comment thread lib/aikido/zen/idor/protector.rb Outdated
@marksmith marksmith requested a review from hansott April 3, 2026 08:11
@marksmith marksmith requested a review from timokoessler April 3, 2026 08:11
Comment thread lib/aikido/zen/sql.rb
when /^\?(\d+)$/
match = Regexp.last_match

index = match[1].to_i - 1
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If the query contains ?0, would this throw?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Its shouldn't raise an error but it could return the wrong element.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants