Chore/Add Deny List URLs (#4933)
Refactor URL filtering logic in App class - Introduced a denylist for URLs using the DENYLIST_URLS environment variable. - Updated the whitelist logic to filter out denylisted URLs, ensuring improved request validation.
This commit is contained in:
parent
f2bd83252d
commit
d081221a97
|
|
@ -197,7 +197,8 @@ export class App {
|
||||||
if (next) next()
|
if (next) next()
|
||||||
})
|
})
|
||||||
|
|
||||||
const whitelistURLs = WHITELIST_URLS
|
const denylistURLs = process.env.DENYLIST_URLS ? process.env.DENYLIST_URLS.split(',') : []
|
||||||
|
const whitelistURLs = WHITELIST_URLS.filter((url) => !denylistURLs.includes(url))
|
||||||
const URL_CASE_INSENSITIVE_REGEX: RegExp = /\/api\/v1\//i
|
const URL_CASE_INSENSITIVE_REGEX: RegExp = /\/api\/v1\//i
|
||||||
const URL_CASE_SENSITIVE_REGEX: RegExp = /\/api\/v1\//
|
const URL_CASE_SENSITIVE_REGEX: RegExp = /\/api\/v1\//
|
||||||
|
|
||||||
|
|
@ -209,7 +210,7 @@ export class App {
|
||||||
// Step 2: Check if the req path is casesensitive
|
// Step 2: Check if the req path is casesensitive
|
||||||
if (URL_CASE_SENSITIVE_REGEX.test(req.path)) {
|
if (URL_CASE_SENSITIVE_REGEX.test(req.path)) {
|
||||||
// Step 3: Check if the req path is in the whitelist
|
// Step 3: Check if the req path is in the whitelist
|
||||||
const isWhitelisted = whitelistURLs.some((url) => req.path.startsWith(url))
|
const isWhitelisted = whitelistURLs.includes(req.path)
|
||||||
if (isWhitelisted) {
|
if (isWhitelisted) {
|
||||||
next()
|
next()
|
||||||
} else if (req.headers['x-request-from'] === 'internal') {
|
} else if (req.headers['x-request-from'] === 'internal') {
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue