-
-
Notifications
You must be signed in to change notification settings - Fork 47
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix basic XSS vector, check with more of them
- Loading branch information
Showing
13 changed files
with
139 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
module Matestack | ||
module Ui | ||
module Core | ||
# Custom Cell options/handling based on a Cell from the cells gem. | ||
# | ||
# Needed to redefine some options and gives us more control over | ||
# the cells. | ||
module Cell | ||
include ::Cell::Haml | ||
|
||
# based on https://github.com/trailblazer/cells-haml/blob/master/lib/cell/haml.rb | ||
# be aware that as of February 2020 this differs from the released version though. | ||
def template_options_for(_options) | ||
# Note, cells uses Hash#delete which mutates the hash, | ||
# hence we can't use a constant here as on the first | ||
# invocation it'd lose it's suffix key | ||
{ | ||
template_class: ::Tilt::HamlTemplate, | ||
escape_html: true, | ||
escape_attrs: true, | ||
suffix: "haml" | ||
} | ||
end | ||
|
||
# def html_escape(string) | ||
|
||
# end | ||
end | ||
end | ||
end | ||
end | ||
|
||
# Matestack::Ui::Core::Cell = ::Cell::Haml |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
module XSS | ||
EVIL_SCRIPT = "<script>alert('hello');</script>" | ||
ESCAPED_EVIL_SCRIPT = "<script>alert('hello');</script>" | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
describe "XSS behavior", type: :feature, js: true do | ||
|
||
describe "injection in heading as an example" do | ||
it "escapes the evil script" do | ||
class ExamplePage < Matestack::Ui::Page | ||
def response | ||
components { | ||
heading text: XSS::EVIL_SCRIPT | ||
} | ||
end | ||
end | ||
|
||
visit "/example" | ||
|
||
static_output = page.html | ||
expect(static_output).to include("<h1>\n#{XSS::ESCAPED_EVIL_SCRIPT}\n</h1>") | ||
end | ||
|
||
it "does not escape when we specifically say #html_safe" do | ||
class ExamplePage < Matestack::Ui::Page | ||
def response | ||
components { | ||
heading text: XSS::EVIL_SCRIPT.html_safe | ||
} | ||
end | ||
end | ||
|
||
# gotta accept our injected alert | ||
accept_alert do | ||
visit "/example" | ||
end | ||
|
||
# for reasons beyond me Chrome seems to remove our injected script tag, | ||
# but since we accepted an alert to get here this test should be fine | ||
end | ||
|
||
it "escapes the evil when injecting into attributes" do | ||
class ExamplePage < Matestack::Ui::Page | ||
|
||
def response | ||
components { | ||
heading text: "Be Safe!", id: "something-\"#{XSS::EVIL_SCRIPT}" | ||
} | ||
end | ||
|
||
end | ||
|
||
visit "/example" | ||
|
||
expect(page.html).to include("id=\"something-"<script>alert('hello');</script>") | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters