Cancancan Security issue
Steps to reproduce:
- Clone the repo
git clone https://github.com/barttenbrinke/cancancan_issue.git
- Run
bundle install
- Run
rails db:migrate
- Open
http://localhost:3000/working_documents_controller/new
- You should get a
CanCan::AccessDenied
exception, as cancancan checkscan?(:new, Document)
and you are not allowed in. - Open
http://localhost:3000/broken_documents_controller/new
- You should get a
CanCan::AccessDenied
exception, however cancancan just checkscan?(:read, Document)
and you are allowed to continue.
The Working Documents controller has:
class WorkingDocumentsController < ApplicationController
authorize_resource class: Document
The Broken Documents controller has:
class BrokenDocumentsController < ApplicationController
authorize_resource :document
Ability has:
class Ability
include CanCan::Ability
def initialize(session)
can :read, Document
end
end
I believe this is a bug and a security issue.