Skip to content

Commit

Permalink
Make usable chars more strict
Browse files Browse the repository at this point in the history
Remove other than alphanumeric and some punctuations considered
filesystem-safe, instead of removing some unsafe chars only.

https://hackerone.com/reports/1131465
  • Loading branch information
nobu committed Apr 1, 2021
1 parent 363e1ec commit adf294b
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 3 deletions.
2 changes: 1 addition & 1 deletion lib/tmpdir.rb
Expand Up @@ -115,7 +115,7 @@ def tmpdir
Dir.tmpdir
end

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

class << (RANDOM = Random.new)
MAX = 36**6 # < 0x100000000
Expand Down
6 changes: 4 additions & 2 deletions test/test_tmpdir.rb
Expand Up @@ -97,8 +97,10 @@ def assert_mktmpdir_traversal
target = target.chomp('/') + '/'
traversal_path = target.sub(/\A\w:/, '') # for DOSISH
traversal_path = Array.new(target.count('/')-2, '..').join('/') + traversal_path
actual = yield traversal_path
assert_not_send([File.absolute_path(actual), :start_with?, target])
[File::SEPARATOR, File::ALT_SEPARATOR].compact.each do |separator|
actual = yield traversal_path.tr('/', separator)
assert_not_send([File.absolute_path(actual), :start_with?, target])
end
end
end
end

0 comments on commit adf294b

Please sign in to comment.