@rpcbase/server 0.280.0 → 0.281.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.
@@ -0,0 +1,26 @@
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
+ if (req.hostname !== APP_DOMAIN) {
15
+ console.log("request from invalid hostname", {
16
+ hostname: req.hostname,
17
+ url: req.url
18
+ })
19
+ req.connection.destroy()
20
+ } else {
21
+ next()
22
+ }
23
+ })
24
+ }
25
+
26
+ 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: 1.0, // Capture 100% of the transactions, reduce in production!,
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`}))
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@rpcbase/server",
3
- "version": "0.280.0",
3
+ "version": "0.281.0",
4
4
  "license": "SSPL-1.0",
5
5
  "main": "./index.js",
6
6
  "bin": {