Skip to content

Commit

Permalink
Default host to localhost when in development mode.
Browse files Browse the repository at this point in the history
* Running Rack apps on 0.0.0.0 in development mode will allow malicious
  users on the local network (ex: Coffee Shop) to abuse or potentially
  exploit the app. Safer to default host to localhost when in development
  mode.
  • Loading branch information
postmodern committed Feb 10, 2013
1 parent 189bce4 commit 0f9a959
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 2 deletions.
2 changes: 1 addition & 1 deletion lib/sinatra/base.rb
Original file line number Diff line number Diff line change
Expand Up @@ -1690,7 +1690,7 @@ class << self
set :run, false # start server via at-exit hook?
set :running, false # is the built-in server running now?
set :server, %w[http webrick]
set :bind, '0.0.0.0'
set :bind, Proc.new { development? ? 'localhost' : '0.0.0.0' }
set :port, Integer(ENV['PORT'] || 4567)

ruby_engine = defined?(RUBY_ENGINE) && RUBY_ENGINE
Expand Down
2 changes: 1 addition & 1 deletion lib/sinatra/main.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ class Application < Base
require 'optparse'
OptionParser.new { |op|
op.on('-p port', 'set the port (default is 4567)') { |val| set :port, Integer(val) }
op.on('-o addr', 'set the host (default is 0.0.0.0)') { |val| set :bind, val }
op.on('-o addr', "set the host (default is #{bind})") { |val| set :bind, val }
op.on('-e env', 'set the environment (default is development)') { |val| set :environment, val.to_sym }
op.on('-s server', 'specify rack server/handler (default is thin)') { |val| set :server, val }
op.on('-x', 'turn on the mutex lock (default is off)') { set :lock, true }
Expand Down

8 comments on commit 0f9a959

@envygeeks
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Don't most, if not all Firewalls block incoming by default?

@whitequark
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@envygeeks, not everyone runs a[n enabled] firewall. A default Debian installation does not feature one, for example. Not sure about OS X.

@envygeeks
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@whitequark The default Debian install does come with a packet filter and most sysadmins who use Debian would have already added:

-P INPUT DROP
-P FORWARD DROP
-A INPUT -m state --state ESTABLISHED,RELATED -j ACCEPT

as one of the first things they do on their clean system... I too do not know about OS X. On Ubuntu you need only type:

sudo ufw default deny
sudo ufw enabled

on Windows I believe you need do nothing special because it's Firewall is enabled by default if I remember.

@postmodern
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also not sure about OSX or Windows. Do they block all incoming connections, or only certain port rages?

@whitequark
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@envygeeks, the key word is "sysadmins". We're talking about developers here.

@envygeeks
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I just checked my Windows laptop and it looks like on Windows it defaults to blocking based on application so by default it allows no incoming connections that are not related, unless it's networking (router communication and such) and if you choose home it will allow sharing and all that junk.

@envygeeks
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@whitequark fair enough, that's a good point.

@postmodern
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

FWIW, even though Ubuntu/Fedora started shipping with connection-tracking firewalls, they still run internal services on 127.0.0.1.

Please sign in to comment.