
Security News
Follow-up and Clarification on Recent Malicious Ruby Gems Campaign
A clarification on our recent research investigating 60 malicious Ruby gems.
A Ruby gem for integrating Friendly Captcha v2 into your Ruby and Rails applications. Friendly Captcha is a privacy-first, GDPR-compliant captcha service that protects your websites from spam and abuse without tracking users or requiring them to solve puzzles.
Add this line to your application's Gemfile:
gem 'friendly_captcha'
And then execute:
$ bundle install
Or install it yourself as:
$ gem install friendly_captcha
Create an initializer file config/initializers/friendly_captcha.rb
:
FriendlyCaptcha.configure do |config|
config.api_key = ENV['FRIENDLY_CAPTCHA_API_KEY'] # Your API key
config.site_key = ENV['FRIENDLY_CAPTCHA_SITE_KEY'] # Your site key
# Optional: Use EU endpoint for GDPR compliance
# config.verification_endpoint = FriendlyCaptcha.config.eu_endpoint
# Optional: Enable strict mode (reject when verification fails)
# config.strict_mode = true
end
Add the captcha widget to your forms:
<%= form_with url: "/submit" do |form| %>
<%= form.text_field :email, placeholder: "Email" %>
<!-- Add the Friendly Captcha widget -->
<%= friendly_captcha %>
<%= form.submit "Submit" %>
<% end %>
<!-- Basic usage -->
<%= friendly_captcha %>
<!-- With custom options -->
<%= friendly_captcha(
sitekey: "your-custom-site-key", # Override default site key
start: "focus", # auto, focus, or none
lang: "de", # Language code
form_field_name: "custom-field" # Custom form field name
) %>
Verify the captcha response in your controller:
class ContactController < ApplicationController
def create
result = verify_friendly_captcha
if result[:success]
# Captcha verification successful
# Process the form...
redirect_to success_path, notice: "Thank you for your submission!"
else
# Captcha verification failed
flash.now[:error] = "Please complete the captcha verification."
render :new
end
end
end
# With custom options
result = verify_friendly_captcha(
api_key: "custom-api-key",
sitekey: "custom-site-key",
field_name: "custom-field-name",
endpoint: FriendlyCaptcha.config.eu_endpoint
)
# Check the result
if result[:success]
puts "Verification successful!"
puts "Challenge timestamp: #{result[:challenge_timestamp]}" if result[:challenge_timestamp]
else
puts "Verification failed: #{result[:error]}"
puts "Error code: #{result[:error_code]}" if result[:error_code]
puts "Fallback mode: #{result[:fallback]}" if result[:fallback]
end
For non-Rails Ruby applications:
require 'friendly_captcha'
# Configure
FriendlyCaptcha.configure do |config|
config.api_key = "your-api-key"
config.site_key = "your-site-key"
end
# Generate widget HTML
include FriendlyCaptcha::ViewHelpers
widget_html = friendly_captcha
# Verify response (in your request handler)
include FriendlyCaptcha::ControllerHelpers
# Mock params for non-Rails usage
def params
{ 'frc-captcha-response' => 'user-response-token' }
end
result = verify_friendly_captcha
Option | Description | Default |
---|---|---|
api_key | Your Friendly Captcha API key | nil |
site_key | Your Friendly Captcha site key | nil |
verification_endpoint | API endpoint for verification | https://global.frcapi.com/api/v2/captcha/siteverify |
eu_endpoint | EU-only API endpoint | https://eu.frcapi.com/api/v2/captcha/siteverify |
strict_mode | Reject when verification fails | false |
source | Modern widget script URL | Latest v2 SDK |
source_compat | Legacy browser script URL | Latest v2 SDK |
Attribute | Description | Default |
---|---|---|
sitekey | Your site key | From config |
start | When to start solving (auto , focus , none ) | auto |
lang | Language code (e.g., en , de , fr ) | Auto-detected |
form_field_name | Name of the hidden form field | frc-captcha-response |
The gem includes intelligent error handling:
# Enable strict mode
FriendlyCaptcha.configure do |config|
config.strict_mode = true
end
In your test environment, you might want to bypass captcha verification:
# In test environment
if Rails.env.test?
# Mock successful verification
allow_any_instance_of(FriendlyCaptcha::ControllerHelpers)
.to receive(:verify_friendly_captcha)
.and_return({ success: true })
end
After checking out the repo, run bin/setup
to install dependencies. Then, run rake spec
to run the tests. You can also run bin/console
for an interactive prompt.
To install this gem onto your local machine, run bundle exec rake install
.
If you're upgrading from Friendly Captcha v1:
frc-captcha-solution
to frc-captcha-response
api_key
instead of secret
Bug reports and pull requests are welcome on GitHub at https://github.com/hendrixfan/friendly_captcha. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the code of conduct.
The gem is available as open source under the terms of the MIT License.
Everyone interacting in the FriendlyCaptcha project's codebases, issue trackers, chat rooms and mailing lists is expected to follow the code of conduct.
FAQs
Unknown package
We found that friendly_captcha demonstrated a healthy version release cadence and project activity because the last version was released less than 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.