diff --git a/History.md b/History.md index e976580608..b74782128a 100644 --- a/History.md +++ b/History.md @@ -1,5 +1,6 @@ ## v.NEXT +* Fix stack trace when a browser tries to use the server like a proxy. #1212 ## v1.0.2.1, 2014-Dec-22 diff --git a/packages/routepolicy/routepolicy.js b/packages/routepolicy/routepolicy.js index e426f6ac37..81e47c64c0 100644 --- a/packages/routepolicy/routepolicy.js +++ b/packages/routepolicy/routepolicy.js @@ -97,6 +97,10 @@ _.extend(RoutePolicyConstructor.prototype, { self.urlPrefixTypes[urlPrefix] = type; }, + isValidUrl: function (url) { + return url.charAt(0) === '/'; + }, + classify: function (url) { var self = this; if (url.charAt(0) !== '/') diff --git a/packages/webapp/webapp_server.js b/packages/webapp/webapp_server.js index 422357e33b..b5bd652d0e 100644 --- a/packages/webapp/webapp_server.js +++ b/packages/webapp/webapp_server.js @@ -565,6 +565,18 @@ var runWebAppServer = function () { var rawConnectHandlers = connect(); app.use(rawConnectHandlers); + // We're not a proxy; reject (without crashing) attempts to treat us like + // one. (See #1212.) + app.use(function(req, res, next) { + if (RoutePolicy.isValidUrl(req.url)) { + next(); + return; + } + res.writeHead(400); + res.write("Not a proxy"); + res.end(); + }); + // Strip off the path prefix, if it exists. app.use(function (request, response, next) { var pathPrefix = __meteor_runtime_config__.ROOT_URL_PATH_PREFIX;