Skip to content

Commit e96915c

Browse files
committed
Fix basic XSS vector, check with more of them
1 parent 8cd6fc1 commit e96915c

File tree

13 files changed

+139
-7
lines changed

13 files changed

+139
-7
lines changed

Gemfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ group :development, :test do
2626
gem 'puma'
2727
gem 'simplecov', require: false, group: :test
2828
gem 'byebug'
29-
# gem 'pry-byebug'
29+
gem 'pry-byebug'
3030
gem 'webmock'
3131
gem 'webdrivers', '~> 4.1'
3232
end

Gemfile.lock

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,7 @@ GEM
8080
cells (>= 4.1.6, < 5.0.0)
8181
childprocess (0.9.0)
8282
ffi (~> 1.0, >= 1.0.11)
83+
coderay (1.1.2)
8384
concurrent-ruby (1.1.5)
8485
crack (0.4.3)
8586
safe_yaml (~> 1.0.0)
@@ -125,6 +126,12 @@ GEM
125126
nokogiri (1.10.5)
126127
mini_portile2 (~> 2.4.0)
127128
pipetree (0.1.1)
129+
pry (0.12.2)
130+
coderay (~> 1.1.0)
131+
method_source (~> 0.9.0)
132+
pry-byebug (3.8.0)
133+
byebug (~> 11.0)
134+
pry (~> 0.10)
128135
public_suffix (3.0.3)
129136
puma (4.3.1)
130137
nio4r (~> 2.0)
@@ -253,6 +260,7 @@ DEPENDENCIES
253260
cells-rails
254261
generator_spec
255262
matestack-ui-core!
263+
pry-byebug
256264
puma
257265
rspec-rails (~> 3.8)
258266
selenium-webdriver

app/concepts/matestack/ui/core/app/app.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
module Matestack::Ui::Core::App
22
class App < Trailblazer::Cell
33

4-
include ::Cell::Haml
4+
include Matestack::Ui::Core::Cell
55
include Matestack::Ui::Core::ApplicationHelper
66
include Matestack::Ui::Core::ToCell
77

app/concepts/matestack/ui/core/component/dynamic.rb

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
module Matestack::Ui::Core::Component
22
class Dynamic < Trailblazer::Cell
3-
4-
include ::Cell::Haml
3+
include Matestack::Ui::Core::Cell
54
include Matestack::Ui::Core::ApplicationHelper
65
include Matestack::Ui::Core::ToCell
76
include Matestack::Ui::Core::HasViewContext

app/concepts/matestack/ui/core/page/page.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ module Matestack::Ui::Core::Page
22
class Page < Trailblazer::Cell
33

44
include ActionView::Helpers::TranslationHelper
5-
include ::Cell::Haml
5+
include Matestack::Ui::Core::Cell
66
include Matestack::Ui::Core::ApplicationHelper
77
include Matestack::Ui::Core::ToCell
88
include Matestack::Ui::Core::HasViewContext

app/concepts/matestack/ui/core/plain/plain.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ module Matestack::Ui::Core::Plain
22
class Plain < Matestack::Ui::Core::Component::Static
33

44
def show
5-
@argument
5+
html_escape @argument
66
end
77

88
end

lib/matestack/ui/core.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
require 'cell/rails'
55
require 'cell/haml'
66

7+
require "matestack/ui/core/cell"
78
require "matestack/ui/core/engine"
89

910
module Matestack

lib/matestack/ui/core/cell.rb

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
module Matestack
2+
module Ui
3+
module Core
4+
# Custom Cell options/handling based on a Cell from the cells gem.
5+
#
6+
# Needed to redefine some options and gives us more control over
7+
# the cells.
8+
module Cell
9+
include ::Cell::Haml
10+
11+
# based on https://github.com/trailblazer/cells-haml/blob/master/lib/cell/haml.rb
12+
# be aware that as of February 2020 this differs from the released version though.
13+
def template_options_for(_options)
14+
# Note, cells uses Hash#delete which mutates the hash,
15+
# hence we can't use a constant here as on the first
16+
# invocation it'd lose it's suffix key
17+
{
18+
template_class: ::Tilt::HamlTemplate,
19+
escape_html: true,
20+
escape_attrs: true,
21+
suffix: "haml"
22+
}
23+
end
24+
25+
# def html_escape(string)
26+
27+
# end
28+
end
29+
end
30+
end
31+
end
32+
33+
# Matestack::Ui::Core::Cell = ::Cell::Haml

spec/spec_helper.rb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,8 @@
3636

3737
Dir[File.join File.dirname(__FILE__), 'support', '**', '*.rb'].each { |f| require f }
3838

39+
require 'pry'
40+
3941
RSpec.configure do |config|
4042
# config.include Capybara::DSL
4143
# rspec-expectations config goes here. You can use an alternate

spec/support/xss.rb

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
module XSS
2+
EVIL_SCRIPT = "<script>alert('hello');</script>"
3+
ESCAPED_EVIL_SCRIPT = "&lt;script&gt;alert('hello');&lt;/script&gt;"
4+
end

0 commit comments

Comments
 (0)