Rack::Attack VS Pundit

Compare Rack::Attack vs Pundit and see what are their differences.

Pundit

Minimal authorization through OO design and pure Ruby classes (by varvet)
Our great sponsors
  • InfluxDB - Power Real-Time Data Analytics at Scale
  • WorkOS - The modern identity platform for B2B SaaS
  • SaaSHub - Software Alternatives and Reviews
Rack::Attack Pundit
13 25
5,480 8,170
0.5% 0.6%
7.1 6.9
about 2 months ago 27 days ago
Ruby Ruby
MIT License MIT License
The number of mentions indicates the total number of mentions that we've tracked plus the number of user suggested alternatives.
Stars - the number of stars that a project has on GitHub. Growth - month over month growth in stars.
Activity is a relative number indicating how actively a project is being developed. Recent commits have higher weight than older ones.
For example, an activity of 9.0 indicates that a project is amongst the top 10% of the most actively developed projects that we are tracking.

Rack::Attack

Posts with mentions or reviews of Rack::Attack. We have used some of these posts to build our list of alternatives and similar projects. The last one was on 2023-10-28.
  • Rails Authentication for Compliance
    5 projects | dev.to | 28 Oct 2023
    The first line of defense should be to put rate-limiting on your login endpoints. rack-attack can help with that. I recommend to limit the login attempts to 5 per minute for a username and block the IP for 30 minutes. You should also limit the number of login attempts from the same IP address, but this needs to be adjusted to the application you are working on, because if it is a tool used in classrooms, it might be legit to have 50 logins within a few minutes from the same IP. (I have a few post written about rack-attack)
  • 4 Essential Security Tools To Level Up Your Rails Security
    10 projects | dev.to | 31 May 2023
    Rack::Attack
  • Huginn’s IP keeps getting blocked by Kickstarter
    2 projects | /r/selfhosted | 17 Dec 2022
  • rack/rack-attack: Rack middleware for blocking & throttling
    1 project | /r/ruby | 17 Dec 2022
  • Rack-attack gem setup to protect Rails and Rack apps from bad clients
    1 project | dev.to | 8 Aug 2022
    Rack middleware for blocking & throttling abusive requests. Protect your Rails and Rack apps from bad clients. Rack::Attack lets you quickly decide when to allow, block, and throttle based on the properties of the request. Using this gem you can save your web application from attacks, we can whitelist IPs, Block requests according to requirements, and many more… Install Rack-attack gem: # In your Gemfile gem 'rack-attack' Enter fullscreen mode Exit fullscreen mode Plugging into the application Then tell your ruby web application to use rack-attack as a middleware. # config/application.rb # rack attack middleware config.middleware.use Rack::Attack Enter fullscreen mode Exit fullscreen mode Once you’ve done that, you’ll need to configure it. You can do this by creating the file, config/initializers/rack-attack.rband adding the rules to fit your needs. You can disable it permanently (like for a specific environment) or temporarily (can be helpful for specific test cases) by writing: Usage Safe listing Safelists have the most precedence, so any request matching a safelist would be allowed despite matching any number of blocklists or throttles. safelist_ip(ip_address_string) Rack::Attack.safelist_ip(“5.6.7.8”) Enter fullscreen mode Exit fullscreen mode safelist_ip(ip_subnet_string) Rack::Attack.safelist_ip(“5.6.7.0/24”) Enter fullscreen mode Exit fullscreen mode safelist(name, &block) Name your custom safelist and make your ruby-block argument return a truthy value if you want the request to be allowed, and false otherwise. Blocking blocklist_ip(ip_address_string) Rack::Attack.blocklist_ip(“1.2.3.4”) Enter fullscreen mode Exit fullscreen mode blocklist_ip(ip_subnet_string) Rack::Attack.blocklist_ip(“1.2.0.0/16”) Enter fullscreen mode Exit fullscreen mode blocklist(name, &block) Name your custom blocklist and make your ruby-block argument return a truthy value if you want the request to be blocked, and false otherwise. Throttling *throttle(name, options, &block) *( provide limit and period as options) Throttle state is stored in a configurable cache (which defaults to Rails.cache if present). Name your custom throttle, provide limit and period as options, and make your ruby-block argument return the discriminator. This discriminator is how you tell rack-attack whether you’re limiting per IP address, per user email, or any other. For example, if we want to restrict requests other than defined routes and display a custom error page. Error page: If we want to restrict requests/IP and if the request limit increases then send a reminder mail. For Example, we want to allow only 300 requests per 30 seconds after that will restrict requests from this IP till the next 30 seconds interval starting. Get error mail if the limit is extended. Performance The overhead of running Rack::Attack is typically negligible (a few milliseconds per request), but it depends on how many checks you’ve configured, and how long they take. Throttles usually require a network roundtrip to your cache server(s), so try to keep the number of throttle checks per request low. If a request is blocklisted or throttled, the response is a very simple Rack response. A single typical ruby web server thread can block several hundred requests per second. Sample rack-attack.rb file For more information: https://github.com/rack/rack-attack If this guide has been helpful to you and your team please share it with others!
  • Limiting the amount of calls user can make to an api
    1 project | /r/rails | 11 Nov 2021
    Second vote for rack-attack!
  • Devise and email spam?
    1 project | /r/rails | 4 Nov 2021
    You could use something like Rack Attack to mitigate this type of behavior if it becomes an issue.
  • 10 things I add to every Rails app
    9 projects | dev.to | 2 Oct 2021
    The final gem I like to include in all projects is rack-attack. This is a rate limiting tool which is great for throttling dangerous actions in your app to prevent bot attacks or other malicious users.
  • Rails application boilerplate for fast MVP development
    63 projects | dev.to | 6 Aug 2021
    rack-attack to prevent bruteforce and DDoS attacks
  • How to prevent scraping/copying data?
    1 project | /r/ruby | 23 Jun 2021
    Check out Rack Attack. It lets you block bots that make requests too fast to be real users, or that request obviously-suspect URLs (/phpmyadmin for example). There are lots of other options, but those are the quick wins IMO.

Pundit

Posts with mentions or reviews of Pundit. We have used some of these posts to build our list of alternatives and similar projects. The last one was on 2023-11-07.
  • A guide to Auth & Access Control in web apps 🔐
    8 projects | dev.to | 7 Nov 2023
    https://github.com/varvet/pundit Popular open-source Ruby library focused around the notion of policies, giving you the freedom to implement your own approach based on that.
  • Pundit VS Action Policy - a user suggested alternative
    2 projects | 2 Jul 2023
  • Launch HN: Infield (YC W20) – Safer, faster dependency upgrades
    4 projects | news.ycombinator.com | 8 Jun 2023
    Can you expand a little? Here's some technical background on what we're doing:

    We have our own database of every version of every rubygems package alongside its runtime dependencies (like you see at https://rubygems.org/gems/pundit).

    Then we parse your Gemfile and Gemfile.lock. We use the Gemfile to figure out gem group and pinned requirements (we run turn your Gemfile into a ruby AST since Gemfiles can be arbitrary ruby code; we use bundler's APIs to parse your Gemfile.lock). This gives us all of the dependencies your rely on.

    Then we let you choose one or more package that you want to upgrade and the version you want to target (let's say Rails 7.0.4.3).

    Now we have [your dependencies and their current versions], [target rails version], [all of the runtime dependency constraints of these gems]. We run this through a dependency resolution algorithm (pubgrub). If it resolves then you're good to upgrade to that version of Rails without changing anything.

    If this fails to resolve, it's because one or more of your current dependencies has a runtime restriction on rails (or another indirect gem being pulled in by the new rails version). This is where the optimization part comes in. The problem becomes "what is the optimal set of versions of all your dependencies that would resolve with the next version of Rails". Currently we solve for this set trying to optimize for the fewest upgrades. As our dataset of breaking changes gets better we'll change that to optimizing for the "lowest effort".

    Happy to elaborate.

  • Authentication, Roles, and Authorization... oh my.
    6 projects | /r/rails | 26 Apr 2023
    For authorization, I'm going back and forth with Pundit and CanCanCan
  • Protect your GraphQL data with resource_policy
    3 projects | dev.to | 20 Feb 2023
    Expressing authorization rules can be a bit challenging with the use of other authorization gems, such as pundit or cancancan. The resource_policy gem provides a more concise and expressive policy definition that uses a simple block-based syntax that makes it easy to understand and write authorization rules for each attribute.
  • Default to Deny for More Secure Apps
    1 project | dev.to | 18 Jan 2023
    As an example of how to default to deny, consider a Ruby on Rails app (as we tend to do). The primary way a user interacts with the app is through API endpoints powered by controllers. We use Pundit, a popular authorization library for Rails, to manage user permissions.
  • Permissions (access control) in web apps
    7 projects | dev.to | 30 Nov 2022
    https://github.com/varvet/pundit Popular open-source Ruby library focused around the notion of policies, giving you the freedom to implement your own approach based on that.
  • YAGNI exceptions
    3 projects | /r/programming | 17 Oct 2022
    PS If you do mobile / web work (or something else with "detached" UI), I find that declarative access control rules are far superior to imperative ones, because they can be serialized and shipped over the wire. For example, backend running cancancan can be easily send the same rules to casl on the frontend, while if you used something like pundit to secure your backend, you either end up re-implementing it in the frontend, or sending ton of "canEdit" flags with every record.
  • Best practice for displaying info to different user roles?
    3 projects | /r/rails | 4 Oct 2022
    You can use a combination of an authorization gem (https://github.com/varvet/pundit) and decorators (https://www.rubyguides.com/2018/04/decorator-pattern-in-ruby/) if you want to extend functionality based on their roles.
  • Concerns about authorization when going in production
    2 projects | /r/rails | 16 Aug 2022
    Use Action Policy or Pundit, and write tests for your policies. Authz is worth testing with near complete coverage.

What are some alternatives?

When comparing Rack::Attack and Pundit you can also consider the following projects:

Metasploit - Metasploit Framework

CanCanCan - The authorization Gem for Ruby on Rails.

Rack::Protection - NOTE: This project has been merged upstream to sinatra/sinatra

rolify - Role management library with resource scoping

rspec-rails - RSpec for Rails 6+

Action Policy - Authorization framework for Ruby/Rails applications

Rack::UTF8Sanitizer - Rack::UTF8Sanitizer is a Rack middleware which cleans up invalid UTF8 characters in request URI and headers.

Devise - Flexible authentication solution for Rails with Warden.

BeEF - The Browser Exploitation Framework Project

Authority

Gitrob - Reconnaissance tool for GitHub organizations

Declarative Authorization - An unmaintained authorization plugin for Rails. Please fork to support current versions of Rails