honeypot-captcha 0.0.2 → 1.0.1

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: de70aea71253224308afd97ec53f4b3c5d0f27b4268d072ca5b53ea7eb73a148
4
+ data.tar.gz: b4da23ac08e48707139cb823f0aa64617e72addebb2f965c897d71d444e59e67
5
+ SHA512:
6
+ metadata.gz: 813eae953f01c398c378bf8c3dc7f965fb638c709337bcaff9ebf022c684f8eb956969dd3758c2fe7a731d822dfc3ab2a83868e54129479ece775cd7eb0e4afc
7
+ data.tar.gz: 603bae094ed48572cada9b9a537c2b304459296bdea2942d9b51deaf8b819caaddfe1f44ff6fbae064a18de0faad0a66226acf1c296c2e604a3315d0ad47dbec
data/README.markdown CHANGED
@@ -1,6 +1,6 @@
1
1
  # Honeypot Captcha
2
2
 
3
- A simple way to add honeypot captchas in your Rails forms.
3
+ **The simplest way to add honeypot captchas in your Rails forms.**
4
4
 
5
5
  Honeypot captchas work off the premise that you can present different form
6
6
  fields to a spam bot than you do to a real user. Spam bots will typically try
@@ -12,17 +12,27 @@ 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
+
19
+ ## Installation
20
+
21
+ In your Gemfile, simply add
22
+
23
+ gem 'honeypot-captcha'
15
24
 
16
25
  ## Usage
17
26
 
18
27
  I've tried to make it pretty simple to add a honeypot captcha, but I'm open to
19
- any suggestions you may have.
28
+ any suggestions you may have. By default, `create` and `update` actions are
29
+ protected. For other actions, see [below](#protection-for-actions-other-than-create-and-update).
20
30
 
21
31
  ### form_for
22
32
 
23
33
  Simply specify that the form has a honeypot in the HTML options hash:
24
34
 
25
- <% form_for Comment.new, :html => { :honeypot => true } do |form| -%>
35
+ <%= form_for Comment.new, :html => { :honeypot => true } do |form| -%>
26
36
  ...
27
37
  <% end -%>
28
38
 
@@ -30,7 +40,7 @@ Simply specify that the form has a honeypot in the HTML options hash:
30
40
 
31
41
  Simply specify that the form has a honeypot in the options hash:
32
42
 
33
- <% form_tag comments_path, :honeypot => true do -%>
43
+ <%= form_tag comments_path, :honeypot => true do -%>
34
44
  ...
35
45
  <% end -%>
36
46
 
@@ -42,8 +52,66 @@ Simply specify that the form has a honeypot in the options hash:
42
52
  ...
43
53
  </form>
44
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
+
63
+ ### Protection for actions other than `create` and `update`
64
+
65
+ If you are submitting a form to a non-RESTful action and require
66
+ honeypot protection, simply add the before filter for that action
67
+ in your controller. For example:
68
+
69
+ class NewsletterController < ApplicationController
70
+ prepend_before_action :protect_from_spam, :only => [:subscribe]
71
+ ...
72
+ end
73
+
74
+ ### Customizing the honeypot fields
75
+
76
+ Override the `honeypot_fields` method within `ApplicationController` to
77
+ add your own custom field names and values. For example:
78
+
79
+ def honeypot_fields
80
+ {
81
+ :my_custom_comment_body => 'Do not fill in this field, sucka!',
82
+ :another_thingy => 'Really... do not fill out!'
83
+ }
84
+ end
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
+
45
113
  ## Note on Patches/Pull Requests
46
-
114
+
47
115
  * Fork the project.
48
116
  * Make your feature addition or bug fix.
49
117
  * Add tests for it. This is important so I don't break it in a future version unintentionally.
@@ -51,13 +119,24 @@ Simply specify that the form has a honeypot in the options hash:
51
119
  * Send me a pull request. Bonus points for topic branches.
52
120
 
53
121
  ## Author
122
+ Created by [Curtis Miller](http://millarian.com) of Velocity Labs, a
123
+ [Ruby on Rails development company](http://velocitylabs.io).
124
+
125
+ ### Collaborators
54
126
 
55
- Written by [Curtis Miller](http://millarian.com) of [Flatterline](http://flatterline.com)
127
+ * [Dave Tapley](https://github.com/dukedave)
56
128
 
57
129
  ### Contributors
58
130
 
131
+ Thank you to all contributors!
132
+
59
133
  * [Eric Saxby](http://github.com/sax)
134
+ * [Bernard Grymonpon](https://github.com/wonko)
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)
60
139
 
61
140
  ## Copyright
62
141
 
63
- 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.2
1
+ 1.0.1
@@ -2,36 +2,57 @@
2
2
  module ActionView
3
3
  module Helpers
4
4
  module FormTagHelper
5
- def form_tag_with_honeypot(url_for_options = {}, options = {}, *parameters_for_url, &block)
6
- honeypot = options.delete(:honeypot)
7
- html = form_tag_without_honeypot(url_for_options, options, *parameters_for_url, &block)
5
+ def form_tag_html_with_honeypot(options)
6
+ honeypot = options.delete(:honeypot) || options.delete('honeypot')
7
+ html = form_tag_html_without_honeypot(options)
8
+
8
9
  if honeypot
9
- captcha = "".respond_to?(:html_safe) ? honey_pot_captcha.html_safe : honey_pot_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
- alias_method_chain :form_tag, :honeypot
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
- html_ids = []
24
- honeypot_fields.collect do |f, l|
25
- html_ids << (html_id = "#{f}_hp_#{Time.now.to_i}")
26
- content_tag :div, :id => html_id do
27
- content_tag(:style, :type => 'text/css', :media => 'screen', :scoped => "scoped") do
28
- "#{html_ids.map { |i| "##{i}" }.join(', ')} { display:none; }"
29
- end +
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
- end.join
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 ''.html_safe 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
37
- end
58
+ end
@@ -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? :before_filter
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
metadata CHANGED
@@ -1,71 +1,161 @@
1
- --- !ruby/object:Gem::Specification
1
+ --- !ruby/object:Gem::Specification
2
2
  name: honeypot-captcha
3
- version: !ruby/object:Gem::Version
4
- prerelease: false
5
- segments:
6
- - 0
7
- - 0
8
- - 2
9
- version: 0.0.2
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.1
10
5
  platform: ruby
11
- authors:
6
+ authors:
12
7
  - curtis
13
8
  autorequire:
14
9
  bindir: bin
15
10
  cert_chain: []
16
-
17
- date: 2010-05-23 00:00:00 -07:00
18
- default_executable:
19
- dependencies: []
20
-
11
+ date: 2019-02-27 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: actionview
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: railties
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rspec
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '3.8'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '3.8'
55
+ - !ruby/object:Gem::Dependency
56
+ name: rspec-html-matchers
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: rdoc
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: '6.1'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: '6.1'
83
+ - !ruby/object:Gem::Dependency
84
+ name: bundler
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - "~>"
88
+ - !ruby/object:Gem::Version
89
+ version: '2'
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - "~>"
95
+ - !ruby/object:Gem::Version
96
+ version: '2'
97
+ - !ruby/object:Gem::Dependency
98
+ name: jeweler
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - "~>"
102
+ - !ruby/object:Gem::Version
103
+ version: '2.3'
104
+ type: :development
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - "~>"
109
+ - !ruby/object:Gem::Version
110
+ version: '2.3'
111
+ - !ruby/object:Gem::Dependency
112
+ name: simplecov
113
+ requirement: !ruby/object:Gem::Requirement
114
+ requirements:
115
+ - - ">="
116
+ - !ruby/object:Gem::Version
117
+ version: '0'
118
+ type: :development
119
+ prerelease: false
120
+ version_requirements: !ruby/object:Gem::Requirement
121
+ requirements:
122
+ - - ">="
123
+ - !ruby/object:Gem::Version
124
+ version: '0'
21
125
  description: A simple way to add honeypot captchas to Rails forms
22
- email: curtis@flatterline.com
126
+ email: curtis@velocitylabs.io
23
127
  executables: []
24
-
25
128
  extensions: []
26
-
27
- extra_rdoc_files:
129
+ extra_rdoc_files:
28
130
  - LICENSE
29
131
  - README.markdown
30
- files:
31
- - .document
32
- - .gitignore
132
+ files:
33
133
  - LICENSE
34
134
  - README.markdown
35
- - Rakefile
36
135
  - VERSION
37
- - honeypot-captcha.gemspec
38
136
  - lib/honeypot-captcha.rb
39
137
  - lib/honeypot-captcha/form_tag_helper.rb
40
- has_rdoc: true
41
138
  homepage: http://github.com/curtis/honeypot-captcha
42
139
  licenses: []
43
-
140
+ metadata: {}
44
141
  post_install_message:
45
- rdoc_options:
46
- - --charset=UTF-8
47
- require_paths:
142
+ rdoc_options: []
143
+ require_paths:
48
144
  - lib
49
- required_ruby_version: !ruby/object:Gem::Requirement
50
- requirements:
145
+ required_ruby_version: !ruby/object:Gem::Requirement
146
+ requirements:
51
147
  - - ">="
52
- - !ruby/object:Gem::Version
53
- segments:
54
- - 0
55
- version: "0"
56
- required_rubygems_version: !ruby/object:Gem::Requirement
57
- requirements:
148
+ - !ruby/object:Gem::Version
149
+ version: '0'
150
+ required_rubygems_version: !ruby/object:Gem::Requirement
151
+ requirements:
58
152
  - - ">="
59
- - !ruby/object:Gem::Version
60
- segments:
61
- - 0
62
- version: "0"
153
+ - !ruby/object:Gem::Version
154
+ version: '0'
63
155
  requirements: []
64
-
65
156
  rubyforge_project:
66
- rubygems_version: 1.3.6
157
+ rubygems_version: 2.7.8
67
158
  signing_key:
68
- specification_version: 3
159
+ specification_version: 4
69
160
  summary: A simple way to add honeypot captchas to Rails forms
70
161
  test_files: []
71
-
data/.document DELETED
@@ -1,5 +0,0 @@
1
- README.rdoc
2
- lib/**/*.rb
3
- bin/*
4
- features/**/*.feature
5
- LICENSE
data/.gitignore DELETED
@@ -1,21 +0,0 @@
1
- ## MAC OS
2
- .DS_Store
3
-
4
- ## TEXTMATE
5
- *.tmproj
6
- tmtags
7
-
8
- ## EMACS
9
- *~
10
- \#*
11
- .\#*
12
-
13
- ## VIM
14
- *.swp
15
-
16
- ## PROJECT::GENERAL
17
- coverage
18
- rdoc
19
- pkg
20
-
21
- ## PROJECT::SPECIFIC
data/Rakefile DELETED
@@ -1,45 +0,0 @@
1
- require 'rubygems'
2
- require 'rake'
3
-
4
- begin
5
- require 'jeweler'
6
- Jeweler::Tasks.new do |gem|
7
- gem.name = "honeypot-captcha"
8
- gem.summary = %Q{A simple way to add honeypot captchas to Rails forms}
9
- gem.description = %Q{A simple way to add honeypot captchas to Rails forms}
10
- gem.email = "curtis@flatterline.com"
11
- gem.homepage = "http://github.com/curtis/honeypot-captcha"
12
- gem.authors = ["curtis"]
13
- # gem.add_development_dependency "rspec", ">= 1.2.9"
14
- # gem is a Gem::Specification... see http://www.rubygems.org/read/chapter/20 for additional settings
15
- end
16
- Jeweler::GemcutterTasks.new
17
- rescue LoadError
18
- puts "Jeweler (or a dependency) not available. Install it with: gem install jeweler"
19
- end
20
-
21
- require 'spec/rake/spectask'
22
- Spec::Rake::SpecTask.new(:spec) do |spec|
23
- spec.libs << 'lib' << 'spec'
24
- spec.spec_files = FileList['spec/**/*_spec.rb']
25
- end
26
-
27
- Spec::Rake::SpecTask.new(:rcov) do |spec|
28
- spec.libs << 'lib' << 'spec'
29
- spec.pattern = 'spec/**/*_spec.rb'
30
- spec.rcov = true
31
- end
32
-
33
- task :spec => :check_dependencies
34
-
35
- task :default => :spec
36
-
37
- require 'rake/rdoctask'
38
- Rake::RDocTask.new do |rdoc|
39
- version = File.exist?('VERSION') ? File.read('VERSION') : ""
40
-
41
- rdoc.rdoc_dir = 'rdoc'
42
- rdoc.title = "honeypot-captcha #{version}"
43
- rdoc.rdoc_files.include('README*')
44
- rdoc.rdoc_files.include('lib/**/*.rb')
45
- end
@@ -1,46 +0,0 @@
1
- # Generated by jeweler
2
- # DO NOT EDIT THIS FILE DIRECTLY
3
- # Instead, edit Jeweler::Tasks in Rakefile, and run the gemspec command
4
- # -*- encoding: utf-8 -*-
5
-
6
- Gem::Specification.new do |s|
7
- s.name = %q{honeypot-captcha}
8
- s.version = "0.0.2"
9
-
10
- s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
- s.authors = ["curtis"]
12
- s.date = %q{2010-05-23}
13
- s.description = %q{A simple way to add honeypot captchas to Rails forms}
14
- s.email = %q{curtis@flatterline.com}
15
- s.extra_rdoc_files = [
16
- "LICENSE",
17
- "README.markdown"
18
- ]
19
- s.files = [
20
- ".document",
21
- ".gitignore",
22
- "LICENSE",
23
- "README.markdown",
24
- "Rakefile",
25
- "VERSION",
26
- "honeypot-captcha.gemspec",
27
- "lib/honeypot-captcha.rb",
28
- "lib/honeypot-captcha/form_tag_helper.rb"
29
- ]
30
- s.homepage = %q{http://github.com/curtis/honeypot-captcha}
31
- s.rdoc_options = ["--charset=UTF-8"]
32
- s.require_paths = ["lib"]
33
- s.rubygems_version = %q{1.3.6}
34
- s.summary = %q{A simple way to add honeypot captchas to Rails forms}
35
-
36
- if s.respond_to? :specification_version then
37
- current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
38
- s.specification_version = 3
39
-
40
- if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
41
- else
42
- end
43
- else
44
- end
45
- end
46
-