Skip to content

Commit f357243

Browse files
arfonxuanxu
authored andcommitted
Prevent path traversal via bibliography metadata field
The bibliography filename is read from the submitter-controlled paper.yml / paper.md front matter and concatenated to the paper's directory with no normalisation, so a value like "../../../../etc/hosts" resolves outside the clone directory. BibTeX.open then reads that file and any unparseable lines are echoed back into the public review issue via DOIWorker. Clamp the bibliography filename with File.basename so the lookup always stays inside the paper's directory.
1 parent 86fa5b8 commit f357243

2 files changed

Lines changed: 11 additions & 1 deletion

File tree

app/lib/paper_file.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ def bibtex_entries
3939
end
4040

4141
def bibtex_path
42-
@bibtex_path ||= "#{File.dirname(paper_path)}/#{bibtex_filename}"
42+
@bibtex_path ||= "#{File.dirname(paper_path)}/#{File.basename(bibtex_filename.to_s)}"
4343
end
4444

4545
def bibtex_filename

spec/paper_file_spec.rb

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,16 @@
5454
expect(YAML).to receive(:load_file).with("./doc/paper.md").and_return({'bibliography' => 'references.bib'})
5555
expect(subject.bibtex_path).to eq("./doc/references.bib")
5656
end
57+
58+
it "should clamp the bibliography filename to its basename to prevent path traversal" do
59+
expect(YAML).to receive(:load_file).with("./doc/paper.md").and_return({'bibliography' => '../../../../etc/hosts'})
60+
expect(subject.bibtex_path).to eq("./doc/hosts")
61+
end
62+
63+
it "should strip leading directories from the bibliography filename" do
64+
expect(YAML).to receive(:load_file).with("./doc/paper.md").and_return({'bibliography' => 'subdir/refs.bib'})
65+
expect(subject.bibtex_path).to eq("./doc/refs.bib")
66+
end
5767
end
5868

5969
describe "#bib" do

0 commit comments

Comments
 (0)