mirror of
https://github.com/wekan/wekan.git
synced 2026-11-24 18:10:06 -05:00
Admin Panel -> Settings -> Global Webhooks -> Internal destinations: the hosts on WeKan's own network - a Node-RED, a chat server, a Matrix hookshot - that outgoing webhooks may reach, one per line, a name or an address, with a port to allow only that port. Empty by default. Only site administrators read and change it, through methods, and it is never published, so a board member still can not point a webhook inward and the list does not describe the network to anyone else. A listed host is called directly without following redirects; every other address stays behind the SSRF guard, and the REST routes that save a webhook accept a listed host as well. The Node-RED how-to (#2017) says how. The new strings are translated in every locale. Thanks to xet7 !
45 lines
1.8 KiB
JavaScript
45 lines
1.8 KiB
JavaScript
// Admin Panel / Settings / Global Webhooks / Internal destinations
|
|
// (models/lib/internalWebhookHosts.js): the hosts on WeKan's own network that
|
|
// outgoing webhooks may reach. Site administrators only, never published: the
|
|
// list describes the internal network.
|
|
import { Meteor } from 'meteor/meteor';
|
|
import { check, Match } from 'meteor/check';
|
|
import Settings from '/models/settings';
|
|
|
|
const { cleanInternalHosts, isInternalHostAllowed } = require('/models/lib/internalWebhookHosts');
|
|
|
|
async function requireSiteAdmin(userId) {
|
|
const user = userId && await Meteor.users.findOneAsync(userId, { fields: { isAdmin: 1 } });
|
|
if (!user || user.isAdmin !== true) throw new Meteor.Error('not-authorized');
|
|
}
|
|
|
|
// A short cache: every webhook send asks.
|
|
let cached = { at: 0, hosts: [] };
|
|
export async function internalWebhookHosts() {
|
|
if (Date.now() - cached.at < 10000) return cached.hosts;
|
|
const setting = await Settings.findOneAsync({}, { fields: { webhookInternalHosts: 1 } });
|
|
cached = { at: Date.now(), hosts: cleanInternalHosts((setting && setting.webhookInternalHosts) || []).hosts };
|
|
return cached.hosts;
|
|
}
|
|
|
|
export async function webhookHostIsInternalAllowed(url) {
|
|
return isInternalHostAllowed(url, await internalWebhookHosts());
|
|
}
|
|
|
|
Meteor.methods({
|
|
async getWebhookInternalHosts() {
|
|
await requireSiteAdmin(this.userId);
|
|
return internalWebhookHosts();
|
|
},
|
|
async saveWebhookInternalHosts(input) {
|
|
check(input, Match.OneOf(String, [String]));
|
|
await requireSiteAdmin(this.userId);
|
|
const { hosts, rejected } = cleanInternalHosts(input);
|
|
const setting = await Settings.findOneAsync({});
|
|
if (!setting) throw new Meteor.Error('settings-not-found');
|
|
await Settings.updateAsync(setting._id, { $set: { webhookInternalHosts: hosts } });
|
|
cached = { at: 0, hosts: [] };
|
|
return { hosts, rejected };
|
|
},
|
|
});
|