@@ -32,10 +32,17 @@ const config = {
32
32
PORT : process . env . PORT || 3000 ,
33
33
LOG_LEVEL_OVERRIDE_DURATION : process . env . LOG_LEVEL_OVERRIDE_DURATION || 300 ,
34
34
ENV : process . env . ENV || "NA" ,
35
+ PERMITTED_ROUTES_FILE : process . env . PERMITTED_ROUTES_FILE || "./config/permitted-routes.json" ,
36
+ PERMITTED_ROUTES_JSON : process . env . PERMITTED_ROUTES_JSON || ""
35
37
} ;
36
38
37
- if ( fs . existsSync ( "./config/permitted-routes.json" ) ) {
38
- config . PERMITTED_ROUTES = JSON . parse ( fs . readFileSync ( "./config/permitted-routes.json" ) ) ;
39
+ if ( fs . existsSync ( config . PERMITTED_ROUTES_FILE ) ) {
40
+ if ( config . PERMITTED_ROUTES_JSON ) {
41
+ config . PERMITTED_ROUTES = JSON . parse ( config . PERMITTED_ROUTES_JSON )
42
+ }
43
+ else {
44
+ config . PERMITTED_ROUTES = JSON . parse ( fs . readFileSync ( config . PERMITTED_ROUTES_FILE ) ) ;
45
+ }
39
46
}
40
47
41
48
// #endregion
@@ -46,19 +53,19 @@ const gLogFunc = console.log;
46
53
const gWarnFunc = console . warn ;
47
54
48
55
function initLogLevels ( level ) {
49
- console . debug = ( ) => { } ;
50
- console . trace = ( ) => { } ;
51
- console . info = ( ) => { } ;
52
- console . warn = ( ) => { } ;
53
- console . log = ( ) => { } ;
56
+ console . debug = ( ) => { } ;
57
+ console . trace = ( ) => { } ;
58
+ console . info = ( ) => { } ;
59
+ console . warn = ( ) => { } ;
60
+ console . log = ( ) => { } ;
54
61
55
62
if ( level === "warn" ) {
56
- console . log = ( ) => { } ;
63
+ console . log = ( ) => { } ;
57
64
console . warn = gWarnFunc ;
58
65
}
59
66
if ( level === "error" ) {
60
- console . log = ( ) => { } ;
61
- console . warn = ( ) => { } ;
67
+ console . log = ( ) => { } ;
68
+ console . warn = ( ) => { } ;
62
69
}
63
70
if ( level === "info" ) {
64
71
console . log = gLogFunc ;
@@ -179,7 +186,12 @@ async function fetchAPIKeysInfo(key) {
179
186
}
180
187
} ) ;
181
188
}
182
-
189
+ /**
190
+ *
191
+ * @param {String } url "Url to validate against route rules"
192
+ * @param {Array } routes "Allowed or Permitted routes to match against"
193
+ * @returns
194
+ */
183
195
const checkRoutes = ( url , routes ) => {
184
196
if ( ! routes || ! routes . length ) {
185
197
return false ;
@@ -203,7 +215,6 @@ const allowPassthrough = (url, method, acl) => {
203
215
if ( config . ALLOW_PUBLIC_ACCESS ) {
204
216
return true ;
205
217
}
206
-
207
218
// check permitted routes
208
219
if ( config . PERMITTED_ROUTES && config . PERMITTED_ROUTES [ method ] ?. length && checkRoutes ( url , config . PERMITTED_ROUTES [ method ] ) ) {
209
220
return true ;
@@ -213,7 +224,6 @@ const allowPassthrough = (url, method, acl) => {
213
224
if ( checkRoutes ( url , acl ?. ops ) ) {
214
225
return true ;
215
226
}
216
-
217
227
return false ;
218
228
} ;
219
229
// #endregion
@@ -257,6 +267,7 @@ app.use(async (req, res, next) => {
257
267
}
258
268
259
269
if ( ! allowPassthrough ( req . url , req . method , req . acl ) ) {
270
+ console . warn ( `AUTH-PROXY-AUDIT: ${ req . url } ` )
260
271
return res . status ( 401 ) . send ( "Unauthorized" ) ;
261
272
} else {
262
273
next ( ) ;
@@ -325,6 +336,9 @@ app.use(
325
336
// Proxy request to end point
326
337
const writeBody = ( bodyData ) => {
327
338
proxyReq . setHeader ( "Content-Length" , Buffer . byteLength ( bodyData ) ) ;
339
+ if ( config . LOG_LEVEL === "debug" ) {
340
+ proxyReq . removeHeader ( 'Accept-Encoding' )
341
+ }
328
342
proxyReq . write ( bodyData ) ;
329
343
} ;
330
344
0 commit comments