Skip to content

Commit 987b921

Browse files
hwillsonbenjamn
authored andcommitted
Adjusted force-ssl to work with the forwarded header (RFC 7239). (meteor#8440)
* Adjusted force-ssl to work with the forwarded header (RFC 7239). * Fixed invalid Object.assign call.
1 parent 67fff9f commit 987b921

File tree

12 files changed

+450
-35
lines changed

12 files changed

+450
-35
lines changed
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
node_modules
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
This directory and the files immediately inside it are automatically generated
2+
when you change this package's NPM dependencies. Commit the files in this
3+
directory (npm-shrinkwrap.json, .gitignore, and this README) to source control
4+
so that others run the same versions of sub-dependencies.
5+
6+
You should NOT check in the node_modules directory that Meteor automatically
7+
creates; if you are using git, the .gitignore file tells git to ignore it.

packages/force-ssl-common/.npm/package/npm-shrinkwrap.json

Lines changed: 254 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

packages/force-ssl-common/README.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
# force-ssl-common
2+
[Source code of released version](https://github.com/meteor/meteor/tree/master/packages/force-ssl-common) | [Source code of development version](https://github.com/meteor/meteor/tree/devel/packages/force-ssl-common)
3+
***
4+
5+
This is an internal Meteor package.
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
import forwarded from 'forwarded-http';
2+
3+
// Determine if the connection is only over localhost. Both we
4+
// received it on localhost, and all proxies involved received on
5+
// localhost (supports "forwarded" and "x-forwarded-for").
6+
const isLocalConnection = (req) => {
7+
const localhostRegexp = /^\s*(127\.0\.0\.1|\[?::1\]?)\s*$/;
8+
const request = Object.create(req);
9+
request.connection = Object.assign(
10+
{},
11+
req.connection,
12+
{ remoteAddress: req.connection.remoteAddress || req.socket.remoteAddress }
13+
);
14+
const forwardedParams = forwarded(request);
15+
let isLocal = true;
16+
Object.keys(forwardedParams.for).forEach((forKey) => {
17+
if (!localhostRegexp.test(forKey)) {
18+
isLocal = false;
19+
}
20+
});
21+
return isLocal;
22+
};
23+
24+
// Determine if the connection was over SSL at any point. Either we
25+
// received it as SSL, or a proxy did and translated it for us.
26+
const isSslConnection = (req) => {
27+
const forwardedParams = forwarded(req);
28+
return req.connection.pair
29+
|| forwardedParams.proto && forwardedParams.proto.indexOf('https') !== -1;
30+
};
31+
32+
export { isLocalConnection, isSslConnection };

0 commit comments

Comments
 (0)