From 62561f28448bc848fe4572a1849adea4488b0a17 Mon Sep 17 00:00:00 2001 From: Mitchell Hashimoto Date: Fri, 8 Aug 2014 11:58:53 -0700 Subject: [PATCH] core: guard against SSH to localhost:22 [GH-4070] --- CHANGELOG.md | 1 + lib/vagrant/machine.rb | 7 +++++++ test/unit/vagrant/machine_test.rb | 7 +++++++ 3 files changed, 15 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 6e007f1ba..b1aec259b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -19,6 +19,7 @@ IMPROVEMENTS: BUG FIXES: + - core: Guard against SSHing to localhost:22 [GH-4070] - core: Downloading box files should resume in more cases since the temporary file is preserved in more cases. [GH-4301] - core: Windows is not detected as NixOS in some cases. [GH-4302] diff --git a/lib/vagrant/machine.rb b/lib/vagrant/machine.rb index 9d2c0d15c..fc1f9929a 100644 --- a/lib/vagrant/machine.rb +++ b/lib/vagrant/machine.rb @@ -434,6 +434,13 @@ module Vagrant File.expand_path(path, @env.root_path) end + # If we're connecting to localhost:22, then short-circuit + # and return nil here since this is something that nobody ever + # really wants. + if info[:host] == "127.0.0.1" && info[:port] == 22 + return nil + end + # Return the final compiled SSH info data info end diff --git a/test/unit/vagrant/machine_test.rb b/test/unit/vagrant/machine_test.rb index 3e10d8959..beb23887e 100644 --- a/test/unit/vagrant/machine_test.rb +++ b/test/unit/vagrant/machine_test.rb @@ -605,6 +605,13 @@ describe Vagrant::Machine do expect(instance.ssh_info[:password]).to eql("") end + it "should return nil if localhost:22" do + provider_ssh_info[:host] = "127.0.0.1" + instance.config.ssh.port = 22 + + expect(instance.ssh_info).to be_nil + end + context "with no data dir" do let(:base) { true } let(:data_dir) { nil }