Skip to content

Commit adf294b

Browse files
committed
Make usable chars more strict
Remove other than alphanumeric and some punctuations considered filesystem-safe, instead of removing some unsafe chars only. https://hackerone.com/reports/1131465
1 parent 363e1ec commit adf294b

File tree

2 files changed

+5
-3
lines changed

2 files changed

+5
-3
lines changed

lib/tmpdir.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,7 @@ def tmpdir
115115
Dir.tmpdir
116116
end
117117

118-
UNUSABLE_CHARS = [File::SEPARATOR, File::ALT_SEPARATOR, File::PATH_SEPARATOR, ":"].uniq.join("").freeze
118+
UNUSABLE_CHARS = "^,-.0-9A-Z_a-z~"
119119

120120
class << (RANDOM = Random.new)
121121
MAX = 36**6 # < 0x100000000

test/test_tmpdir.rb

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -97,8 +97,10 @@ def assert_mktmpdir_traversal
9797
target = target.chomp('/') + '/'
9898
traversal_path = target.sub(/\A\w:/, '') # for DOSISH
9999
traversal_path = Array.new(target.count('/')-2, '..').join('/') + traversal_path
100-
actual = yield traversal_path
101-
assert_not_send([File.absolute_path(actual), :start_with?, target])
100+
[File::SEPARATOR, File::ALT_SEPARATOR].compact.each do |separator|
101+
actual = yield traversal_path.tr('/', separator)
102+
assert_not_send([File.absolute_path(actual), :start_with?, target])
103+
end
102104
end
103105
end
104106
end

0 commit comments

Comments
 (0)