rack-escapee 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
data/.document ADDED
@@ -0,0 +1,4 @@
1
+ lib/**/*.rb
2
+ bin/*
3
+ -
4
+ LICENSE.txt
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --color
2
+ --format progress
data/Gemfile ADDED
@@ -0,0 +1,13 @@
1
+ source "http://rubygems.org"
2
+ # Add dependencies required to use your gem here.
3
+ # Example:
4
+ # gem "activesupport", ">= 2.3.5"
5
+
6
+ # Add dependencies to develop your gem here.
7
+ # Include everything needed to run rake, tests, features, etc.
8
+ group :development do
9
+ gem "bundler", "~> 1.0.0"
10
+ gem "jeweler", "~> 1.5.1"
11
+ gem "rspec", "~> 2.1.0"
12
+ gem "sinatra", "~> 1.0"
13
+ end
data/Gemfile.lock ADDED
@@ -0,0 +1,32 @@
1
+ GEM
2
+ remote: http://rubygems.org/
3
+ specs:
4
+ diff-lcs (1.1.2)
5
+ git (1.2.5)
6
+ jeweler (1.5.1)
7
+ bundler (~> 1.0.0)
8
+ git (>= 1.2.5)
9
+ rake
10
+ rack (1.2.1)
11
+ rake (0.8.7)
12
+ rspec (2.1.0)
13
+ rspec-core (~> 2.1.0)
14
+ rspec-expectations (~> 2.1.0)
15
+ rspec-mocks (~> 2.1.0)
16
+ rspec-core (2.1.0)
17
+ rspec-expectations (2.1.0)
18
+ diff-lcs (~> 1.1.2)
19
+ rspec-mocks (2.1.0)
20
+ sinatra (1.1.0)
21
+ rack (~> 1.1)
22
+ tilt (~> 1.1)
23
+ tilt (1.1)
24
+
25
+ PLATFORMS
26
+ ruby
27
+
28
+ DEPENDENCIES
29
+ bundler (~> 1.0.0)
30
+ jeweler (~> 1.5.1)
31
+ rspec (~> 2.1.0)
32
+ sinatra (~> 1.0)
data/LICENSE.txt ADDED
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2010 Bobby Wilson
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,57 @@
1
+ rack-escapee
2
+ ============
3
+
4
+ rack-escapee is a rack middleware that logs any time you are rendering escaped
5
+ html tags and entities, because this is usually unwanted behavior. This is an
6
+ attempt to make it easier to switch from an unescaped by default view rendering
7
+ to escaped by default view rendering, such as adding the rails_xss plugin to
8
+ Rails 2.x projects or moving from Rails 2 to Rails 3.
9
+
10
+ Uses
11
+ ----
12
+
13
+ The most automated way to take advantage of this tool is with integration
14
+ tests. When your integration test suite runs, rack-escapee will be logging as
15
+ usual. After your tests run, you will have a log full of anything that your
16
+ integration tests touch (hopefully most of your app).
17
+
18
+ Configuration
19
+ -------------
20
+
21
+ Escapee by default outputs to STDOUT but can be optionally configured to use a
22
+ log file. The logfile is my preferred way so that it is all in one place
23
+ especially if you are running your integration suite with escapee.
24
+
25
+ Rails
26
+ -----
27
+
28
+ Rails::Initializer.run do |config|
29
+ config.gem 'rack-escapee', :lib => 'rack/escapee'
30
+
31
+ config.middleware.use "Rack::Escapee", "log/escapee.log"
32
+ end
33
+
34
+ Sinatra
35
+ -------
36
+
37
+ require 'rack/escapee'
38
+
39
+ use Rack::Escapee, "log/stuff_to_fix.log"
40
+
41
+ Contributing to rack-escapee
42
+ ----------------------------
43
+
44
+ * Check out the latest master to make sure the feature hasn't been implemented or the bug hasn't been fixed yet
45
+ * Check out the issue tracker to make sure someone already hasn't requested it and/or contributed it
46
+ * Fork the project
47
+ * Start a feature/bugfix branch
48
+ * Commit and push until you are happy with your contribution
49
+ * Make sure to add tests for it. This is important so I don't break it in a future version unintentionally.
50
+ * Please try not to mess with the Rakefile, version, or history. If you want to have your own version, or is otherwise necessary, that is fine, but please isolate to its own commit so I can cherry-pick around it.
51
+
52
+ Copyright
53
+ ---------
54
+
55
+ Copyright (c) 2010 Bobby Wilson. See LICENSE.txt for
56
+ further details.
57
+
data/Rakefile ADDED
@@ -0,0 +1,52 @@
1
+ require 'rubygems'
2
+ require 'bundler'
3
+ begin
4
+ Bundler.setup(:default, :development)
5
+ rescue Bundler::BundlerError => e
6
+ $stderr.puts e.message
7
+ $stderr.puts "Run `bundle install` to install missing gems"
8
+ exit e.status_code
9
+ end
10
+ require 'rake'
11
+
12
+ require 'jeweler'
13
+ Jeweler::Tasks.new do |gem|
14
+ # gem is a Gem::Specification... see http://docs.rubygems.org/read/chapter/20 for more options
15
+ gem.name = "rack-escapee"
16
+ gem.homepage = "http://github.com/bobbyw/rack-escaped-tags"
17
+ gem.license = "MIT"
18
+ gem.summary = %Q{log when escaped html tags and entities are rendered}
19
+ gem.description = %Q{middleware to let you know when escaped html tags are being rendered, so you can fix them}
20
+ gem.email = "bobbywilson0@gmail.com"
21
+ gem.authors = ["Bobby Wilson"]
22
+ # Include your dependencies below. Runtime dependencies are required when using your gem,
23
+ # and development dependencies are only needed for development (ie running rake tasks, tests, etc)
24
+ gem.development_dependencies << ["rspec", "~> 2.1.0"]
25
+ gem.development_dependencies << ["bundler", "~> 2.1.0"]
26
+ gem.development_dependencies << ["sinatra", "~> 1.0"]
27
+ end
28
+
29
+ Jeweler::RubygemsDotOrgTasks.new
30
+
31
+ require 'rspec/core'
32
+ require 'rspec/core/rake_task'
33
+ RSpec::Core::RakeTask.new(:spec) do |spec|
34
+ spec.pattern = FileList['spec/**/*_spec.rb']
35
+ end
36
+
37
+ RSpec::Core::RakeTask.new(:rcov) do |spec|
38
+ spec.pattern = 'spec/**/*_spec.rb'
39
+ spec.rcov = true
40
+ end
41
+
42
+ task :default => :spec
43
+
44
+ require 'rake/rdoctask'
45
+ Rake::RDocTask.new do |rdoc|
46
+ version = File.exist?('VERSION') ? File.read('VERSION') : ""
47
+
48
+ rdoc.rdoc_dir = 'rdoc'
49
+ rdoc.title = "example #{version}"
50
+ rdoc.rdoc_files.include('README*')
51
+ rdoc.rdoc_files.include('lib/**/*.rb')
52
+ end
data/VERSION ADDED
@@ -0,0 +1 @@
1
+ 0.1.0
@@ -0,0 +1,40 @@
1
+ require 'logger'
2
+
3
+ module Rack
4
+ class Escapee
5
+ ESCAPED_TAG = /(&lt;\w+&gt;)/
6
+ ESCAPED_ENTITY = /(&\w+;)/
7
+
8
+
9
+ def initialize(app, options = {})
10
+ @app = app
11
+ @options = {
12
+ :logfile => false
13
+ }.merge(options)
14
+
15
+ if @options[:logfile]
16
+ @logger = ::Logger.new(@options[:logfile])
17
+ else
18
+ @logger = ::Logger.new(STDOUT)
19
+ end
20
+ @logger.datetime_format = "%Y-%m-%d %H:%M:%S"
21
+ end
22
+
23
+ def call(env)
24
+ req = Request.new(env)
25
+ path = req.path_info
26
+ status, headers, response = @app.call(env)
27
+ response_body = []
28
+ response.each do |part|
29
+ if part =~ ESCAPED_TAG
30
+ @logger.warn("rendering escaped tag: #{$1} - #{path}")
31
+ elsif part =~ ESCAPED_ENTITY
32
+ @logger.warn("rendering escaped entity: #{$1} - #{path}")
33
+ end
34
+ response_body << part
35
+ end
36
+
37
+ [status, headers, response_body]
38
+ end
39
+ end
40
+ end
@@ -0,0 +1,68 @@
1
+ # Generated by jeweler
2
+ # DO NOT EDIT THIS FILE DIRECTLY
3
+ # Instead, edit Jeweler::Tasks in Rakefile, and run 'rake gemspec'
4
+ # -*- encoding: utf-8 -*-
5
+
6
+ Gem::Specification.new do |s|
7
+ s.name = %q{rack-escapee}
8
+ s.version = "0.1.0"
9
+
10
+ s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
+ s.authors = ["Bobby Wilson"]
12
+ s.date = %q{2010-11-19}
13
+ s.description = %q{middleware to let you know when escaped html tags are being rendered, so you can fix them}
14
+ s.email = %q{bobbywilson0@gmail.com}
15
+ s.extra_rdoc_files = [
16
+ "LICENSE.txt",
17
+ "README.md"
18
+ ]
19
+ s.files = [
20
+ ".document",
21
+ ".rspec",
22
+ "Gemfile",
23
+ "Gemfile.lock",
24
+ "LICENSE.txt",
25
+ "README.md",
26
+ "Rakefile",
27
+ "VERSION",
28
+ "lib/rack/escapee.rb",
29
+ "rack-escapee.gemspec",
30
+ "spec/escaped_tags_and_entities_spec.rb",
31
+ "spec/fixtures/test_app.rb",
32
+ "spec/log/.gitignore",
33
+ "spec/spec_helper.rb"
34
+ ]
35
+ s.homepage = %q{http://github.com/bobbyw/rack-escaped-tags}
36
+ s.licenses = ["MIT"]
37
+ s.require_paths = ["lib"]
38
+ s.rubygems_version = %q{1.3.7}
39
+ s.summary = %q{log when escaped html tags and entities are rendered}
40
+ s.test_files = [
41
+ "spec/escaped_tags_and_entities_spec.rb",
42
+ "spec/fixtures/test_app.rb",
43
+ "spec/spec_helper.rb"
44
+ ]
45
+
46
+ if s.respond_to? :specification_version then
47
+ current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
48
+ s.specification_version = 3
49
+
50
+ if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
51
+ s.add_development_dependency(%q<bundler>, ["~> 1.0.0"])
52
+ s.add_development_dependency(%q<jeweler>, ["~> 1.5.1"])
53
+ s.add_development_dependency(%q<rspec>, ["~> 2.1.0"])
54
+ s.add_development_dependency(%q<sinatra>, ["~> 1.0"])
55
+ else
56
+ s.add_dependency(%q<bundler>, ["~> 1.0.0"])
57
+ s.add_dependency(%q<jeweler>, ["~> 1.5.1"])
58
+ s.add_dependency(%q<rspec>, ["~> 2.1.0"])
59
+ s.add_dependency(%q<sinatra>, ["~> 1.0"])
60
+ end
61
+ else
62
+ s.add_dependency(%q<bundler>, ["~> 1.0.0"])
63
+ s.add_dependency(%q<jeweler>, ["~> 1.5.1"])
64
+ s.add_dependency(%q<rspec>, ["~> 2.1.0"])
65
+ s.add_dependency(%q<sinatra>, ["~> 1.0"])
66
+ end
67
+ end
68
+
@@ -0,0 +1,33 @@
1
+ require 'spec_helper'
2
+
3
+ describe 'Find escaped tags and entities' do
4
+
5
+ before :each do
6
+ @escaped_tag_notice = Rack::Escapee.new(TestApp.new, {:logfile => LOG_FILE})
7
+ end
8
+
9
+ it 'finds escaped strong tag' do
10
+ @escaped_tag_notice.call Rack::MockRequest.env_for('/escaped_tag')
11
+ last_line = ''
12
+ File.open(LOG_FILE, 'r') do |f|
13
+ while line = f.gets
14
+ last_line = line
15
+ end
16
+ end
17
+
18
+ last_line[32..-2].should == "WARN -- : rendering escaped tag: &lt;strong&gt; - /escaped_tag"
19
+ end
20
+
21
+ it 'finds escaped ampersand entity' do
22
+ @escaped_tag_notice.call Rack::MockRequest.env_for('/escaped_entity')
23
+ last_line = ''
24
+ File.open(LOG_FILE, 'r') do |f|
25
+ while line = f.gets
26
+ last_line = line
27
+ end
28
+ end
29
+
30
+ last_line[32..-2].should == "WARN -- : rendering escaped entity: &amp; - /escaped_entity"
31
+ end
32
+
33
+ end
@@ -0,0 +1,37 @@
1
+ require 'sinatra/base'
2
+
3
+ class TestApp < Sinatra::Base
4
+
5
+ get '/escaped_tag' do
6
+ <<-HTML
7
+ <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
8
+ "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
9
+ <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
10
+ <head>
11
+ <meta http-equiv="Content-Type" content="text/htmll; charset=utf-8"/>
12
+ <title>sample</title>
13
+ </head>
14
+ <body>
15
+ &lt;strong&gt;just some text inside escaped tags&lt;strong&gt;
16
+ </body>
17
+ </html>
18
+ HTML
19
+ end
20
+
21
+ get '/escaped_entity' do
22
+ <<-HTML
23
+ <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
24
+ "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
25
+ <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
26
+ <head>
27
+ <meta http-equiv="Content-Type" content="text/htmll; charset=utf-8"/>
28
+ <title>sample</title>
29
+ </head>
30
+ <body>
31
+ Tom&amp;Jerry
32
+ </body>
33
+ </html>
34
+ HTML
35
+ end
36
+
37
+ end
@@ -0,0 +1 @@
1
+ *.log
@@ -0,0 +1,16 @@
1
+ $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
2
+ $LOAD_PATH.unshift(File.dirname(__FILE__))
3
+ require 'rspec'
4
+ require 'sinatra'
5
+ require 'rack/escapee'
6
+
7
+ # Requires supporting files with custom matchers and macros, etc,
8
+ # in ./support/ and its subdirectories.
9
+ Dir["#{File.dirname(__FILE__)}/support/**/*.rb"].each {|f| require f}
10
+ Dir["#{File.dirname(__FILE__)}/fixtures/**/*.rb"].each {|f| require f}
11
+
12
+ LOG_FILE = File.dirname(__FILE__) + '/log/example.log'
13
+
14
+ RSpec.configure do |config|
15
+
16
+ end
metadata ADDED
@@ -0,0 +1,139 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: rack-escapee
3
+ version: !ruby/object:Gem::Version
4
+ prerelease: false
5
+ segments:
6
+ - 0
7
+ - 1
8
+ - 0
9
+ version: 0.1.0
10
+ platform: ruby
11
+ authors:
12
+ - Bobby Wilson
13
+ autorequire:
14
+ bindir: bin
15
+ cert_chain: []
16
+
17
+ date: 2010-11-19 00:00:00 -07:00
18
+ default_executable:
19
+ dependencies:
20
+ - !ruby/object:Gem::Dependency
21
+ name: bundler
22
+ requirement: &id001 !ruby/object:Gem::Requirement
23
+ none: false
24
+ requirements:
25
+ - - ~>
26
+ - !ruby/object:Gem::Version
27
+ segments:
28
+ - 1
29
+ - 0
30
+ - 0
31
+ version: 1.0.0
32
+ type: :development
33
+ prerelease: false
34
+ version_requirements: *id001
35
+ - !ruby/object:Gem::Dependency
36
+ name: jeweler
37
+ requirement: &id002 !ruby/object:Gem::Requirement
38
+ none: false
39
+ requirements:
40
+ - - ~>
41
+ - !ruby/object:Gem::Version
42
+ segments:
43
+ - 1
44
+ - 5
45
+ - 1
46
+ version: 1.5.1
47
+ type: :development
48
+ prerelease: false
49
+ version_requirements: *id002
50
+ - !ruby/object:Gem::Dependency
51
+ name: rspec
52
+ requirement: &id003 !ruby/object:Gem::Requirement
53
+ none: false
54
+ requirements:
55
+ - - ~>
56
+ - !ruby/object:Gem::Version
57
+ segments:
58
+ - 2
59
+ - 1
60
+ - 0
61
+ version: 2.1.0
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: *id003
65
+ - !ruby/object:Gem::Dependency
66
+ name: sinatra
67
+ requirement: &id004 !ruby/object:Gem::Requirement
68
+ none: false
69
+ requirements:
70
+ - - ~>
71
+ - !ruby/object:Gem::Version
72
+ segments:
73
+ - 1
74
+ - 0
75
+ version: "1.0"
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: *id004
79
+ description: middleware to let you know when escaped html tags are being rendered, so you can fix them
80
+ email: bobbywilson0@gmail.com
81
+ executables: []
82
+
83
+ extensions: []
84
+
85
+ extra_rdoc_files:
86
+ - LICENSE.txt
87
+ - README.md
88
+ files:
89
+ - .document
90
+ - .rspec
91
+ - Gemfile
92
+ - Gemfile.lock
93
+ - LICENSE.txt
94
+ - README.md
95
+ - Rakefile
96
+ - VERSION
97
+ - lib/rack/escapee.rb
98
+ - rack-escapee.gemspec
99
+ - spec/escaped_tags_and_entities_spec.rb
100
+ - spec/fixtures/test_app.rb
101
+ - spec/log/.gitignore
102
+ - spec/spec_helper.rb
103
+ has_rdoc: true
104
+ homepage: http://github.com/bobbyw/rack-escaped-tags
105
+ licenses:
106
+ - MIT
107
+ post_install_message:
108
+ rdoc_options: []
109
+
110
+ require_paths:
111
+ - lib
112
+ required_ruby_version: !ruby/object:Gem::Requirement
113
+ none: false
114
+ requirements:
115
+ - - ">="
116
+ - !ruby/object:Gem::Version
117
+ hash: -2802512562520839201
118
+ segments:
119
+ - 0
120
+ version: "0"
121
+ required_rubygems_version: !ruby/object:Gem::Requirement
122
+ none: false
123
+ requirements:
124
+ - - ">="
125
+ - !ruby/object:Gem::Version
126
+ segments:
127
+ - 0
128
+ version: "0"
129
+ requirements: []
130
+
131
+ rubyforge_project:
132
+ rubygems_version: 1.3.7
133
+ signing_key:
134
+ specification_version: 3
135
+ summary: log when escaped html tags and entities are rendered
136
+ test_files:
137
+ - spec/escaped_tags_and_entities_spec.rb
138
+ - spec/fixtures/test_app.rb
139
+ - spec/spec_helper.rb