Security News
pnpm 10.0.0 Blocks Lifecycle Scripts by Default
pnpm 10 blocks lifecycle scripts by default to improve security, addressing supply chain attack risks but sparking debate over compatibility and workflow changes.
Drop this Rack middleware in your web application to enable CAPTCHA verification via Recaptcha API.
First, install the library with: [sudo] gem install rack-recaptcha
You have to require 'rack-recaptcha' in your gemfile.
## Gemfile
gem 'rack-recaptcha', :require => 'rack/recaptcha'
Available options for `Rack::Recaptcha` middleware are:
* :public_key -- your ReCaptcha API public key *(required)*
* :private_key -- your ReCaptcha API private key *(required)*
* :proxy_host -- the HTTP Proxy hostname *(optional)*
* :proxy_port -- the HTTP Proxy port *(optional)*
* :proxy_user -- the HTTP Proxy user *(optional, omit unless the proxy requires it)*
* :proxy_password -- the HTTP Proxy password *(optional, omit unless the proxy requires it)*
Now configure your app to use the middleware. This might be different across each web framework.
## app.rb
use Rack::Recaptcha, :public_key => 'KEY', :private_key => 'SECRET'
helpers Rack::Recaptcha::Helpers
## app/app.rb
use Rack::Recaptcha, :public_key => 'KEY', :private_key => 'SECRET'
helpers Rack::Recaptcha::Helpers
## application.rb:
module YourRailsAppName
class Application < Rails::Application
...
config.gem 'rack-recaptcha', :lib => 'rack/recaptcha'
config.middleware.use Rack::Recaptcha, :public_key => 'KEY', :private_key => 'SECRET'
end
end
## application_helper.rb or whatever helper you want it in.
module ApplicationHelper
include Rack::Recaptcha::Helpers
end
## application_controller.rb or whatever controller you want it in.
class ApplicationController < ActionController::Base
...
include Rack::Recaptcha::Helpers
...
end
The Rack::Recaptcha::Helpers
module (for Sinatra, Rails, Padrino) adds these methods to your app:
Return a javascript recaptcha form
recaptcha_tag :challenge
Return a non-javascript recaptcha form
recaptcha_tag :noscript
Return a ajax recaptcha form
recaptcha_tag :ajax
For ajax recaptcha's, you can pass additional options like:
recaptcha_tag :ajax, :display => { :theme => 'red'}
For non-ajax recaptcha's, you can pass additional options like:
# Overrides the key set in Middleware
recaptcha_tag :challenge, :public_key => KEY
# Adjust Height and/or Width
recaptcha_tag :noscript, :height => 300, :width => 500
# Adjust the rows and/or columns
recaptcha_tag :challenge, :row => 3, :cols => 5
# Set the language
recaptcha_tag :noscript, :language => :en
To test whether or not the verification passed, you can use:
recaptcha_valid?
The recaptcha_valid?
helper can also be overloaded during tests. You
can set its response to either true or false by doing the following:
# Have recaptcha_valid? return true
Rack::Recaptcha.test_mode!
# Or have it return false
Rack::Recaptcha.test_mode! :return => false
For additional options and resources checkout the customization page
In Padrino, here's how you would use the helpers.
## new.haml
- form_tag '/login', :class => 'some_form', :method => 'post' do
= text_field_tag :email
= password_field_tag :password
= recaptcha_tag(:challenge)
= submit_tag "Submit"
## sessions.rb
post :create, :map => '/login' do
if recaptcha_valid?
"passed!"
else
"failed!"
end
end
In rails, you'll need to use also use the raw method:
## new.html.haml
- form_tag '/login' do
= raw recaptcha_tag(:challenge)
= submit_tag "Submit"
Daniel Mendler - minad
Eric Anderson - eric1234
Chad Johnston - iamthechad
Eric Hu - eric-hu
request
is presentTobias Begalke - elcamino
Julik Tarkhanov - julik
Rob Worley - robworley
sam71 - sam71
Copyright (c) 2010, 2011, 2012 Arthur Chiu. See LICENSE for details.
FAQs
Unknown package
We found that rack-recaptcha 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
pnpm 10 blocks lifecycle scripts by default to improve security, addressing supply chain attack risks but sparking debate over compatibility and workflow changes.
Product
Socket now supports uv.lock files to ensure consistent, secure dependency resolution for Python projects and enhance supply chain security.
Research
Security News
Socket researchers have discovered multiple malicious npm packages targeting Solana private keys, abusing Gmail to exfiltrate the data and drain Solana wallets.