@warren-bank/hls-proxy 3.6.5 → 3.6.6

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/README.md CHANGED
@@ -159,6 +159,7 @@ options:
159
159
  -v <number>
160
160
  --acl-ip <ip_address_list>
161
161
  --acl-pass <password_list>
162
+ --block-req-hostname <hostname_list>
162
163
  --http-proxy <http[s]://[user:pass@]hostname:port>
163
164
  --tls-cert <filepath>
164
165
  --tls-key <filepath>
@@ -394,6 +395,8 @@ options:
394
395
  * ex: `"192.168.1.100,192.168.1.101,192.168.1.102"`
395
396
  * _--acl-pass_ restricts proxy server access to requests that include a `password` querystring parameter having a value in whitelist
396
397
  * ex: `"1111,2222,3333,4444,5555"`
398
+ * _--block-req-hostname_ blocks proxy server requests to hostnames in blacklist
399
+ * ex: `"localhost,127.0.0.1"`
397
400
  * --http-proxy enables all outbound HTTP and HTTPS requests from HLS-Proxy to be tunnelled through an additional external web proxy server
398
401
  * SOCKS proxies are not supported
399
402
  * ex: `http://myusername:mypassword@myproxy.example.com:1234`
@@ -47,6 +47,7 @@ const middleware = require('../proxy')({
47
47
  debug_level: argv_vals["-v"],
48
48
  acl_ip: argv_vals["--acl-ip"],
49
49
  acl_pass: argv_vals["--acl-pass"],
50
+ block_req_hostname: argv_vals["--block-req-hostname"],
50
51
  http_proxy: argv_vals["--http-proxy"],
51
52
  manifest_extension: argv_vals["--manifest-extension"],
52
53
  segment_extension: argv_vals["--segment-extension"]
@@ -30,6 +30,7 @@ options:
30
30
  -v <number>
31
31
  --acl-ip <ip_address_list>
32
32
  --acl-pass <password_list>
33
+ --block-req-hostname <hostname_list>
33
34
  --http-proxy <http[s]://[user:pass@]hostname:port>
34
35
  --tls-cert <filepath>
35
36
  --tls-key <filepath>
@@ -38,6 +38,7 @@ const argv_flags = {
38
38
  "-v": {num: "int"},
39
39
  "--acl-ip": {},
40
40
  "--acl-pass": {},
41
+ "--block-req-hostname": {},
41
42
  "--http-proxy": {},
42
43
 
43
44
  "--tls-cert": {file: "path-exists"},
@@ -177,6 +178,10 @@ if (argv_vals["--acl-pass"]) {
177
178
  argv_vals["--acl-pass"] = argv_vals["--acl-pass"].trim().split(/\s*,\s*/g)
178
179
  }
179
180
 
181
+ if (argv_vals["--block-req-hostname"]) {
182
+ argv_vals["--block-req-hostname"] = argv_vals["--block-req-hostname"].trim().toLowerCase().split(/\s*,\s*/g)
183
+ }
184
+
180
185
  if (argv_vals["--http-proxy"]) {
181
186
  const proxy_options = {
182
187
  keepAlive: true,
@@ -6,17 +6,17 @@ const timers = require('./timers')
6
6
  const utils = require('./utils')
7
7
 
8
8
  const get_middleware = function(params) {
9
- const {cache_segments} = params
10
- let {acl_ip} = params
9
+ const {acl_ip, cache_segments} = params
11
10
 
12
11
  const segment_cache = require('./segment_cache')(params)
13
12
  const {get_segment, add_listener} = segment_cache
14
13
 
15
- const is_acl_pass_allowed = acl_pass.is_allowed.bind(null, params)
16
- const debug = utils.debug.bind(null, params)
17
- const parse_req_url = utils.parse_req_url.bind(null, params)
18
- const get_request_options = utils.get_request_options.bind(null, params)
19
- const modify_m3u8_content = parser.modify_m3u8_content.bind(null, params, segment_cache)
14
+ const is_acl_pass_allowed = acl_pass.is_allowed.bind(null, params)
15
+ const debug = utils.debug.bind(null, params)
16
+ const parse_req_url = utils.parse_req_url.bind(null, params)
17
+ const get_request_options = utils.get_request_options.bind(null, params)
18
+ const block_request_options = utils.block_request_options.bind(null, params)
19
+ const modify_m3u8_content = parser.modify_m3u8_content.bind(null, params, segment_cache)
20
20
 
21
21
  const middleware = {}
22
22
 
@@ -57,6 +57,14 @@ const get_middleware = function(params) {
57
57
 
58
58
  const qs_password = acl_pass.get_decoded_qs_password(req)
59
59
  const is_m3u8 = (url_type === 'm3u8')
60
+ const options = get_request_options(url, is_m3u8, referer_url, querystring_req_headers, req.headers)
61
+
62
+ if (block_request_options(options)) {
63
+ res.writeHead(401)
64
+ res.end()
65
+ debug(2, 'request blocked by hostname blacklist:', url)
66
+ return
67
+ }
60
68
 
61
69
  const send_cache_segment = function(segment, type) {
62
70
  if (!type)
@@ -79,7 +87,6 @@ const get_middleware = function(params) {
79
87
  }
80
88
  }
81
89
 
82
- const options = get_request_options(url, is_m3u8, referer_url, querystring_req_headers, req.headers)
83
90
  debug(1, 'proxying:', url)
84
91
  debug(3, 'm3u8:', (is_m3u8 ? 'true' : 'false'))
85
92
 
@@ -197,6 +197,24 @@ const get_request_options = function(params, url, is_m3u8, referer_url, querystr
197
197
  return request_options
198
198
  }
199
199
 
200
+ const block_request_options = function(params, request_options) {
201
+ const {block_req_hostname} = params
202
+
203
+ // short circuit
204
+ if (!block_req_hostname || !Array.isArray(block_req_hostname) || !block_req_hostname.length || !request_options)
205
+ return false
206
+
207
+ // special case: url
208
+ if (typeof request_options === 'string')
209
+ request_options = parse_url(request_options)
210
+
211
+ // sanity check
212
+ if (!request_options.hostname || (typeof request_options.hostname !== 'string'))
213
+ return false
214
+
215
+ return (block_req_hostname.indexOf(request_options.hostname.toLowerCase()) >= 0)
216
+ }
217
+
200
218
  const should_prefetch_url = function(params, url, url_type) {
201
219
  const {hooks, cache_segments} = params
202
220
 
@@ -226,5 +244,6 @@ module.exports = {
226
244
  debug,
227
245
  normalize_req_headers,
228
246
  get_request_options,
247
+ block_request_options,
229
248
  should_prefetch_url
230
249
  }
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@warren-bank/hls-proxy",
3
3
  "description": "Node.js server to proxy HLS video streams",
4
- "version": "3.6.5",
4
+ "version": "3.6.6",
5
5
  "scripts": {
6
6
  "start": "node hls-proxy/bin/hlsd.js",
7
7
  "sudo": "sudo node hls-proxy/bin/hlsd.js"