Skip to content
This repository has been archived by the owner on Apr 7, 2021. It is now read-only.

Commit

Permalink
allow for environmental variables to be blacklisted
Browse files Browse the repository at this point in the history
  • Loading branch information
atmos committed Dec 14, 2010
1 parent 108045f commit d90b212
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 0 deletions.
5 changes: 5 additions & 0 deletions server.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ QueryString = require 'querystring'

port = parseInt process.env.PORT || 8081
version = "0.3.0"
excluded = process.env.CAMO_HOST_EXCLUSIONS || '*.example.org'
shared_key = process.env.CAMO_KEY || '0x24FEEDFACEDEADBEEFCAFE'
logging_enabled = process.env.CAMO_LOGGING_ENABLED || "disabled"

Expand All @@ -15,6 +16,7 @@ log = (msg) ->
console.log(msg)
console.log("--------------------------------------------")

EXCLUDED_HOSTS = new RegExp(excluded.replace(".", "\\.").replace("*", "\\.*"))
RESTRICTED_IPS = /^(10\.)|(127\.)|(169\.254)|(192\.168)|(172\.(1[6-9])|(2[0-9])|(3[0-1]))/

server = Http.createServer (req, resp) ->
Expand Down Expand Up @@ -55,6 +57,9 @@ server = Http.createServer (req, resp) ->
url = Url.parse query_params.url

if url.host? && !url.host.match(RESTRICTED_IPS)
if url.host.match(EXCLUDED_HOSTS)
return four_oh_four("Hitting excluded hostnames")

src = Http.createClient url.port || 80, url.hostname

src.on 'error', (error) ->
Expand Down
6 changes: 6 additions & 0 deletions test/proxy_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -88,4 +88,10 @@ def test_404s_on_192_168_ip_range
request('http://192.168.0.1/foo.cgi')
end
end

def test_404s_on_environmental_excludes
assert_raise RestClient::ResourceNotFound do
request('http://iphone.internal.example.org/foo.cgi')
end
end
end

0 comments on commit d90b212

Please sign in to comment.