Skip to content

Fix shell command injection via sequence range in Database#retrieve - #844

Open
yannickwurm wants to merge 1 commit into
masterfrom
claude/security-shell-injection-saml-llstzr
Open

Fix shell command injection via sequence range in Database#retrieve#844
yannickwurm wants to merge 1 commit into
masterfrom
claude/security-shell-injection-saml-llstzr

Conversation

@yannickwurm

Copy link
Copy Markdown
Member

Summary

Database#retrieve (lib/sequenceserver/database.rb) builds the shell command blastdbcmd -db <db> -entry '<accession>' -range <coords> with coords interpolated unquoted. The only guard was the unanchored regex /[0-9]+-[0-9]*/, so any string containing a digit-dash pair passed, e.g. 1-2;echo INJECTED, and the trailing command was executed by the shell.

Reachable via GET /searchdata.json?query=<accession>:1-2;<cmd>. This is pre-authentication in standalone SequenceServer and behind login in the cloud deployment. Present in 3.1.3 (the commit this branch is based on is the one deployed as the sequenceserver submodule of sequenceserver-cloud).

Changes

  • lib/sequenceserver/blast.rb: add BLAST::VALID_SEQUENCE_RANGE = /\A[0-9]+-[0-9]*\z/, anchored at both ends, next to the existing VALID_SEQUENCE_ID.
  • lib/sequenceserver/database.rb: validate coords against that constant instead of the unanchored literal. Only start-stop or start- (open ended) can now reach the command line; everything else raises InvalidParameterError as before.
  • spec/database_spec.rb: regression specs for an appended command (1-2;echo INJECTED), a command hidden behind a newline (1-2\n;echo INJECTED, which ^/$ anchors would have missed), and a non-numeric prefix (x1-2).

Accessions were already validated by the anchored VALID_SEQUENCE_ID and are not affected.

Testing

bundle exec rspec spec/database_spec.rb   # 11 examples, 0 failures

Run locally with BLAST+ 2.12 (NCBI FTP is blocked from the sandbox, so BLAST_VERSION was overridden for the local run only; nothing of that is in the diff). RuboCop reports no new offences on the changed files.

🤖 Generated with Claude Code

https://claude.ai/code/session_01T22rUQt69nPsbSUDFxhuq3


Generated by Claude Code

Database#retrieve interpolates the user supplied range into a shell command
(`blastdbcmd ... -range <coords>`), but validated it with the unanchored
regex /[0-9]+-[0-9]*/. Any string containing a digit-dash pair passed, so a
range such as `1-2;echo INJECTED` was accepted and the trailing command was
executed by the shell. The range is reachable, without authentication in
standalone SequenceServer, through
`GET /searchdata.json?query=<accession>:<range>`.

The range is now validated against BLAST::VALID_SEQUENCE_RANGE, which is
anchored at both ends (\A[0-9]+-[0-9]*\z) so only "start-stop" or "start-"
can reach the command line. Specs cover an appended command, a command
hidden behind a newline, and a non-numeric prefix.

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01T22rUQt69nPsbSUDFxhuq3
@CLAassistant

Copy link
Copy Markdown

CLA assistant check
Thank you for your submission! We really appreciate it. Like many open source projects, we ask that you sign our Contributor License Agreement before we can accept your contribution.
You have signed the CLA already but the status is still pending? Let us recheck it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants