rucaptcha 3.2.4-aarch64-linux-musl

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 45ffa827fa5929c94b3632e21d92d9800529de3f7d21d8e467d799740ac12f17
4
+ data.tar.gz: 5b54fffcc01369e6443ad97b2c8bc1d564aac4b23d900d4716053905111c7b12
5
+ SHA512:
6
+ metadata.gz: 877fe4abef3e2a267239f5eb054d107ec2d08e89ff20381f94410576c4e4183c0e117129a82c70d3d63a639886c4aafeac5e600f19246a089238cdc096e0c80a
7
+ data.tar.gz: bc659bcaaecc2a4c6bb6795fe4c728622b750dd037fce2f7c8f93df9d874c9fb6f94955fda1a409f267ebb20e15913a7d04c52e7d17141b3000d229ba6a832c4
data/README.md ADDED
@@ -0,0 +1,191 @@
1
+ # RuCaptcha
2
+
3
+ [![Gem Version](https://badge.fury.io/rb/rucaptcha.svg)](https://badge.fury.io/rb/rucaptcha)
4
+ [![build](https://github.com/huacnlee/rucaptcha/workflows/build/badge.svg)](https://github.com/huacnlee/rucaptcha/actions?query=workflow%3Abuild)
5
+
6
+ Captcha Gem for Rails, which generates captcha image by Rust.
7
+
8
+ > NOTE: According to the use of Ruby China, the verification code looks like has a lower than 5% probability of being parsed by OCR and the verification code is cracked (All Image Captcha libs are has same problem). It is recommended that you use the IP rate limit to enhance the protection.
9
+ > NOTE: 以 Ruby China 的使用来看,验证码似乎有低于 5% 的概率被 OCR 读取解析 (图片验证码都有这个问题) 导致验证码被破解(我们从日志分析绝大多数是成功的,但偶尔一个成功,配合大量机器攻击,导致注册了很多的垃圾账号),建议你额外配合 IP 频率限制的功能来加强保护。
10
+
11
+ > 如果你需要更高强度的验证,建议选择商用服务。
12
+
13
+ [中文介绍和使用说明](https://ruby-china.org/topics/27832)
14
+
15
+ ## Example
16
+
17
+ <img src="https://user-images.githubusercontent.com/5518/196329734-fee49f62-050b-44c8-a5a8-7ffdd3c5a3f6.png" height="50" alt="0"> <img src="https://user-images.githubusercontent.com/5518/196329738-64b264a1-e3fb-4804-ac46-0df18fb31d1e.png" height="50" alt="1"> <img src="https://user-images.githubusercontent.com/5518/196329740-e10ded26-ba46-4e9b-93b8-ce30c198f880.png" height="50" alt="2"> <img src="https://user-images.githubusercontent.com/5518/196329743-c7b055b8-b309-4554-8c95-66c5caf4437d.png" height="50" alt="3"> <img src="https://user-images.githubusercontent.com/5518/196329745-eb68f0c3-ccac-4fa3-aa7a-cc4c2caeb41e.png" height="50" alt="4"> <img src="https://user-images.githubusercontent.com/5518/196329746-b15a9f71-262e-4699-87c7-a5561c6caf2c.png" height="50" alt="5"> <img src="https://user-images.githubusercontent.com/5518/196329747-d111a5d3-89a1-487b-989e-5be8059488c2.png" height="50" alt="6"> <img src="https://user-images.githubusercontent.com/5518/196329749-2cb44aa3-8b59-427c-91f3-59566d6de8a5.png" height="50" alt="7"> <img src="https://user-images.githubusercontent.com/5518/196329754-ae64374b-f2e5-44b8-a7f4-3aee1405c193.png" height="50" alt="8"> <img src="https://user-images.githubusercontent.com/5518/196329755-26b88705-bf34-4d32-a4dc-076530582a90.png" height="50" alt="9">
18
+
19
+ ## Feature
20
+
21
+ - Native Gem base on Rust.
22
+ - For Rails Application;
23
+ - Simple, Easy to use;
24
+ - High performance.
25
+
26
+ ## Usage
27
+
28
+ Put rucaptcha in your `Gemfile`:
29
+
30
+ ```
31
+ gem 'rucaptcha'
32
+ ```
33
+
34
+ Create `config/initializers/rucaptcha.rb`
35
+
36
+ ```rb
37
+ RuCaptcha.configure do
38
+ # Custom captcha code expire time if you need, default: 2 minutes
39
+ # self.expires_in = 120
40
+
41
+  # [Requirement / 重要]
42
+ # Store Captcha code where, this config more like Rails config.cache_store
43
+ # default: Read config info from `Rails.application.config.cache_store`
44
+ # But RuCaptcha requirements cache_store not in [:null_store, :memory_store, :file_store]
45
+  # 默认:会从 Rails 配置的 cache_store 里面读取相同的配置信息,并尝试用可以运行的方式,用于存储验证码字符
46
+  # 但如果是 [:null_store, :memory_store, :file_store] 之类的,你可以通过下面的配置项单独给 RuCaptcha 配置 cache_store
47
+  self.cache_store = :mem_cache_store
48
+
49
+ # If you wants disable `cache_store` check warning, you can do it, default: false
50
+ # 如果想要 disable cache_store 的 warning,就设置为 true,default false
51
+ # self.skip_cache_store_check = true
52
+
53
+ # Chars length, default: 5, allows: [3 - 7]
54
+ # self.length = 5
55
+
56
+ # Enable or disable Strikethrough, default: true
57
+ # self.line = true
58
+
59
+ # Enable or disable noise, default: false
60
+ # self.noise = false
61
+
62
+ # Set the image format, default: png, allows: [jpeg, png, webp]
63
+ # self.format = 'png'
64
+
65
+ # Custom mount path, default: '/rucaptcha'
66
+ # self.mount_path = '/rucaptcha'
67
+ end
68
+ ```
69
+
70
+ RuCaptcha 没有使用 Rails Session 来存储验证码信息,因为 Rails 的默认 Session 是存储在 Cookie 里面,如果验证码存在里面会存在 [Replay attack](https://en.wikipedia.org/wiki/Replay_attack) 漏洞,导致验证码关卡被攻破。
71
+
72
+ 所以我在设计上要求 RuCaptcha 得配置一个可以支持分布式的后端存储方案例如:Memcached 或 Redis 以及其他可以支持分布式的 cache_store 方案。
73
+
74
+ 同时,为了保障易用性,默认会尝试使用 `:file_store` 的方式,将验证码存在应用程序的 `tmp/cache/rucaptcha/session` 目录(但请注意,多机器部署这样是无法正常运作的)。
75
+
76
+ 所以,我建议大家使用的时候,配置上 `cache_store` (详见 [Rails Guides 缓存配置部分](https://ruby-china.github.io/rails-guides/caching_with_rails.html#%E9%85%8D%E7%BD%AE)的文档)到一个 Memcached 或 Redis,这才是最佳实践。
77
+
78
+ #
79
+
80
+ (RuCaptha do not use Rails Session to store captcha information. As the default session is stored in Cookie in Rails, there's a [Replay attack](https://en.wikipedia.org/wiki/Replay_attack) bug which may causes capthcha being destroyed if we store captcha in Rails Session.
81
+
82
+ So in my design I require RuCaptcha to configure a distributed backend storage scheme, such as Memcached, Redis or other cache_store schemes which support distribution.
83
+
84
+ Meanwhile, for the ease of use, RuCapthca would try to use `:file_store` by default and store the capthca in `tmp/cache/rucaptcha/session` directory (kindly note that it's not working if deploy on multiple machine).
85
+
86
+ For recommendation, configure the `cache_store`(more details on [Rails Guides Configuration of Cache Stores](http://guides.rubyonrails.org/caching_with_rails.html#configuration)) to Memcached or Redis, that would be the best practice.)
87
+
88
+ #
89
+
90
+ Controller `app/controller/account_controller.rb`
91
+
92
+ When you called `verify_rucaptcha?`, it uses value from `params[:_rucaptcha]` to validate.
93
+
94
+ ```rb
95
+ class AccountController < ApplicationController
96
+ def create
97
+ @user = User.new(params[:user])
98
+ if verify_rucaptcha?(@user) && @user.save
99
+ redirect_to root_path, notice: 'Sign up successed.'
100
+ else
101
+ render 'account/new'
102
+ end
103
+ end
104
+ end
105
+
106
+ class ForgotPasswordController < ApplicationController
107
+ def create
108
+ # without any args
109
+ if verify_rucaptcha?
110
+ to_send_email
111
+ else
112
+ redirect_to '/forgot-password', alert: 'Invalid captcha code.'
113
+ end
114
+ end
115
+ end
116
+ ```
117
+
118
+ > TIP: Sometimes you may need to keep last verified captcha code in session on `verify_rucaptcha?` method call, you can use `keep_session: true`. For example: `verify_rucaptcha? @user, keep_session: true`.
119
+
120
+ View `app/views/account/new.html.erb`
121
+
122
+ ```erb
123
+ <form method="POST">
124
+ ...
125
+ <div class="form-group">
126
+ <%= rucaptcha_input_tag(class: 'form-control', placeholder: 'Input Captcha') %>
127
+ <%= rucaptcha_image_tag(alt: 'Captcha') %>
128
+ </div>
129
+ ...
130
+
131
+ <div class="form-group">
132
+ <button type="submit" class="btn btn-primary">Submit</button>
133
+ </div>
134
+ </form>
135
+ ```
136
+
137
+ And if you are using [Devise](https://github.com/plataformatec/devise), you can read this reference to add validation: [RuCaptcha with Devise](https://github.com/huacnlee/rucaptcha/wiki/Working-with-Devise).
138
+
139
+ ### Write your test skip captcha validation
140
+
141
+ for RSpec
142
+
143
+ ```rb
144
+ describe 'sign up and login', type: :feature do
145
+ before do
146
+ allow_any_instance_of(ActionController::Base).to receive(:verify_rucaptcha?).and_return(true)
147
+ end
148
+
149
+ it { ... }
150
+ end
151
+ ```
152
+
153
+ for MiniTest
154
+
155
+ ```rb
156
+ class ActionDispatch::IntegrationTest
157
+ def sign_in(user)
158
+ ActionController::Base.any_instance.stubs(:verify_rucaptcha?).returns(true)
159
+ post user_session_path \
160
+ 'user[email]' => user.email,
161
+ 'user[password]' => user.password
162
+ end
163
+ end
164
+ ```
165
+
166
+ ### Invalid message without Devise
167
+
168
+ When you are using this gem without Devise, you may find out that the invalid message is missing.
169
+ For this case, use the trick below to add your i18n invalid message manually.
170
+
171
+ ```rb
172
+ if verify_rucaptcha?(@user) && @user.save
173
+ do_whatever_you_want
174
+ redirect_to someplace_you_want
175
+ else
176
+ # this is the trick
177
+ @user.errors.add(:base, t('rucaptcha.invalid'))
178
+ render :new
179
+ end
180
+ ```
181
+
182
+ ## Performance
183
+
184
+ `rake benchmark` to run benchmark test.
185
+
186
+ ```
187
+ Warming up --------------------------------------
188
+ Generate image 51.000 i/100ms
189
+ Calculating -------------------------------------
190
+ Generate image 526.350 (± 2.5%) i/s - 2.652k in 5.041681s
191
+ ```
data/Rakefile ADDED
@@ -0,0 +1,72 @@
1
+ require "bundler/gem_tasks"
2
+ require "rspec/core/rake_task"
3
+ require "rake/extensiontask"
4
+ require "rubygems/package_task"
5
+ require "bundler"
6
+
7
+ CROSS_PLATFORMS = %w[
8
+ aarch64-linux
9
+ arm64-darwin
10
+ x64-mingw32
11
+ x86_64-darwin
12
+ x86_64-linux
13
+ x86_64-linux-musl
14
+ aarch64-linux-musl
15
+ ]
16
+
17
+ spec = Bundler.load_gemspec("rucaptcha.gemspec")
18
+
19
+ Gem::PackageTask.new(spec).define
20
+
21
+ Rake::ExtensionTask.new("rucaptcha", spec) do |ext|
22
+ ext.lib_dir = "lib/rucaptcha"
23
+ ext.source_pattern = "*.{rs,toml}"
24
+ ext.cross_compile = true
25
+ ext.cross_platform = CROSS_PLATFORMS
26
+ end
27
+
28
+ RSpec::Core::RakeTask.new(:spec)
29
+ task default: :spec
30
+
31
+ def create_captcha(length = 5, difficulty = 5)
32
+ require "rucaptcha"
33
+ RuCaptchaCore.create(length, difficulty, false, false, "png")
34
+ end
35
+
36
+ task :preview do
37
+ require "rucaptcha"
38
+ res = create_captcha()
39
+ warn "-------------------------\n#{res[0]}"
40
+ puts res[1].pack("c*")
41
+ end
42
+
43
+ task :memory do
44
+ require "rucaptcha"
45
+ require "memory_profiler"
46
+
47
+ create_captcha()
48
+
49
+ report = MemoryProfiler.report do
50
+ 1000.times do
51
+ create_captcha()
52
+ end
53
+ end
54
+
55
+ GC.start
56
+ report.pretty_print
57
+
58
+ puts "------------------------- Result Guide -------------------------"
59
+ puts "If [Total retained] have any bytes, there will have memory leak."
60
+ end
61
+
62
+ task :benchmark do
63
+ require "rucaptcha"
64
+ require "benchmark/ips"
65
+
66
+ RuCaptchaCore.create(5, 5, true, true, "png")
67
+
68
+ Benchmark.ips do |x|
69
+ x.report("Generate image") { RuCaptchaCore.create(5, 5, true, true, "png") }
70
+ x.compare!
71
+ end
72
+ end
@@ -0,0 +1,14 @@
1
+ module RuCaptcha
2
+ class CaptchaController < ActionController::Base
3
+ def index
4
+ return head :ok if request.head?
5
+
6
+ headers["Cache-Control"] = "no-cache, no-store, max-age=0, must-revalidate"
7
+ headers["Pragma"] = "no-cache"
8
+ data = generate_rucaptcha
9
+
10
+ opts = { disposition: "inline", type: "image/jpeg" }
11
+ send_data data, opts
12
+ end
13
+ end
14
+ end
@@ -0,0 +1,3 @@
1
+ 'de-DE':
2
+ rucaptcha:
3
+ invalid: "Falsches Captcha (Wenn es nicht erkannt wird, klicken Sie darauf , um das Captcha zu aktualisieren)"
@@ -0,0 +1,3 @@
1
+ en:
2
+ rucaptcha:
3
+ invalid: "The captcha code is incorrect (if you can't read, you can click image to refresh it)"
@@ -0,0 +1,3 @@
1
+ 'pt-BR':
2
+ rucaptcha:
3
+ invalid: "Código inválido!"
@@ -0,0 +1,3 @@
1
+ 'zh-CN':
2
+ rucaptcha:
3
+ invalid: "验证码不正确(如无法识别,可以点击刷新验证码)"
@@ -0,0 +1,3 @@
1
+ 'zh-TW':
2
+ rucaptcha:
3
+ invalid: "驗證碼不正確(如無法識別,可以點擊刷新驗證碼)"
data/config/routes.rb ADDED
@@ -0,0 +1,3 @@
1
+ RuCaptcha::Engine.routes.draw do
2
+ root to: "captcha#index"
3
+ end