honeypot-captcha 0.0.3 → 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/README.markdown +51 -3
- data/VERSION +1 -1
- data/lib/honeypot-captcha.rb +13 -1
- data/lib/honeypot-captcha/form_tag_helper.rb +34 -13
- metadata +11 -12
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 93a2779cd20a2bce72fbf2fe5b9998c9b0ba425581cd50446b909472963a4610
|
4
|
+
data.tar.gz: 2f49e4c15e9e209bf81f06571ab8b342a7bb91ba4d4a0245b55e7d2bcfa314e4
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 9e541ea8ca330d5ef0eccf0a8db89153fb7c6086829f46523eb11cdbf0b17ff25ea4b33c55adf9d8603507433fd05ee64cdffd7a7ce304d78c7d5cb917eff617
|
7
|
+
data.tar.gz: 6df18e62d6a19d0ac04ec57d2e6ad54166b72b5b863e1bf4f4f6e991d496b9717d97a0bb9f3362f202686980b57b7f528decbf160e7879355bda3640682ee5e7
|
data/README.markdown
CHANGED
@@ -12,6 +12,10 @@ submitted with values. If they are, we assume that we encountered a spam bot.
|
|
12
12
|
* [Honeypot Captcha by Phil Haack](http://haacked.com/archive/2007/09/11/honeypot-captcha.aspx)
|
13
13
|
* [Stopping spambots with hashes and honeypots](http://nedbatchelder.com/text/stopbots.html)
|
14
14
|
|
15
|
+
## Requirements
|
16
|
+
|
17
|
+
* Rails >= 2.3.8
|
18
|
+
|
15
19
|
## Installation
|
16
20
|
|
17
21
|
In your Gemfile, simply add
|
@@ -48,6 +52,14 @@ Simply specify that the form has a honeypot in the options hash:
|
|
48
52
|
...
|
49
53
|
</form>
|
50
54
|
|
55
|
+
### simple_form_for
|
56
|
+
|
57
|
+
Simply specify that the form has a honeypot in the HTML options hash:
|
58
|
+
|
59
|
+
<%= simple_form_for Comment.new, :html => { :honeypot => true } do |form| -%>
|
60
|
+
...
|
61
|
+
<% end -%>
|
62
|
+
|
51
63
|
### Protection for actions other than `create` and `update`
|
52
64
|
|
53
65
|
If you are submitting a form to a non-RESTful action and require
|
@@ -55,7 +67,7 @@ honeypot protection, simply add the before filter for that action
|
|
55
67
|
in your controller. For example:
|
56
68
|
|
57
69
|
class NewsletterController < ApplicationController
|
58
|
-
|
70
|
+
prepend_before_action :protect_from_spam, :only => [:subscribe]
|
59
71
|
...
|
60
72
|
end
|
61
73
|
|
@@ -71,6 +83,33 @@ add your own custom field names and values. For example:
|
|
71
83
|
}
|
72
84
|
end
|
73
85
|
|
86
|
+
NOTE: `honeypot_fields` hash keys are used at the beginning of the generated HTML id attributes. The HTML 4.01 spec states that ids must start with a letter ([A-Za-z]), so be aware of this when creating the hash keys. HTML5 is much less strict.
|
87
|
+
|
88
|
+
Override the `honeypot_string` method within `ApplicationController` to
|
89
|
+
disguise the string that will be included in the honeypot name. For example:
|
90
|
+
|
91
|
+
def honeypot_string
|
92
|
+
'im-not-a-honeypot-at-all'
|
93
|
+
end
|
94
|
+
|
95
|
+
Override the `honeypot_style_class` method within `ApplicationController` to
|
96
|
+
provide a non-inline CSS class that will be applied to hide honeypot fields
|
97
|
+
(if nil, the style will be applied inline). For example:
|
98
|
+
|
99
|
+
def honeypot_style_class
|
100
|
+
'display-none'
|
101
|
+
end
|
102
|
+
|
103
|
+
... assigns an HTML class for styling purposes:
|
104
|
+
|
105
|
+
<div id="login_hp_1464171481" class="display-none">
|
106
|
+
|
107
|
+
... which can be styled by a CSS style within app/assets/stylesheets:
|
108
|
+
|
109
|
+
.display-none {
|
110
|
+
display: none;
|
111
|
+
}
|
112
|
+
|
74
113
|
## Note on Patches/Pull Requests
|
75
114
|
|
76
115
|
* Fork the project.
|
@@ -83,12 +122,21 @@ add your own custom field names and values. For example:
|
|
83
122
|
Created by [Curtis Miller](http://millarian.com) of Velocity Labs, a
|
84
123
|
[Ruby on Rails development company](http://velocitylabs.io).
|
85
124
|
|
125
|
+
### Collaborators
|
126
|
+
|
127
|
+
* [Dave Tapley](https://github.com/dukedave)
|
128
|
+
|
86
129
|
### Contributors
|
87
130
|
|
131
|
+
Thank you to all contributors!
|
132
|
+
|
88
133
|
* [Eric Saxby](http://github.com/sax)
|
89
134
|
* [Bernard Grymonpon](https://github.com/wonko)
|
90
|
-
* [
|
135
|
+
* [rchekaluk](https://github.com/rchekaluk)
|
136
|
+
* [Sunny Ripert](https://github.com/sunny)
|
137
|
+
* [RandieM](https://github.com/RandieM)
|
138
|
+
* [Wayne Steven See](https://github.com/weynsee)
|
91
139
|
|
92
140
|
## Copyright
|
93
141
|
|
94
|
-
Copyright (c) 2010 Curtis Miller. See LICENSE for details.
|
142
|
+
Copyright (c) 2010-2019 Curtis Miller. See LICENSE for details.
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.0
|
1
|
+
1.0.0
|
data/lib/honeypot-captcha.rb
CHANGED
@@ -6,14 +6,26 @@ module HoneypotCaptcha
|
|
6
6
|
{ :a_comment_body => 'Do not fill in this field' }
|
7
7
|
end
|
8
8
|
|
9
|
+
def honeypot_string
|
10
|
+
'hp'
|
11
|
+
end
|
12
|
+
|
13
|
+
def honeypot_style_class
|
14
|
+
nil
|
15
|
+
end
|
16
|
+
|
9
17
|
def protect_from_spam
|
10
18
|
head :ok if honeypot_fields.any? { |f,l| !params[f].blank? }
|
11
19
|
end
|
12
20
|
|
13
21
|
def self.included(base) # :nodoc:
|
14
22
|
base.send :helper_method, :honeypot_fields
|
23
|
+
base.send :helper_method, :honeypot_string
|
24
|
+
base.send :helper_method, :honeypot_style_class
|
15
25
|
|
16
|
-
if base.respond_to? :
|
26
|
+
if base.respond_to? :before_action
|
27
|
+
base.send :prepend_before_action, :protect_from_spam, :only => [:create, :update]
|
28
|
+
elsif base.respond_to? :before_filter
|
17
29
|
base.send :prepend_before_filter, :protect_from_spam, :only => [:create, :update]
|
18
30
|
end
|
19
31
|
end
|
@@ -4,33 +4,54 @@ module ActionView
|
|
4
4
|
module FormTagHelper
|
5
5
|
def form_tag_html_with_honeypot(options)
|
6
6
|
honeypot = options.delete(:honeypot) || options.delete('honeypot')
|
7
|
-
html
|
7
|
+
html = form_tag_html_without_honeypot(options)
|
8
|
+
|
8
9
|
if honeypot
|
9
|
-
captcha =
|
10
|
+
captcha = honey_pot_captcha
|
11
|
+
|
10
12
|
if block_given?
|
11
13
|
html.insert(html.index('</form>'), captcha)
|
12
14
|
else
|
13
15
|
html += captcha
|
14
16
|
end
|
15
17
|
end
|
18
|
+
|
16
19
|
html
|
17
20
|
end
|
18
|
-
|
21
|
+
alias_method :form_tag_html_without_honeypot, :form_tag_html
|
22
|
+
alias_method :form_tag_html, :form_tag_html_with_honeypot
|
19
23
|
|
20
24
|
private
|
21
25
|
|
22
26
|
def honey_pot_captcha
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
content_tag :div, :id => html_id do
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
label_tag(f, l) +
|
31
|
-
send([:text_field_tag, :text_area_tag][rand(2)], f)
|
27
|
+
honeypot_fields.collect do |key, value|
|
28
|
+
html_id = sanitized_html_id(key)
|
29
|
+
|
30
|
+
content_tag :div, { :id => html_id }.merge(style_attributes) do
|
31
|
+
style_tag(html_id) +
|
32
|
+
label_tag(key, value) +
|
33
|
+
send([:text_field_tag, :text_area_tag][rand(2)], key)
|
32
34
|
end
|
33
|
-
|
35
|
+
|
36
|
+
end.join.html_safe
|
37
|
+
end
|
38
|
+
|
39
|
+
def sanitized_html_id(key)
|
40
|
+
"#{key}_#{honeypot_string}_#{Time.current.to_i + rand(999)}".gsub(/\]\[|[^-a-zA-Z0-9:.]/, "_")
|
41
|
+
end
|
42
|
+
|
43
|
+
def style_attributes
|
44
|
+
return {} if honeypot_style_class.blank?
|
45
|
+
|
46
|
+
{ :class => honeypot_style_class }
|
47
|
+
end
|
48
|
+
|
49
|
+
def style_tag(html_id)
|
50
|
+
return '' if honeypot_style_class.present?
|
51
|
+
|
52
|
+
content_tag(:style, :type => 'text/css', :media => 'screen', :scoped => "scoped") do
|
53
|
+
"[id='#{html_id}'] { display:none; }".html_safe
|
54
|
+
end.html_safe
|
34
55
|
end
|
35
56
|
end
|
36
57
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: honeypot-captcha
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0
|
4
|
+
version: 1.0.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- curtis
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2019-01-11 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rspec
|
@@ -16,56 +16,56 @@ dependencies:
|
|
16
16
|
requirements:
|
17
17
|
- - "~>"
|
18
18
|
- !ruby/object:Gem::Version
|
19
|
-
version:
|
19
|
+
version: '3.8'
|
20
20
|
type: :development
|
21
21
|
prerelease: false
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
24
|
- - "~>"
|
25
25
|
- !ruby/object:Gem::Version
|
26
|
-
version:
|
26
|
+
version: '3.8'
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
28
|
name: rdoc
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
30
30
|
requirements:
|
31
31
|
- - "~>"
|
32
32
|
- !ruby/object:Gem::Version
|
33
|
-
version: '
|
33
|
+
version: '6.1'
|
34
34
|
type: :development
|
35
35
|
prerelease: false
|
36
36
|
version_requirements: !ruby/object:Gem::Requirement
|
37
37
|
requirements:
|
38
38
|
- - "~>"
|
39
39
|
- !ruby/object:Gem::Version
|
40
|
-
version: '
|
40
|
+
version: '6.1'
|
41
41
|
- !ruby/object:Gem::Dependency
|
42
42
|
name: bundler
|
43
43
|
requirement: !ruby/object:Gem::Requirement
|
44
44
|
requirements:
|
45
45
|
- - "~>"
|
46
46
|
- !ruby/object:Gem::Version
|
47
|
-
version: '
|
47
|
+
version: '2'
|
48
48
|
type: :development
|
49
49
|
prerelease: false
|
50
50
|
version_requirements: !ruby/object:Gem::Requirement
|
51
51
|
requirements:
|
52
52
|
- - "~>"
|
53
53
|
- !ruby/object:Gem::Version
|
54
|
-
version: '
|
54
|
+
version: '2'
|
55
55
|
- !ruby/object:Gem::Dependency
|
56
56
|
name: jeweler
|
57
57
|
requirement: !ruby/object:Gem::Requirement
|
58
58
|
requirements:
|
59
59
|
- - "~>"
|
60
60
|
- !ruby/object:Gem::Version
|
61
|
-
version: 2.
|
61
|
+
version: '2.3'
|
62
62
|
type: :development
|
63
63
|
prerelease: false
|
64
64
|
version_requirements: !ruby/object:Gem::Requirement
|
65
65
|
requirements:
|
66
66
|
- - "~>"
|
67
67
|
- !ruby/object:Gem::Version
|
68
|
-
version: 2.
|
68
|
+
version: '2.3'
|
69
69
|
- !ruby/object:Gem::Dependency
|
70
70
|
name: simplecov
|
71
71
|
requirement: !ruby/object:Gem::Requirement
|
@@ -111,8 +111,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
111
111
|
- !ruby/object:Gem::Version
|
112
112
|
version: '0'
|
113
113
|
requirements: []
|
114
|
-
|
115
|
-
rubygems_version: 2.4.5
|
114
|
+
rubygems_version: 3.0.2
|
116
115
|
signing_key:
|
117
116
|
specification_version: 4
|
118
117
|
summary: A simple way to add honeypot captchas to Rails forms
|