mirror of
https://github.com/Abdulazizzn/n8n-enterprise-unlocked.git
synced 2025-12-22 12:19:09 +00:00
feat: Add option to restrict credential usage in http request node (#17583)
This commit is contained in:
@@ -358,3 +358,43 @@ export function setSafeObjectProperty(
|
||||
target[property] = value;
|
||||
}
|
||||
}
|
||||
|
||||
export function isDomainAllowed(
|
||||
urlString: string,
|
||||
options: {
|
||||
allowedDomains: string;
|
||||
},
|
||||
): boolean {
|
||||
if (!options.allowedDomains || options.allowedDomains.trim() === '') {
|
||||
return true; // If no restrictions are set, allow all domains
|
||||
}
|
||||
|
||||
try {
|
||||
const url = new URL(urlString);
|
||||
const hostname = url.hostname;
|
||||
|
||||
const allowedDomainsList = options.allowedDomains
|
||||
.split(',')
|
||||
.map((domain) => domain.trim())
|
||||
.filter(Boolean);
|
||||
|
||||
for (const allowedDomain of allowedDomainsList) {
|
||||
// Handle wildcard domains (*.example.com)
|
||||
if (allowedDomain.startsWith('*.')) {
|
||||
const domainSuffix = allowedDomain.substring(2); // Remove the *. part
|
||||
if (hostname.endsWith(domainSuffix)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
// Exact match
|
||||
else if (hostname === allowedDomain) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
} catch (error) {
|
||||
// If URL parsing fails, deny access to be safe
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user