Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions lib/sequenceserver/blast.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,10 @@
module SequenceServer
module BLAST
VALID_SEQUENCE_ID = /\A[a-zA-Z0-9\-_.:*#|\[\]]+\z/

# Sequence range accepted by `blastdbcmd -range`: "start-stop" or "start-"
# (open ended). Anchored at both ends so that shell metacharacters cannot
# be smuggled in alongside an otherwise valid range.
VALID_SEQUENCE_RANGE = /\A[0-9]+-[0-9]*\z/
end
end
2 changes: 1 addition & 1 deletion lib/sequenceserver/database.rb
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ def retrieve(accession, coords = nil)
fail(
InvalidParameterError,
"Invalid range coordinates: #{coords}"
) unless coords =~ /[0-9]+-[0-9]*/
) unless coords =~ SequenceServer::BLAST::VALID_SEQUENCE_RANGE

cmd << " -range #{coords}"
end
Expand Down
18 changes: 18 additions & 0 deletions spec/database_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,24 @@ module SequenceServer
Database.retrieve("SI2.2.0_06267:';hi")
end.to raise_error(SequenceServer::InvalidParameterError)
end

it 'rejects a shell command appended to an otherwise valid range' do
expect do
Database.retrieve('SI2.2.0_06267:1-2;echo INJECTED')
end.to raise_error(SequenceServer::InvalidParameterError)
end

it 'rejects a shell command hidden behind a newline in the range' do
expect do
Database.retrieve("SI2.2.0_06267:1-2\n;echo INJECTED")
end.to raise_error(SequenceServer::InvalidParameterError)
end

it 'rejects a range that is only a prefix of a valid one' do
expect do
Database.retrieve('SI2.2.0_06267:x1-2')
end.to raise_error(SequenceServer::InvalidParameterError)
end
end
end
end
Loading