Skip to content

Commit aa9e194

Browse files
committed
some more specs
1 parent e96915c commit aa9e194

File tree

2 files changed

+46
-2
lines changed

2 files changed

+46
-2
lines changed

spec/usage/base/xss_spec.rb

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,20 +34,42 @@ def response
3434
# but since we accepted an alert to get here this test should be fine
3535
end
3636

37+
# note that `heading do "string" end` doesn't work and you
38+
# should rather use `heading do plain "string" end`
39+
# Why the hell is this tested then?
40+
# Well if that behavior changed I'd like to have a reminder
41+
# here to catch it. Call me overly cautious.
42+
it "escaping won't be broken in block form (if it worked)" do
43+
class ExamplePage < Matestack::Ui::Page
44+
def response
45+
components {
46+
heading do
47+
XSS::EVIL_SCRIPT
48+
end
49+
}
50+
end
51+
end
52+
53+
visit "/example"
54+
55+
static_output = page.html
56+
expect(static_output).not_to include("alert(")
57+
end
58+
3759
it "escapes the evil when injecting into attributes" do
3860
class ExamplePage < Matestack::Ui::Page
3961

4062
def response
4163
components {
42-
heading text: "Be Safe!", id: "something-\"#{XSS::EVIL_SCRIPT}"
64+
heading text: "Be Safe!", id: "something-\">#{XSS::EVIL_SCRIPT}"
4365
}
4466
end
4567

4668
end
4769

4870
visit "/example"
4971

50-
expect(page.html).to include("id=\"something-&quot;<script>alert('hello');</script>")
72+
expect(page.html).to include("id=\"something-&quot;><script>alert('hello');</script>")
5173
end
5274
end
5375
end

spec/usage/components/absolute_spec.rb

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,4 +28,26 @@ def response
2828
expect(stripped(static_output)).to include(stripped(expected_static_output))
2929
end
3030

31+
describe "XSSing" do
32+
it "escaping" do
33+
class ExamplePage < Matestack::Ui::Page
34+
35+
def response
36+
components {
37+
absolute top: 50, left: '50px;">' + XSS::EVIL_SCRIPT, right: 50, bottom: 100, z: 3 do
38+
plain 'I am absolute content'
39+
end
40+
}
41+
end
42+
43+
end
44+
45+
visit '/example'
46+
47+
static_output = page.html
48+
49+
expect(static_output).not_to include("alert")
50+
end
51+
end
52+
3153
end

0 commit comments

Comments
 (0)