Skip to content

Commit fae7e25

Browse files
committed
Bump to 1.2.2
See GHSA-242p-4v39-2v8g
1 parent 663130d commit fae7e25

File tree

4 files changed

+36
-11
lines changed

4 files changed

+36
-11
lines changed

.ruby-version

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
3.2.0
1+
3.3.0

lib/phlex/html.rb

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -356,14 +356,6 @@ def capture
356356
end
357357

358358
private def __attributes__(**attributes)
359-
if attributes[:href]&.start_with?(/\s*javascript/)
360-
attributes.delete(:href)
361-
end
362-
363-
if attributes["href"]&.start_with?(/\s*javascript/)
364-
attributes.delete("href")
365-
end
366-
367359
buffer = +""
368360
__build_attributes__(attributes, buffer: buffer)
369361

@@ -384,8 +376,11 @@ def capture
384376
else k.to_s
385377
end
386378

379+
lower_name = name.downcase
380+
next if lower_name == "href" && v.start_with?(/\s*javascript:/i)
381+
387382
# Detect unsafe attribute names. Attribute names are considered unsafe if they match an event attribute or include unsafe characters.
388-
if HTML::EVENT_ATTRIBUTES[name] || name.match?(/[<>&"']/)
383+
if HTML::EVENT_ATTRIBUTES[lower_name] || name.match?(/[<>&"']/)
389384
raise ArgumentError, "Unsafe attribute name detected: #{k}."
390385
end
391386

lib/phlex/version.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
# frozen_string_literal: true
22

33
module Phlex
4-
VERSION = "1.2.1"
4+
VERSION = "1.2.2"
55
end

test/phlex/view/naughty_business.rb

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,36 @@
33
describe Phlex::HTML do
44
extend ViewHelper
55

6+
with "naughty javascript links" do
7+
view do
8+
def template
9+
a(href: "javascript:alert(1)") { "a" }
10+
a(href: "JAVASCRIPT:alert(1)") { "b" }
11+
a(href: :"JAVASCRIPT:alert(1)") { "c" }
12+
a(HREF: "javascript:alert(1)") { "d" }
13+
end
14+
end
15+
16+
it "removes the href attributes" do
17+
expect(output).to be == "<a>a</a><a>b</a><a>c</a><a>d</a>"
18+
end
19+
end
20+
21+
with "naughty uppercase event tag" do
22+
view do
23+
def template
24+
button ONCLICK: "ALERT(1)" do
25+
"naughty button"
26+
end
27+
end
28+
end
29+
30+
it "raises" do
31+
expect { output }.to raise_exception ArgumentError,
32+
message: be == "Unsafe attribute name detected: ONCLICK."
33+
end
34+
end
35+
636
with "naughty text" do
737
view do
838
def template

0 commit comments

Comments
 (0)