Skip to content

Commit

Permalink
Disallow relative paths that start with ../
Browse files Browse the repository at this point in the history
Fixes a potential arbitrary file read vulnerability in yard server.
Thanks to ztz <ztz@ztz.me> for discovery of this security issue.
  • Loading branch information
lsegal committed Nov 23, 2017
1 parent bd56c5d commit b0217b3
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 3 deletions.
2 changes: 2 additions & 0 deletions lib/yard/core_ext/file.rb
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,8 @@ def self.cleanpath(path)
if comp == RELATIVE_PARENTDIR && !acc.empty? && acc.last != RELATIVE_PARENTDIR
acc.pop
next acc
elsif comp == RELATIVE_PARENTDIR && acc.empty?
next acc
end
acc << comp
end
Expand Down
6 changes: 3 additions & 3 deletions spec/core_ext/file_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -41,12 +41,12 @@
expect(File.cleanpath('A/B/C/D/..')).to eq "A/B/C"
end

it "passes the initial directory" do
expect(File.cleanpath('C/../../D')).to eq "../D"
it "does not allow relative path above root" do
expect(File.cleanpath('A/../../../../../D')).to eq "D"
end

it "does not remove multiple '../' at the beginning" do
expect(File.cleanpath('../../A/B')).to eq '../../A/B'
expect(File.cleanpath('../../A/B')).to eq 'A/B'
end
end

Expand Down

0 comments on commit b0217b3

Please # to comment.