
Security News
Follow-up and Clarification on Recent Malicious Ruby Gems Campaign
A clarification on our recent research investigating 60 malicious Ruby gems.
Add this line to your application's Gemfile:
gem 'jwt-rest'
And then execute:
$ bundle
First you will need to provide a way to find if the ApiKey is valid or not, and a way to retrieve the RSA private key to sign JWT tokens. For this, lets create a initializer config/initializers/jwt_rest.rb
.
require "jwt_rest"
module JwtRest
module Secrets
def self.rsa_private_key
# return he Base64 encoded of your RSA private key
end
def self.valid_api_key?(api_key)
# return true if the api_key is valid
end
end
end
Then in your API's base controller do this
class ApiController < ActionController::API
include JwtRest::Authenticable
before_action :demand_api_key
def handle_user_identity(jwt_payload)
return false unless @current_user = User.find_by(email: jwt_payload.dig("email"))
true
end
end
This will ensure that every call to your API i
s made with a valid api key. You could use the method demand_current_user
for those endpoins where you need to authenticate the user with the JWT token.
class UsersController < ApiController
before_action :demand_current_user, only: [:profile]
def profile
# here we have the @current_user variable
end
end
Contribution directions go here.
The gem is available as open source under the terms of the MIT License.
FAQs
Unknown package
We found that jwt-rest 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.