
Security News
Follow-up and Clarification on Recent Malicious Ruby Gems Campaign
A clarification on our recent research investigating 60 malicious Ruby gems.
CanCanCan, But Accessible in the Front-End Javascript
This gem requires you to export your CanCanCan Ability rules to the front-end.
Depending on your implementation and rule-setup, you may not want to do this.
If you're using sensitive data as rule-conditions in your Ability#initialize, then you should NOT use this gem!
create init file: config/initializers/cancancan_js.rb
and populate it with the following:
require "cancancan_js"
# default values shown
CanCanCanJs.configure do |config|
# Option to export ALL rules (SQL-backed) to the front-end
# - false by default
config.export_all_back_end_rules = false
end
Add this to your class Ability:
include CanCanCanJs::Export
Add to your javascript application.js file:
//= require cancancan_js
You can either set the CanCanCanJs.configuration.export_all_back_end_rules config to true
Or use the front_end
block we've added to Ability. Both rules are active, but only the :read, Account
is exported to the front-end.
class Ability
include CanCan::Ability
include CanCanCanJs::Export
def initialize(user = nil)
# not front-end visible
can :read, User
# front-end visible
front_end do
can :read, Account
end
end
end
We need to export the Ability rules to your front-end from your back-end. There are several ways to do this.
current_ability.export
or Ability.export(current_user)
class ApplicationController < ActionController::Base
def abilities
render json: Ability.export(current_user).to_json
# or
# render json: current_ability.export.to_json
end
end
After you are able to pull the back-end cancancan export to the front-end via your created route, you then call this javascript method and pass it the cancancan export:
set_abilities(<export_rules>)
$.get("<path_to_your_controller_and_action>", function(data, status){
set_abilities(data)
});
You can now call the JS function can
, and pass it similar CanCanCan values
ex: can('show', 'User')
ex: can('show', 'User', {id: 1, email: "test_email", name: "John Johnson"})
You can also check against allow-listed attribs (that you would have set up in CanCanCan)
ex: can('update', 'User', {id: 1, email: "test_email", name: "John Johnson"}, 'email')
Create a new function in AngularJS, to pass the attributes onto the JS function
$scope.can = function(action, class_name, object, column, options) {
return can(action, class_name, object, column, options)
}
You can now use it in angular HTML with angular objects:
ng-show="can('update', resource_class, resource_instance)"
FAQs
Unknown package
We found that cancancan_js demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
A clarification on our recent research investigating 60 malicious Ruby gems.
Security News
ESLint now supports parallel linting with a new --concurrency flag, delivering major speed gains and closing a 10-year-old feature request.
Research
/Security News
A malicious Go module posing as an SSH brute forcer exfiltrates stolen credentials to a Telegram bot controlled by a Russian-speaking threat actor.