mirror of
https://github.com/Abdulazizzn/n8n-enterprise-unlocked.git
synced 2025-12-17 18:12:04 +00:00
feat(core): Add Support for custom CORS origins for webhooks (#7455)
node-850 https://community.n8n.io/t/add-ability-to-set-cors-allow-list-in-n8n-webhooks/7610 https://community.n8n.io/t/configure-cors-pre-flight-request-option-method-in-the-roadmap/32189 --------- Co-authored-by: कारतोफ्फेलस्क्रिप्ट™ <aditya@netroy.in>
This commit is contained in:
@@ -98,7 +98,28 @@ export const webhookRequestHandler =
|
||||
return ResponseHelper.sendErrorResponse(res, error as Error);
|
||||
}
|
||||
}
|
||||
res.header('Access-Control-Allow-Origin', req.headers.origin);
|
||||
|
||||
const requestedMethod =
|
||||
method === 'OPTIONS'
|
||||
? (req.headers['access-control-request-method'] as IHttpRequestMethods)
|
||||
: method;
|
||||
if (webhookManager.findAccessControlOptions && requestedMethod) {
|
||||
const options = await webhookManager.findAccessControlOptions(path, requestedMethod);
|
||||
const { allowedOrigins } = options ?? {};
|
||||
|
||||
res.header(
|
||||
'Access-Control-Allow-Origin',
|
||||
!allowedOrigins || allowedOrigins === '*' ? req.headers.origin : allowedOrigins,
|
||||
);
|
||||
|
||||
if (method === 'OPTIONS') {
|
||||
res.header('Access-Control-Max-Age', '300');
|
||||
const requestedHeaders = req.headers['access-control-request-headers'];
|
||||
if (requestedHeaders?.length) {
|
||||
res.header('Access-Control-Allow-Headers', requestedHeaders);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (method === 'OPTIONS') {
|
||||
|
||||
Reference in New Issue
Block a user