@rpcbase/server 0.280.0 → 0.282.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/express/block_invalid_hosts.js +27 -0
- package/express/index.js +4 -1
- package/package.json +1 -1
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
/* @flow */
|
|
2
|
+
const assert = require("assert")
|
|
3
|
+
|
|
4
|
+
const {APP_DOMAIN} = process.env
|
|
5
|
+
|
|
6
|
+
const is_production = process.env.NODE_ENV === "production"
|
|
7
|
+
|
|
8
|
+
const block_invalid_hosts = (app) => {
|
|
9
|
+
|
|
10
|
+
// only block invalid hosts in production
|
|
11
|
+
if (!is_production) return
|
|
12
|
+
|
|
13
|
+
app.use((req, res, next) => {
|
|
14
|
+
// dockerip.host is needed for platform/reverse-proxy
|
|
15
|
+
if (![APP_DOMAIN, "dockerip.host"].includes(req.hostname)) {
|
|
16
|
+
console.log("request from invalid hostname", {
|
|
17
|
+
hostname: req.hostname,
|
|
18
|
+
url: req.url
|
|
19
|
+
})
|
|
20
|
+
req.connection.destroy()
|
|
21
|
+
} else {
|
|
22
|
+
next()
|
|
23
|
+
}
|
|
24
|
+
})
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
module.exports = block_invalid_hosts
|
package/express/index.js
CHANGED
|
@@ -11,6 +11,7 @@ const sessions = require("../src/sessions")
|
|
|
11
11
|
|
|
12
12
|
const dev_save_coverage = require("./dev_save_coverage")
|
|
13
13
|
const custom_cors = require("./custom_cors")
|
|
14
|
+
const block_invalid_hosts = require("./block_invalid_hosts")
|
|
14
15
|
|
|
15
16
|
const log = debug("rb:server")
|
|
16
17
|
|
|
@@ -45,7 +46,7 @@ module.exports = () => {
|
|
|
45
46
|
}),
|
|
46
47
|
],
|
|
47
48
|
// Performance Monitoring
|
|
48
|
-
tracesSampleRate:
|
|
49
|
+
tracesSampleRate: 0.5, // Capture 100% of the transactions, reduce in production!,
|
|
49
50
|
})
|
|
50
51
|
|
|
51
52
|
// Trace incoming requests
|
|
@@ -53,6 +54,8 @@ module.exports = () => {
|
|
|
53
54
|
app.use(Sentry.Handlers.tracingHandler())
|
|
54
55
|
}
|
|
55
56
|
|
|
57
|
+
block_invalid_hosts(app)
|
|
58
|
+
|
|
56
59
|
app.use(request_ip.mw())
|
|
57
60
|
|
|
58
61
|
app.use(body_parser.json({limit: `${BODY_MAX_SIZE_MB}mb`}))
|