invisible_captcha 0.11.0 → 0.12.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +5 -0
- data/README.md +31 -23
- data/lib/invisible_captcha/version.rb +1 -1
- data/lib/invisible_captcha/view_helpers.rb +6 -2
- data/spec/view_helpers_spec.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 69fb2a8c65477376dbea0a7162151d6c100282dc
|
4
|
+
data.tar.gz: b5f5134aff6f55b7d766972151ce85194cadd3e6
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 390075abc680625ac3eee6b237765336554c5e7eec9c06acb368aa1b7f403ef4c1fc8b7ff21170fde71217b7704dc85b4d797e2f4760c9e255a464c7367deda5
|
7
|
+
data.tar.gz: be7d59009de1f3d70485fc19dd6e3bb5b8f0537a5f2e51b879a33ff8a4de9d7832bc81583ca3cf2f5f229ddd1fdde8c54f0e1201127a4e6941974b410f0127b2
|
data/CHANGELOG.md
CHANGED
@@ -2,6 +2,10 @@
|
|
2
2
|
|
3
3
|
All notable changes to this project will be documented in this file.
|
4
4
|
|
5
|
+
## [0.12.0]
|
6
|
+
|
7
|
+
- Honeypot input with autocomplete="off" by default (#42)
|
8
|
+
|
5
9
|
## [0.11.0]
|
6
10
|
|
7
11
|
- Improve logging (#40, #41)
|
@@ -88,6 +92,7 @@ All notable changes to this project will be documented in this file.
|
|
88
92
|
|
89
93
|
- First version of controller filters
|
90
94
|
|
95
|
+
[0.12.0]: https://github.com/markets/invisible_captcha/compare/v0.11.0...v0.12.0
|
91
96
|
[0.11.0]: https://github.com/markets/invisible_captcha/compare/v0.10.0...v0.11.0
|
92
97
|
[0.10.0]: https://github.com/markets/invisible_captcha/compare/v0.9.3...v0.10.0
|
93
98
|
[0.9.3]: https://github.com/markets/invisible_captcha/compare/v0.9.2...v0.9.3
|
data/README.md
CHANGED
@@ -1,6 +1,7 @@
|
|
1
1
|
# Invisible Captcha
|
2
2
|
|
3
|
-
[![Gem
|
3
|
+
[![Gem](https://img.shields.io/gem/v/invisible_captcha.svg?style=flat-square)](https://rubygems.org/gems/invisible_captcha)
|
4
|
+
[![Build Status](https://travis-ci.org/markets/invisible_captcha.svg)](https://travis-ci.org/markets/invisible_captcha)
|
4
5
|
|
5
6
|
> Simple and flexible spam protection solution for Rails applications.
|
6
7
|
|
@@ -10,9 +11,9 @@ The main protection is a solution based on the `honeypot` principle, which provi
|
|
10
11
|
|
11
12
|
Essentially, the strategy consists on adding an input field :honey_pot: into the form that:
|
12
13
|
|
13
|
-
|
14
|
-
|
15
|
-
|
14
|
+
- shouldn't be visible by the real users
|
15
|
+
- should be left empty by the real users
|
16
|
+
- will most be filled by spam bots
|
16
17
|
|
17
18
|
It also comes with a time-sensitive :hourglass: form submission.
|
18
19
|
|
@@ -88,13 +89,13 @@ This section contains a description of all plugin options and customizations.
|
|
88
89
|
|
89
90
|
You can customize:
|
90
91
|
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
92
|
+
- `sentence_for_humans`: text for real users if input field was visible. By default, it uses I18n (see below).
|
93
|
+
- `honeypots`: collection of default honeypots. Used by the view helper, called with no args, to generate a random honeypot field name. By default, a random collection is already generated.
|
94
|
+
- `visual_honeypots`: make honeypots visible, also useful to test/debug your implementation.
|
95
|
+
- `timestamp_threshold`: fastest time (in seconds) to expect a human to submit the form (see [original article by Yoav Aner](https://blog.gingerlime.com/2012/simple-detection-of-comment-spam-in-rails/) outlining the idea). By default, 4 seconds. **NOTE:** It's recommended to deactivate the autocomplete feature to avoid false positives (`autocomplete="off"`).
|
96
|
+
- `timestamp_enabled`: option to disable the time threshold check at application level. Could be useful, for example, on some testing scenarios. By default, true.
|
97
|
+
- `timestamp_error_message`: flash error message thrown when form submitted quicker than the `timestamp_threshold` value. It uses I18n by default.
|
98
|
+
- `injectable_styles`: if enabled, you should call anywhere in your layout the following helper `<%= invisible_captcha_styles %>`. This allows you to inject styles, for example, in `<head>`. False by default, styles are injected inline with the honeypot.
|
98
99
|
|
99
100
|
To change these defaults, add the following to an initializer (recommended `config/initializers/invisible_captcha.rb`):
|
100
101
|
|
@@ -116,24 +117,31 @@ end
|
|
116
117
|
|
117
118
|
The `invisible_captcha` method accepts some options:
|
118
119
|
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
|
126
|
-
|
120
|
+
- `only`: apply to given controller actions.
|
121
|
+
- `except`: exclude to given controller actions.
|
122
|
+
- `honeypot`: name of custom honeypot.
|
123
|
+
- `scope`: name of scope, ie: 'topic[subtitle]' -> 'topic' is the scope.
|
124
|
+
- `on_spam`: custom callback to be called on spam detection.
|
125
|
+
- `timestamp_enabled`: enable/disable this technique at action level.
|
126
|
+
- `on_timestamp_spam`: custom callback to be called when form submitted too quickly. The default action redirects to `:back` printing a warning in `flash[:error]`.
|
127
|
+
- `timestamp_threshold`: custom threshold per controller/action. Overrides the global value for `InvisibleCaptcha.timestamp_threshold`.
|
127
128
|
|
128
129
|
### View helpers options:
|
129
130
|
|
130
|
-
Using the view/form helper you can override some defaults for the given instance. Actually, it allows to change:
|
131
|
+
Using the view/form helper you can override some defaults for the given instance. Actually, it allows to change:
|
132
|
+
|
133
|
+
- `sentence_for_humans`
|
131
134
|
|
132
135
|
```erb
|
133
136
|
<%= form_for(@topic) do |f| %>
|
134
|
-
<%= f.invisible_captcha :subtitle,
|
135
|
-
|
136
|
-
|
137
|
+
<%= f.invisible_captcha :subtitle, sentence_for_humans: "hey! leave this input empty!" %>
|
138
|
+
<% end %>
|
139
|
+
```
|
140
|
+
- `visual_honeypots`
|
141
|
+
|
142
|
+
```erb
|
143
|
+
<%= form_for(@topic) do |f| %>
|
144
|
+
<%= f.invisible_captcha :subtitle, visual_honeypots: true %>
|
137
145
|
<% end %>
|
138
146
|
```
|
139
147
|
|
@@ -41,7 +41,7 @@ module InvisibleCaptcha
|
|
41
41
|
content_tag(:div, class: css_class) do
|
42
42
|
concat styles unless InvisibleCaptcha.injectable_styles
|
43
43
|
concat label_tag(build_label_name(honeypot, scope), label)
|
44
|
-
concat text_field_tag(
|
44
|
+
concat text_field_tag(build_input_name(honeypot, scope), nil, default_honeypot_options.merge(options))
|
45
45
|
end
|
46
46
|
end
|
47
47
|
|
@@ -67,12 +67,16 @@ module InvisibleCaptcha
|
|
67
67
|
end
|
68
68
|
end
|
69
69
|
|
70
|
-
def
|
70
|
+
def build_input_name(honeypot, scope = nil)
|
71
71
|
if scope.present?
|
72
72
|
"#{scope}[#{honeypot}]"
|
73
73
|
else
|
74
74
|
honeypot
|
75
75
|
end
|
76
76
|
end
|
77
|
+
|
78
|
+
def default_honeypot_options
|
79
|
+
{ autocomplete: 'off', tabindex: -1 }
|
80
|
+
end
|
77
81
|
end
|
78
82
|
end
|
data/spec/view_helpers_spec.rb
CHANGED
@@ -31,7 +31,7 @@ describe InvisibleCaptcha::ViewHelpers, type: :helper do
|
|
31
31
|
it 'generated html + styles' do
|
32
32
|
InvisibleCaptcha.honeypots = [:foo_id]
|
33
33
|
output = invisible_captcha.gsub("\"", "'")
|
34
|
-
regexp = %r{<div class='foo_id_\w*'><style.*>.foo_id_\w* {display:none;}</style><label.*>#{InvisibleCaptcha.sentence_for_humans}
|
34
|
+
regexp = %r{<div class='foo_id_\w*'><style.*>.foo_id_\w* {display:none;}</style><label.*>#{InvisibleCaptcha.sentence_for_humans}</label><input (?=.*name='foo_id'.*)(?=.*autocomplete='off'.*)(?=.*tabindex='-1'.*).*/></div>}
|
35
35
|
|
36
36
|
expect(output).to match(regexp)
|
37
37
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: invisible_captcha
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.12.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Marc Anguera Insa
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2018-
|
11
|
+
date: 2018-12-03 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rails
|