Skip to content

Commit e254606

Browse files
committed
prevent Symbol attack in Raydebug scanner
1 parent ee30738 commit e254606

File tree

1 file changed

+14
-2
lines changed

1 file changed

+14
-2
lines changed

lib/coderay/scanners/raydebug.rb

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
require 'set'
2+
13
module CodeRay
24
module Scanners
35

@@ -12,6 +14,11 @@ class Raydebug < Scanner
1214

1315
protected
1416

17+
def setup
18+
super
19+
@known_token_kinds = TokenKinds.keys.map(&:to_s).to_set
20+
end
21+
1522
def scan_tokens encoder, options
1623

1724
opened_tokens = []
@@ -26,8 +33,13 @@ def scan_tokens encoder, options
2633
encoder.text_token kind, :class
2734
encoder.text_token '(', :operator
2835
match = self[2]
29-
# FIXME: cache attack
30-
encoder.text_token match, kind.to_sym unless match.empty?
36+
unless match.empty?
37+
if @known_token_kinds.include? kind
38+
encoder.text_token match, kind.to_sym
39+
else
40+
encoder.text_token match, :plain
41+
end
42+
end
3143
encoder.text_token match, :operator if match = scan(/\)/)
3244

3345
elsif match = scan(/ (\w+) ([<\[]) /x)

0 commit comments

Comments
 (0)