Commit ea88c9b2 authored by Jacob Vosmaer's avatar Jacob Vosmaer

Handle invalid number of arguments

When a remote user with a valid SSH key runs something like 'ssh
git@gitlab.example.com foobar', gitlab-shell would raise an exception in
the GitlabShell#escape_path method. With this change, we catch an
invalid number of arguments as soon as possible and exit.
parent b5284310
v1.9.8
- Replace raise with abort when checking path to prevent path exposure
- Handle invalid number of arguments on remote commands
v1.9.7
- Increased test coverage
......
......@@ -3,6 +3,8 @@ require 'shellwords'
require_relative 'gitlab_net'
class GitlabShell
DisallowedCommandError = Class.new(StandardError)
attr_accessor :key_id, :repo_name, :git_cmd, :repos_path, :repo_name
def initialize
......@@ -28,19 +30,22 @@ class GitlabShell
$stderr.puts "Access denied."
end
else
message = "gitlab-shell: Attempt to execute disallowed command <#{@origin_cmd}> by #{log_username}."
$logger.warn message
puts 'Not allowed command'
raise DisallowedCommandError
end
else
puts "Welcome to GitLab, #{username}!"
end
rescue DisallowedCommandError => ex
message = "gitlab-shell: Attempt to execute disallowed command <#{@origin_cmd}> by #{log_username}."
$logger.warn message
puts 'Not allowed command'
end
protected
def parse_cmd
args = Shellwords.shellwords(@origin_cmd)
raise DisallowedCommandError unless args.count == 2
@git_cmd = args[0]
@repo_name = escape_path(args[1])
end
......
......@@ -48,6 +48,14 @@ describe GitlabShell do
its(:repo_name) { should == 'dmitriy.zaporozhets/gitlab-ci.git' }
its(:git_cmd) { should == 'git-upload-pack' }
end
context 'with an invalid number of arguments' do
before { ssh_cmd 'foobar' }
it "should raise an DisallowedCommandError" do
expect { subject.send :parse_cmd }.to raise_error(GitlabShell::DisallowedCommandError)
end
end
end
describe :exec do
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment