tarantula 0.0.5

Sign up to get free protection for your applications and to get access to all the features.
Files changed (118) hide show
  1. data/CHANGELOG +2 -0
  2. data/MIT-LICENSE +20 -0
  3. data/README.rdoc +106 -0
  4. data/Rakefile +80 -0
  5. data/init.rb +1 -0
  6. data/install.rb +1 -0
  7. data/laf/images/background.jpg +0 -0
  8. data/laf/images/relevance-os-logo.gif +0 -0
  9. data/laf/images/tab.png +0 -0
  10. data/laf/images/table-sort.gif +0 -0
  11. data/laf/images/tarantula-sprites.png +0 -0
  12. data/laf/javascripts/jquery-1.2.3.js +3408 -0
  13. data/laf/javascripts/jquery-ui-tabs.js +890 -0
  14. data/laf/javascripts/jquery.tablesorter.js +861 -0
  15. data/laf/javascripts/tarantula.js +10 -0
  16. data/laf/stylesheets/tarantula.css +638 -0
  17. data/laf/stylesheets/ui.tabs.css +113 -0
  18. data/lib/relevance/core_extensions/ellipsize.rb +34 -0
  19. data/lib/relevance/core_extensions/file.rb +9 -0
  20. data/lib/relevance/core_extensions/response.rb +9 -0
  21. data/lib/relevance/core_extensions/test_case.rb +12 -0
  22. data/lib/relevance/tarantula.rb +63 -0
  23. data/lib/relevance/tarantula/attack.rb +15 -0
  24. data/lib/relevance/tarantula/attack_form_submission.rb +75 -0
  25. data/lib/relevance/tarantula/attack_handler.rb +37 -0
  26. data/lib/relevance/tarantula/crawler.rb +240 -0
  27. data/lib/relevance/tarantula/detail.html.erb +77 -0
  28. data/lib/relevance/tarantula/form.rb +21 -0
  29. data/lib/relevance/tarantula/form_submission.rb +70 -0
  30. data/lib/relevance/tarantula/html_document_handler.rb +36 -0
  31. data/lib/relevance/tarantula/html_report_helper.rb +56 -0
  32. data/lib/relevance/tarantula/html_reporter.rb +105 -0
  33. data/lib/relevance/tarantula/index.html.erb +48 -0
  34. data/lib/relevance/tarantula/invalid_html_handler.rb +18 -0
  35. data/lib/relevance/tarantula/io_reporter.rb +34 -0
  36. data/lib/relevance/tarantula/link.rb +56 -0
  37. data/lib/relevance/tarantula/log_grabber.rb +16 -0
  38. data/lib/relevance/tarantula/rails_integration_proxy.rb +70 -0
  39. data/lib/relevance/tarantula/recording.rb +12 -0
  40. data/lib/relevance/tarantula/response.rb +13 -0
  41. data/lib/relevance/tarantula/result.rb +66 -0
  42. data/lib/relevance/tarantula/test_report.html.erb +34 -0
  43. data/lib/relevance/tarantula/tidy_handler.rb +32 -0
  44. data/lib/relevance/tarantula/transform.rb +17 -0
  45. data/manifest.txt +117 -0
  46. data/rails/init.rb +1 -0
  47. data/tarantula.gemspec +48 -0
  48. data/tasks/tarantula_tasks.rake +34 -0
  49. data/template/tarantula_test.rb +12 -0
  50. data/test/relevance/core_extensions/ellipsize_test.rb +19 -0
  51. data/test/relevance/core_extensions/file_test.rb +8 -0
  52. data/test/relevance/core_extensions/response_test.rb +29 -0
  53. data/test/relevance/core_extensions/test_case_test.rb +16 -0
  54. data/test/relevance/tarantula/attack_form_submission_test.rb +79 -0
  55. data/test/relevance/tarantula/attack_handler_test.rb +29 -0
  56. data/test/relevance/tarantula/crawler_test.rb +296 -0
  57. data/test/relevance/tarantula/form_submission_test.rb +71 -0
  58. data/test/relevance/tarantula/form_test.rb +50 -0
  59. data/test/relevance/tarantula/html_document_handler_test.rb +43 -0
  60. data/test/relevance/tarantula/html_report_helper_test.rb +47 -0
  61. data/test/relevance/tarantula/html_reporter_test.rb +82 -0
  62. data/test/relevance/tarantula/invalid_html_handler_test.rb +33 -0
  63. data/test/relevance/tarantula/io_reporter_test.rb +11 -0
  64. data/test/relevance/tarantula/link_test.rb +61 -0
  65. data/test/relevance/tarantula/log_grabber_test.rb +26 -0
  66. data/test/relevance/tarantula/rails_integration_proxy_test.rb +94 -0
  67. data/test/relevance/tarantula/result_test.rb +85 -0
  68. data/test/relevance/tarantula/tidy_handler_test.rb +58 -0
  69. data/test/relevance/tarantula/transform_test.rb +21 -0
  70. data/test/relevance/tarantula_test.rb +23 -0
  71. data/test/test_helper.rb +34 -0
  72. data/tmp/test_output/images/background.jpg +0 -0
  73. data/tmp/test_output/images/relevance-os-logo.gif +0 -0
  74. data/tmp/test_output/images/tab.png +0 -0
  75. data/tmp/test_output/images/table-sort.gif +0 -0
  76. data/tmp/test_output/images/tarantula-sprites.png +0 -0
  77. data/tmp/test_output/index.html +255 -0
  78. data/tmp/test_output/javascripts/jquery-1.2.3.js +3408 -0
  79. data/tmp/test_output/javascripts/jquery-ui-tabs.js +890 -0
  80. data/tmp/test_output/javascripts/jquery.tablesorter.js +861 -0
  81. data/tmp/test_output/javascripts/tarantula.js +10 -0
  82. data/tmp/test_output/stylesheets/tarantula.css +638 -0
  83. data/tmp/test_output/stylesheets/ui.tabs.css +113 -0
  84. data/tmp/test_output/test_user_pages/1.html +71 -0
  85. data/tmp/test_output/test_user_pages/10.html +71 -0
  86. data/tmp/test_output/test_user_pages/11.html +71 -0
  87. data/tmp/test_output/test_user_pages/12.html +71 -0
  88. data/tmp/test_output/test_user_pages/13.html +71 -0
  89. data/tmp/test_output/test_user_pages/14.html +71 -0
  90. data/tmp/test_output/test_user_pages/15.html +71 -0
  91. data/tmp/test_output/test_user_pages/16.html +71 -0
  92. data/tmp/test_output/test_user_pages/17.html +71 -0
  93. data/tmp/test_output/test_user_pages/18.html +71 -0
  94. data/tmp/test_output/test_user_pages/19.html +71 -0
  95. data/tmp/test_output/test_user_pages/2.html +71 -0
  96. data/tmp/test_output/test_user_pages/20.html +71 -0
  97. data/tmp/test_output/test_user_pages/3.html +71 -0
  98. data/tmp/test_output/test_user_pages/4.html +71 -0
  99. data/tmp/test_output/test_user_pages/5.html +71 -0
  100. data/tmp/test_output/test_user_pages/6.html +71 -0
  101. data/tmp/test_output/test_user_pages/7.html +71 -0
  102. data/tmp/test_output/test_user_pages/8.html +71 -0
  103. data/tmp/test_output/test_user_pages/9.html +71 -0
  104. data/uninstall.rb +1 -0
  105. data/vendor/xss-shield/MIT-LICENSE +20 -0
  106. data/vendor/xss-shield/README +76 -0
  107. data/vendor/xss-shield/init.rb +16 -0
  108. data/vendor/xss-shield/lib/xss_shield.rb +6 -0
  109. data/vendor/xss-shield/lib/xss_shield/erb_hacks.rb +111 -0
  110. data/vendor/xss-shield/lib/xss_shield/haml_hacks.rb +42 -0
  111. data/vendor/xss-shield/lib/xss_shield/safe_string.rb +47 -0
  112. data/vendor/xss-shield/lib/xss_shield/secure_helpers.rb +40 -0
  113. data/vendor/xss-shield/test/test_actionview_integration.rb +40 -0
  114. data/vendor/xss-shield/test/test_erb.rb +44 -0
  115. data/vendor/xss-shield/test/test_haml.rb +43 -0
  116. data/vendor/xss-shield/test/test_helpers.rb +25 -0
  117. data/vendor/xss-shield/test/test_safe_string.rb +55 -0
  118. metadata +283 -0
@@ -0,0 +1,71 @@
1
+ <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
2
+ "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
3
+
4
+ <html>
5
+ <head>
6
+ <meta http-equiv="Content-type" content="text/html; charset=utf-8"/>
7
+ <title>Tarantula report detail get /widgets/9</title>
8
+ <script type="text/javascript" src="../javascripts/jquery-1.2.3.js"></script>
9
+ <script type="text/javascript" src="../javascripts/jquery.tablesorter.js"></script>
10
+ <script type="text/javascript" src="../javascripts/jquery-ui-tabs.js"></script>
11
+ <script type="text/javascript" src="../javascripts/tarantula.js"></script>
12
+ <link type="text/css" media="screen" rel="stylesheet" href="../stylesheets/tarantula.css"/>
13
+ <link type="text/css" media="screen" rel="stylesheet" href="../stylesheets/ui.tabs.css"/>
14
+
15
+ <!--[if lte IE 7]>
16
+ <link rel="stylesheet" href="jqeury.tabs-ie.css" type="text/css" media="projection, screen" />
17
+ <![endif]-->
18
+
19
+ </head>
20
+
21
+ <body id="top">
22
+
23
+ <div id="container">
24
+
25
+ <div id="header">
26
+ <hr class="top"/>
27
+ <h1><span>Tarantula : Eight Legs, Two Fangs, and an Attitude</span></h1>
28
+ </div>
29
+
30
+ <div id="page-container">
31
+ <hr class="top"/>
32
+ <div id="page">
33
+ <h1>Tarantula report detail get /widgets/9</h1>
34
+ <p>Generated on Fri Sep 26 11:33:58 -0400 2008 (<a href="../index.html">Back</a>)</p>
35
+ <p>Visit <a href="http://localhost:3000/widgets/9">http://localhost:3000/widgets/9</a></p>
36
+ <p>Response: 200</p>
37
+ <p>Referrer: /random/62</p>
38
+ <div id="tabs-container">
39
+ <ul>
40
+ <li><a href="#fragment-1"><span>Data</span></a></li>
41
+ <li><a href="#fragment-2"><span>Body</span></a></li>
42
+ <li><a href="#fragment-3"><span>Log</span></a></li>
43
+ </ul>
44
+ <div id="fragment-1">
45
+
46
+ <table class="grid tablesorter"><thead><tr><th class="sort asc"><span>Line #</span><span class="sort"><em>&#8613;</em></span></th><th class="sort left"><span>Line</span><span class="sort"><em>&#8613;</em></span></th></tr></thead><tr><td>1</td><td>{:param1 =&gt; :value, :param2 =&gt; :another_value}</td></tr></table>
47
+
48
+ </div>
49
+ <div id="fragment-2">
50
+
51
+ <table class="grid tablesorter"><thead><tr><th class="sort asc"><span>Line #</span><span class="sort"><em>&#8613;</em></span></th><th class="sort left"><span>Line</span><span class="sort"><em>&#8613;</em></span></th></tr></thead><tr><td>1</td><td>&lt;h1&gt;header&lt;/h1&gt;</td></tr><tr><td>2</td><td>&lt;p&gt;text&lt;/p&gt;</td></tr></table>
52
+
53
+ </div>
54
+ <div id="fragment-3">
55
+
56
+ <table class="grid tablesorter"><thead><tr><th class="sort asc"><span>Line #</span><span class="sort"><em>&#8613;</em></span></th><th class="sort left"><span>Line</span><span class="sort"><em>&#8613;</em></span></th></tr></thead><tr><td>1</td><td>Made-up stack trace:</td></tr><tr><td>2</td><td><a href='txmt://open?url=file:///Users/rsanheim/src/relevance/tarantula/STUB_ROOT/some_module/some_class.rb&line_no=697'>/some_module/some_class.rb:697</a>:in `bad_method'</td></tr><tr><td>3</td><td><a href='txmt://open?url=file:///Users/rsanheim/src/relevance/tarantula/STUB_ROOT/some_module/other_class.rb&line_no=12345677'>/some_module/other_class.rb:12345677</a>:in `long_method'</td></tr><tr><td>4</td><td>this link should be &lt;a href=&quot;#&quot;&gt;escaped&lt;/a&gt;</td></tr><tr><td>5</td><td>blah blah blah</td></tr></table>
57
+
58
+ </div>
59
+ </div>
60
+ </div>
61
+ </div>
62
+ <div id="sidebar">
63
+ <h3><span>Tarantula</span></h3>
64
+ <p>Tarantula is an open-source tool for testing Rails web applications. Tarantula is developed by <a href="http://thinkrelevance.com">Relevance, Inc.</a> and lives at <a href="http://opensource.thinkrelevance.com">http://opensource.thinkrelevance.com</a>.</p>
65
+ </div>
66
+ </div>
67
+ </body>
68
+
69
+ </html>
70
+
71
+
data/uninstall.rb ADDED
@@ -0,0 +1 @@
1
+ # Uninstall hook code here
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2007 Trampoline Systems
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.
@@ -0,0 +1,76 @@
1
+ FIXME: THIS README IS NOT UP-TO-DATE.
2
+
3
+ This plugin provides XSS protection for views coded in HAML and RHTML.
4
+
5
+ ERB templates are sometimes used for HTML, and sometimes for
6
+ other kinds of languages (SQL, email templates, YAML etc.).
7
+ XSS Shield protects only those templates with .rhtml extension,
8
+ leaving templates with .erb extension unprotected.
9
+
10
+ === Quick start ===
11
+
12
+ Assuming you're using HAML for all your templates.
13
+
14
+ * Install plugin.
15
+ * Edit all your layout files and change:
16
+ = @content_for_layout
17
+ = yield(:foo) # Foo being usually :js or :css
18
+ to:
19
+ = @content_for_layout.mark_as_xss_protected
20
+ = yield(:foo).mark_as_xss_protected
21
+ * By this point your application should be runnanble,
22
+ but might need some tweaking here and there to avoid potential
23
+ double-escaping.
24
+
25
+ === How it works ===
26
+
27
+ It works by subclassing String into SafeString.
28
+ When HAML engine seems a "= foo" fragment it check if result of executing "foo"
29
+ is a SafeString. If it is - it copies it to the output, if it's anything else
30
+ (String, Integer, nil and so on) it HTML-escapes it first.
31
+
32
+ To avoid double-escaping output of h is a SafeString, as is everything you
33
+ mark as XSS-protected.
34
+ = h(@foo)
35
+ = @foo # fully equivalent to h(@foo)
36
+ = "X <br /> Y".mark_as_xss_protected
37
+
38
+ It would be cumbersome to require mark_as_xss_protected every time you use
39
+ some helper like render :partial or link_to, so some helpers are modified
40
+ to return SafeString.
41
+
42
+ = render :partial => "foo"
43
+ = link_to "Bar", :action => :bar
44
+
45
+ If you trust your helpers, make them as XSS-protected:
46
+
47
+ module Some::Module
48
+ mark_helpers_as_xss_protected :text_field, :check_box
49
+ end
50
+
51
+ Because it is not possible to alter syntactic keywords like yield
52
+ or instance variables like @content_for_layout to mark them automatically
53
+ as secure, layout files need some manual tweaking.
54
+
55
+ === Other template engines ===
56
+
57
+ If a templates uses some templating engine other than HAML or ERB,
58
+ or it uses ERB but has extension .erb not .rhtml, XSS Shield does not protect it.
59
+
60
+ However some helpers like link_to and button_to are patched by XSS Shield to
61
+ make them more secure, and this extra security will be there even when used
62
+ in an otherwise unprotected context.
63
+
64
+ For example with XSS shield
65
+ link_to "A & B", "/foo"
66
+ will return (marked as safe):
67
+ '<a href="/foo">A &amp; B</a>'
68
+ not (plain String):
69
+ '<a href="/foo">A & B</a>'
70
+
71
+ Also - RHTML protection only works with default ERB engine (erb.rb from Ruby base).
72
+ If you use some alternative ERB engine it probably won't work.
73
+
74
+ Adding support for alternative templating engine should be relatively straightforward.
75
+ It's mostly a matter of changing to_s to to_s_xss_protected in a few places
76
+ in their source.
@@ -0,0 +1,16 @@
1
+ unless ENV['DISABLE_XSS_SHIELD']
2
+ puts "Loading XSS Shield"
3
+ require 'xss_shield'
4
+ else
5
+ class ::String
6
+ def mark_as_xss_protected
7
+ self
8
+ end
9
+ end
10
+
11
+ class ::NilClass
12
+ def mark_as_xss_protected
13
+ self
14
+ end
15
+ end
16
+ end
@@ -0,0 +1,6 @@
1
+ require 'xss_shield/safe_string'
2
+ # Tarantula doesn't use haml
3
+ # require 'xss_shield/haml_hacks'
4
+ # ERB hacks blow up Rails
5
+ # require 'xss_shield/erb_hacks'
6
+ require 'xss_shield/secure_helpers'
@@ -0,0 +1,111 @@
1
+ class XSSProtectedERB < ERB
2
+ class Compiler < ::ERB::Compiler
3
+ def compile(s)
4
+ out = Buffer.new(self)
5
+
6
+ content = ''
7
+ scanner = make_scanner(s)
8
+ scanner.scan do |token|
9
+ if scanner.stag.nil?
10
+ case token
11
+ when PercentLine
12
+ out.push("#{@put_cmd} #{content.dump}") if content.size > 0
13
+ content = ''
14
+ out.push(token.to_s)
15
+ out.cr
16
+ when :cr
17
+ out.cr
18
+ when '<%', '<%=', '<%#'
19
+ scanner.stag = token
20
+ out.push("#{@put_cmd} #{content.dump}") if content.size > 0
21
+ content = ''
22
+ when "\n"
23
+ content << "\n"
24
+ out.push("#{@put_cmd} #{content.dump}")
25
+ out.cr
26
+ content = ''
27
+ when '<%%'
28
+ content << '<%'
29
+ else
30
+ content << token
31
+ end
32
+ else
33
+ case token
34
+ when '%>'
35
+ case scanner.stag
36
+ when '<%'
37
+ if content[-1] == ?\n
38
+ content.chop!
39
+ out.push(content)
40
+ out.cr
41
+ else
42
+ out.push(content)
43
+ end
44
+ when '<%='
45
+ # NOTE: Changed lines
46
+ out.push("#{@insert_cmd}((#{content}).to_s_xss_protected)")
47
+ # NOTE: End changed lines
48
+ when '<%#'
49
+ # out.push("# #{content.dump}")
50
+ end
51
+ scanner.stag = nil
52
+ content = ''
53
+ when '%%>'
54
+ content << '%>'
55
+ else
56
+ content << token
57
+ end
58
+ end
59
+ end
60
+ out.push("#{@put_cmd} #{content.dump}") if content.size > 0
61
+ out.close
62
+ out.script
63
+ end
64
+ end
65
+
66
+ def initialize(str, safe_level=nil, trim_mode=nil, eoutvar='_erbout')
67
+ @safe_level = safe_level
68
+ compiler = XSSProtectedERB::Compiler.new(trim_mode)
69
+ set_eoutvar(compiler, eoutvar)
70
+ @src = compiler.compile(str)
71
+ @filename = nil
72
+ end
73
+ end
74
+
75
+ module ActionView
76
+ class Base
77
+ private
78
+ def create_template_source(extension, template, render_symbol, locals)
79
+ if template_requires_setup?(extension)
80
+ body = case extension.to_sym
81
+ when :rxml, :builder
82
+ content_type_handler = (controller.respond_to?(:response) ? "controller.response" : "controller")
83
+ "#{content_type_handler}.content_type ||= Mime::XML\n" +
84
+ "xml = Builder::XmlMarkup.new(:indent => 2)\n" +
85
+ template +
86
+ "\nxml.target!\n"
87
+ when :rjs
88
+ "controller.response.content_type ||= Mime::JS\n" +
89
+ "update_page do |page|\n#{template}\nend"
90
+ end
91
+ # NOTE: Changed lines
92
+ elsif extension.to_sym == :rhtml
93
+ body = XSSProtectedERB.new(template, nil, @@erb_trim_mode).src
94
+ # NOTE: End changed lines
95
+ else
96
+ body = ERB.new(template, nil, @@erb_trim_mode).src
97
+ end
98
+
99
+ @@template_args[render_symbol] ||= {}
100
+ locals_keys = @@template_args[render_symbol].keys | locals
101
+ @@template_args[render_symbol] = locals_keys.inject({}) { |h, k| h[k] = true; h }
102
+
103
+ locals_code = ""
104
+ locals_keys.each do |key|
105
+ locals_code << "#{key} = local_assigns[:#{key}]\n"
106
+ end
107
+
108
+ "def #{render_symbol}(local_assigns)\n#{locals_code}#{body}\nend"
109
+ end
110
+ end
111
+ end
@@ -0,0 +1,42 @@
1
+ raise "Haml not loaded" unless Haml::Engine.instance_method(:push_script)
2
+
3
+ module Haml
4
+ class Engine
5
+ def push_script(text, flattened)
6
+ unless options[:suppress_eval]
7
+ push_silent("haml_temp = #{text}", true)
8
+ push_silent("haml_temp = haml_temp.to_s_xss_protected", true)
9
+ out = "haml_temp = _hamlout.push_script(haml_temp, #{@output_tabs}, #{flattened})\n"
10
+ if @block_opened
11
+ push_and_tabulate([:loud, out])
12
+ else
13
+ @precompiled << out
14
+ end
15
+ end
16
+ end
17
+
18
+ def build_attributes(attributes = {})
19
+ # We ignore @options[:attr_wrapper] because ERB::Util.h does not espace ' to &apos;
20
+ # making ' as attribute quote not workable
21
+ result = attributes.map do |a,v|
22
+ v = v.to_s_xss_protected
23
+ unless v.blank?
24
+ " #{a}=\"#{v}\""
25
+ end
26
+ end
27
+ result.sort.join
28
+ end
29
+ end
30
+
31
+ class Buffer
32
+ def build_attributes(attributes = {})
33
+ result = attributes.map do |a,v|
34
+ v = v.to_s_xss_protected
35
+ unless v.blank?
36
+ " #{a}=\"#{v}\""
37
+ end
38
+ end
39
+ result.sort.join
40
+ end
41
+ end
42
+ end
@@ -0,0 +1,47 @@
1
+ class SafeString < String
2
+ def to_s
3
+ self
4
+ end
5
+ def to_s_xss_protected
6
+ self
7
+ end
8
+ end
9
+
10
+ class String
11
+ def mark_as_xss_protected
12
+ SafeString.new(self)
13
+ end
14
+ end
15
+
16
+ class NilClass
17
+ def mark_as_xss_protected
18
+ self
19
+ end
20
+ end
21
+
22
+ # ERB::Util.h and (include ERB::Util; h) are different methods
23
+ module ERB::Util
24
+ class <<self
25
+ def h_with_xss_protection(*args)
26
+ h_without_xss_protection(*args).mark_as_xss_protected
27
+ end
28
+ alias_method_chain :h, :xss_protection
29
+ end
30
+
31
+ def h_with_xss_protection(*args)
32
+ h_without_xss_protection(*args).mark_as_xss_protected
33
+ end
34
+ alias_method_chain :h, :xss_protection
35
+ end
36
+
37
+ class Object
38
+ def to_s_xss_protected
39
+ ERB::Util.h(to_s).mark_as_xss_protected
40
+ end
41
+ end
42
+
43
+ class Array
44
+ def join_xss_protected(sep="")
45
+ map(&:to_s_xss_protected).join(sep.to_s_xss_protected).mark_as_xss_protected
46
+ end
47
+ end
@@ -0,0 +1,40 @@
1
+ class Module
2
+ def mark_helpers_as_xss_protected(*ms)
3
+ ms.each do |m|
4
+ begin
5
+ instance_method("#{m}_with_xss_protection")
6
+ rescue NameError
7
+ define_method :"#{m}_with_xss_protection" do |*args|
8
+ send(:"#{m}_without_xss_protection", *args).mark_as_xss_protected
9
+ end
10
+ alias_method_chain m, :xss_protection
11
+ end
12
+ end
13
+ end
14
+ end
15
+
16
+ class ActionView::Base
17
+ mark_helpers_as_xss_protected :javascript_include_tag,
18
+ :stylesheet_link_tag,
19
+ :render,
20
+ :text_field_tag,
21
+ :submit_tag,
22
+ :radio_button,
23
+ :text_area,
24
+ :auto_discovery_link_tag,
25
+ :image_tag
26
+
27
+ def link_to_with_xss_protection(text, *args)
28
+ link_to_without_xss_protection(text.to_s_xss_protected, *args).mark_as_xss_protected
29
+ end
30
+ alias_method_chain :link_to, :xss_protection
31
+
32
+ def button_to_with_xss_protection(text, *args)
33
+ button_to_without_xss_protection(text.to_s_xss_protected, *args).mark_as_xss_protected
34
+ end
35
+ alias_method_chain :button_to, :xss_protection
36
+ end
37
+
38
+ module ActionView::Helpers::FormHelper
39
+ mark_helpers_as_xss_protected :text_field, :check_box
40
+ end