Skip to content

ratnikov/strict-forgery-protection

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

28 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

What does this gem do?

This gem tries to help you detect CSRF vulnerabilities by making sure all requests that change the state of the application are verified.

Application state changes currently supported:

  • Database updates (via ActiveRecord).

This addresses to possible CSRF scenarios:

  1. You have a GET method that modifies database. Rails skips verification for GET methods and thus your action is ripe for an CSRF exploit.

  2. You had a POST action that wasn’t modifying the database, so you removed Rails CSRF protection on it. Later on someone added database access, making your action ripe for CSRF exploit.

In both cases this gem checks whether an action request verification occured. If not and database changes occured, it throws an exception.

This gem also modifies Rails verified_request? method to return false for GET requests. However, the behavior of allowing GET requests without verification (assuming they did not induce an application state change) is still permitted.

How does it tell whether a database query is read or write?

Database adapters tend to return a fixnum of rows affected for write queries. If return from the adapter is an enumerable (e.g. an array), it is considered read. Otherwise, it is considered write.

If you find an issue with this approach, please contact me.

License and Copyright

All of the code is copyrighted by Google and is released under MIT license.

About

Provides strict forgery protection for rails

Resources

Stars

Watchers

Forks

Packages

No packages published

Languages