mirror of
https://github.com/wekan/wekan.git
synced 2026-11-24 18:10:06 -05:00
34 schema files wrote the same two autoValue functions out by hand, 65 times in five spellings: createdAt set on insert and $setOnInsert on upsert, unset otherwise; modifiedAt set on every write. They are now createdAtAutoValue and modifiedAtAutoValue in models/lib/schemaTimestamps.js, named by each field as `autoValue: createdAtAutoValue`. models/settings.js, which may not use import statements, requires them. Schemas whose rule differs keep their own: changeHistory keeps a createdAt the caller set, and listSyncCredentials' updatedAt does not unset. tests/schemaTimestamps runs both functions in SimpleSchema's insert, upsert, update and validation contexts, and fails when a schema writes either one out by hand again. Thanks to xet7 !
160 lines
4.7 KiB
JavaScript
160 lines
4.7 KiB
JavaScript
import { Meteor } from 'meteor/meteor';
|
|
import { Mongo } from 'meteor/mongo';
|
|
import { ReactiveCache } from '/imports/reactiveCache';
|
|
import { createdAtAutoValue, modifiedAtAutoValue } from '/models/lib/schemaTimestamps';
|
|
const { SimpleSchema } = require('/imports/simpleSchema');
|
|
const { deliverySchemaFields } = require('/models/lib/notificationDelivery');
|
|
|
|
const Integrations = new Mongo.Collection('integrations');
|
|
|
|
/**
|
|
* Integration with third-party applications
|
|
*/
|
|
Integrations.attachSchema(
|
|
new SimpleSchema({
|
|
enabled: {
|
|
/**
|
|
* is the integration enabled?
|
|
*/
|
|
type: Boolean,
|
|
defaultValue: true,
|
|
},
|
|
title: {
|
|
/**
|
|
* name of the integration
|
|
*/
|
|
type: String,
|
|
optional: true,
|
|
},
|
|
type: {
|
|
/**
|
|
* type of the integratation (Default to 'outgoing-webhooks')
|
|
*/
|
|
type: String,
|
|
defaultValue: 'outgoing-webhooks',
|
|
},
|
|
activities: {
|
|
/**
|
|
* activities the integration gets triggered (list)
|
|
*/
|
|
type: Array,
|
|
defaultValue: ['all'],
|
|
},
|
|
'activities.$': {
|
|
type: String,
|
|
},
|
|
url: {
|
|
/**
|
|
* First-line, NON-AUTHORITATIVE SSRF check.
|
|
*
|
|
* This validator runs synchronously (isomorphically) and therefore CANNOT
|
|
* resolve DNS. It only rejects the obvious cases (bad protocol, literal
|
|
* private/loopback IPs, localhost) to give quick feedback in the UI. It is
|
|
* trivially bypassed by a public hostname that resolves to an internal IP
|
|
* (e.g. 169-254-169-254.nip.io), so it MUST NOT be relied on as the SSRF
|
|
* boundary — that was the root cause of GHSA-66m2-4wfr-c45p (DnsBleed).
|
|
*
|
|
* The authoritative, DNS-aware checks live server-side and validate the
|
|
* RESOLVED IP of every address family:
|
|
* - input time: validateAttachmentUrl() at the REST write paths
|
|
* (server/models/integrations.js POST/PUT), and
|
|
* - delivery time: fetchSafe() (server/lib/ssrfGuard.js), which resolves
|
|
* once, pins the connection to the validated IP and blocks redirects.
|
|
*/
|
|
type: String,
|
|
custom() {
|
|
try {
|
|
const u = new URL(this.value);
|
|
|
|
// Only allow http and https protocols
|
|
if (!['http:', 'https:'].includes(u.protocol)) {
|
|
return 'invalidProtocol';
|
|
}
|
|
|
|
// Block private/loopback IP ranges and hostnames
|
|
const hostname = u.hostname.toLowerCase();
|
|
const blockedPatterns = [
|
|
/^127\./, // 127.x.x.x (loopback)
|
|
/^10\./, // 10.x.x.x (private)
|
|
/^172\.(1[6-9]|2\d|3[01])\./, // 172.16-31.x.x (private)
|
|
/^192\.168\./, // 192.168.x.x (private)
|
|
/^0\./, // 0.x.x.x (current network)
|
|
/^::1$/, // IPv6 loopback
|
|
/^fe80:/, // IPv6 link-local
|
|
/^fc00:/, // IPv6 unique local
|
|
/^fd00:/, // IPv6 unique local
|
|
/^localhost$/i,
|
|
/\.local$/i,
|
|
/^169\.254\./, // link-local IP
|
|
];
|
|
|
|
if (blockedPatterns.some(pattern => pattern.test(hostname))) {
|
|
return 'privateAddress';
|
|
}
|
|
} catch {
|
|
return 'invalidUrl';
|
|
}
|
|
},
|
|
},
|
|
// #3695: how this webhook delivers - content, grouping, schedule. Unset keys
|
|
// inherit the board's default (board webhooks), then the Admin Panel's.
|
|
// See models/lib/notificationDelivery.js.
|
|
...deliverySchemaFields('notificationDelivery', ['webhook']),
|
|
token: {
|
|
/**
|
|
* token of the integration
|
|
*/
|
|
type: String,
|
|
optional: true,
|
|
},
|
|
boardId: {
|
|
/**
|
|
* Board ID of the integration
|
|
*/
|
|
type: String,
|
|
},
|
|
createdAt: {
|
|
/**
|
|
* Creation date of the integration
|
|
*/
|
|
type: Date,
|
|
autoValue: createdAtAutoValue,
|
|
},
|
|
modifiedAt: {
|
|
type: Date,
|
|
autoValue: modifiedAtAutoValue,
|
|
},
|
|
userId: {
|
|
/**
|
|
* user ID who created the interation
|
|
*/
|
|
type: String,
|
|
},
|
|
mattermostDirectMessages: {
|
|
/**
|
|
* #1297: also send each message to the card's members and assignees as
|
|
* Mattermost direct messages (models/lib/mattermostDirectMessages.js).
|
|
*/
|
|
type: Boolean,
|
|
optional: true,
|
|
},
|
|
bot: {
|
|
/**
|
|
* Board Settings / Bots (models/lib/botRuns.js): this outgoing webhook
|
|
* is a bot's runner. It is sent dispatches only, never board activity.
|
|
*/
|
|
type: Boolean,
|
|
optional: true,
|
|
},
|
|
}),
|
|
);
|
|
Integrations.Const = {
|
|
GLOBAL_WEBHOOK_ID: '_global',
|
|
ONEWAY: 'outgoing-webhooks',
|
|
TWOWAY: 'bidirectional-webhooks',
|
|
get WEBHOOK_TYPES() {
|
|
return [this.ONEWAY, this.TWOWAY];
|
|
},
|
|
};
|
|
export default Integrations;
|