Fix web services with a whiteList including a path component

https://github.com/samuelthomas2774/nxapi/issues/92
This commit is contained in:
Samuel Elliott 2023-11-16 23:41:47 +00:00
parent 58413a0024
commit f35f2ab549
No known key found for this signature in database
GPG Key ID: 8420C7CDE43DC4D6

View File

@ -143,7 +143,12 @@ function isWebServiceUrlAllowed(webservice: WebService, url: string | URL) {
if (typeof url === 'string') url = new URL(url);
for (const host of webservice.whiteList) {
for (const allowed of webservice.whiteList) {
const host = allowed.includes('/') ? allowed.substr(0, allowed.indexOf('/')) : allowed;
const path = allowed.includes('/') ? allowed.substr(allowed.indexOf('/')) : null;
if (path && url.pathname !== path && !url.pathname.startsWith(path + '/')) continue;
if (host.startsWith('*.')) {
if (url.hostname === host.substr(2) ||
url.hostname.endsWith(host.substr(1))