File tree Expand file tree Collapse file tree 3 files changed +34
-6
lines changed Expand file tree Collapse file tree 3 files changed +34
-6
lines changed Original file line number Diff line number Diff line change 2
2
3
3
var anonymousAccessBlocker = require ( './middleware/anonymousAccessBlocker' ) ;
4
4
var healthcheck = require ( './middleware/healthcheck' ) ;
5
+ var httpValidation = require ( './middleware/httpValidation' ) ;
5
6
var log41n = require ( './middleware/log41n' ) ;
6
7
7
8
var Log1n = function ( ) {
8
9
var self = this ;
9
10
10
11
self . register = function ( keystone ) {
12
+ console . log ( 'keystone-hosting: Adding Keystone routes' ) ;
13
+
11
14
keystone . pre ( 'routes' , healthcheck ( keystone ) ) ;
15
+ keystone . pre ( 'routes' , httpValidation ( keystone ) ) ;
12
16
keystone . pre ( 'routes' , log41n ( keystone ) ) ;
13
17
keystone . pre ( 'routes' , anonymousAccessBlocker ( ) ) ;
14
18
} ;
@@ -17,4 +21,5 @@ var Log1n = function() {
17
21
module . exports = new Log1n ( ) ;
18
22
module . exports . anonymousAccessBlocker = anonymousAccessBlocker ;
19
23
module . exports . healthcheck = healthcheck ;
24
+ module . exports . httpValidation = httpValidation ;
20
25
module . exports . log41n = log41n ;
Original file line number Diff line number Diff line change @@ -21,10 +21,7 @@ module.exports = function() {
21
21
// The set of allowed ranges has to be separated by space characters, a comma, or newline.
22
22
var allowedRanges = ipRanges . split ( / \s + | , | \n / ) ;
23
23
24
- // Using req.ips requires that express 'trust proxy' setting is
25
- // true. When it *is* set the value for ips is extracted from the
26
- // X-Forwarded-For request header. The originating IP address is
27
- // the last one in the array.
24
+ //if CLIENT_IP_ADDRESS_HEADER is set and a request coming in does not contain it, it will be denied regardless of IP
28
25
var requestIP = ( process . env . CLIENT_IP_ADDRESS_HEADER ) ? req . header ( process . env . CLIENT_IP_ADDRESS_HEADER ) : req . ip ;
29
26
requestIP = rangeCheck . searchIP ( requestIP ) ;
30
27
@@ -34,13 +31,13 @@ module.exports = function() {
34
31
35
32
if ( requestAllowed ) {
36
33
// Allow the request to process
37
- console . log ( 'Allowed IP: ' + requestIP ) ;
34
+ console . log ( 'keystone-hosting: Allowed IP ' + requestIP ) ;
38
35
return next ( ) ;
39
36
}
40
37
}
41
38
42
39
// Request is not allowed. Send the contents of the unauthorized.html file.
43
- console . log ( 'Blocked IP: ' + requestIP ) ;
40
+ console . log ( 'keystone-hosting: Blocked IP ' + requestIP ) ;
44
41
45
42
//set 'unauthorized' response code
46
43
res . status ( 401 )
Original file line number Diff line number Diff line change
1
+ module . exports = function ( keystone ) {
2
+
3
+ //register a route to a static (e.g. /.well-known/etc) response, if configured
4
+ return function ( req , res , next ) {
5
+
6
+ //example from cloudflare:
7
+ //"http_url": "http://http-preval.example.com/.well-known/pki-validation/ca3-0052344e54074d9693e89e27486692d6.txt",
8
+ //(include leading slash) /.well-known/pki-validation/ca3-0052344e54074d9693e89e27486692d6.txt
9
+ //"http_body": "ca3-be794c5f757b468eba805d1a705e44f6"
10
+ //ca3-be794c5f757b468eba805d1a705e44f6
11
+
12
+ var enabled = process . env . HTTP_VALIDATION_LISTEN ;
13
+ var httpPath = process . env . HTTP_VALIDATION_PATH ;
14
+ var httpBody = process . env . HTTP_VALIDATION_BODY ;
15
+
16
+ //ignore all requests except the exact match for /.well-known/etc...
17
+ if ( enabled !== 'true' || ! httpPath || ! httpBody || req . path !== httpPath ) {
18
+ // console.log('keystone-hosting: ignoring request' + req.path)
19
+ return next ( ) ;
20
+ }
21
+
22
+ //hijack this request and simply return the desired body (a guid)
23
+ console . log ( 'keystone-hosting: HTTP Validation responding to ' + req . path )
24
+ res . send ( httpBody ) ;
25
+ }
26
+ }
You can’t perform that action at this time.
0 commit comments