Files
wekan/server/models/integrations.js
T
Lauri Ojansivu ebcd02be6f Hall of Fame regression audit: every fixed vulnerability still fixed, siblings of six of them closed.
Every Hall of Fame vulnerability without a test naming it (24 names, 30
advisories) was checked against the current source. No fix had been
reverted. Looking for the same mistake elsewhere found siblings:

- FloppyBleed: the fs-path-heal upgrade step joined an attachment's
  stored name into candidate paths as-is; a record a client inserted
  named ../../../etc/passwd made the next upgrade copy that file into
  storage - an arbitrary file read. Only the name's last component is
  used now; the bulk move limits a legacy name's extension the same way.
- FilePathBleed (GHSA-g6vm-7757-pr88): the insert guard looked only
  inside versions; with versions left out ostrio:files falls back to a
  top-level path, which removing the record deletes and validation
  reads. A client's top-level path is refused for attachments and
  avatars, recorded by the existing canaries.
- MoveStorageBleed: validateAttachment, which deletes a file failing the
  current upload rules, was open to anybody who could see the board, a
  public one included. Only who may change the file, or a site admin,
  validates now; a refusal is recorded (authz.attachment-validate).
- HookUrlBleed / IntegrationBleed: the REST reads of a board's
  integrations gave the webhook URL - whose path is its secret - to
  every member reading the board; non-admins get what the publication
  gives them.
- AttachmentMigrationBleed: four migration methods answered any
  logged-in user about any board, deleteDuplicateEmptyLists.getStatus
  with a private board's list titles; they require a visible board and
  record refusals (authz.migration-board).
- LegacyAttachBleed (GHSA-xcxp-hx9w-q5q9) and MimeStorageBleed
  (GHSA-rv5g-5p4g-3v89): the legacy route judged a name dangerous only
  for .svg, the response policy missed x-javascript, ecmascript, xsl and
  +xml types, and the sniffers missed <tag/onx= handlers.

OIDCBleed refusals are now recorded in Admin Panel / Problems too. New
suites name the vulnerabilities they guard, existing ones name the
advisories they already covered, and tests/securityRegressionCoverage
counts 128 of 137 published vulnerabilities with a named test (was 125).

Thanks to xet7 !
2026-10-27 16:28:12 +02:00

264 lines
9.1 KiB
JavaScript

import { Meteor } from 'meteor/meteor';
import { WebApp } from 'meteor/webapp';
import { Authentication } from '/server/authentication';
import { sendJsonResult } from '/server/apiMiddleware';
import { ReactiveCache } from '/imports/reactiveCache';
import Integrations from '/models/integrations';
import { validateAttachmentUrl } from '/models/lib/attachmentUrlValidation';
import { ensureIndex } from '/server/lib/mongoStartup';
const { normalizeDeliverySettings } = require('/models/lib/notificationDelivery');
// ErrorBleed: refusals answer with their real status and a safe message.
const { publicErrorData } = require('/server/lib/apiResponseHelpers');
Meteor.startup(async () => {
await ensureIndex(Integrations, { modifiedAt: -1 });
await ensureIndex(Integrations, { boardId: 1 });
});
// HookUrlBleed, REST sibling (IntegrationBleed area): the board publication
// sends an integration's URL to the board's admins only, because a
// Slack/Mattermost/Teams incoming-webhook URL carries its secret in the path
// (tests/webhookUrlPublication.test.cjs). These two REST reads let any member
// who reads the whole board - read-only and comment-only members included -
// receive that same URL. Board admins and site admins still get everything but
// the token; everybody else gets exactly what the publication gives them. Not
// recorded in Admin Panel -> Problems: an API client of an ordinary member
// reaches this in normal use, so it is not an attempt.
async function integrationFieldsFor(userId, boardId) {
const board = await ReactiveCache.getBoard(boardId);
const boardAdmin = ((board && board.members) || []).some(
m => m.userId === userId && m.isActive && m.isAdmin,
);
const siteAdmin = !boardAdmin && !!(await ReactiveCache.getUser({ _id: userId, isAdmin: true }));
return boardAdmin || siteAdmin ? { token: 0 } : { boardId: 1, enabled: 1, activities: 1 };
}
WebApp.handlers.get('/api/boards/:boardId/integrations', async function(req, res) {
try {
const paramBoardId = req.params.boardId;
await Authentication.checkBoardAccess(req.userId, paramBoardId);
const fields = await integrationFieldsFor(req.userId, paramBoardId);
const data = (await ReactiveCache.getIntegrations(
{ boardId: paramBoardId },
{ fields },
)).map(function(doc) {
return doc;
});
sendJsonResult(res, { code: 200, data });
} catch (error) {
sendJsonResult(res, publicErrorData(error));
}
});
WebApp.handlers.get('/api/boards/:boardId/integrations/:intId', async function(req, res) {
try {
const paramBoardId = req.params.boardId;
const paramIntId = req.params.intId;
await Authentication.checkBoardAccess(req.userId, paramBoardId);
const fields = await integrationFieldsFor(req.userId, paramBoardId);
sendJsonResult(res, {
code: 200,
data: await ReactiveCache.getIntegration(
{ _id: paramIntId, boardId: paramBoardId },
{ fields },
),
});
} catch (error) {
sendJsonResult(res, publicErrorData(error));
}
});
WebApp.handlers.post('/api/boards/:boardId/integrations', async function(req, res) {
try {
const paramBoardId = req.params.boardId;
await Authentication.checkBoardAdmin(req.userId, paramBoardId);
// SSRF protection: block webhook URLs that resolve to private/loopback/
// link-local addresses (e.g. cloud metadata at 169.254.169.254) before the
// URL is ever stored and delivered server-side. See GHSA-hc3x-hq3m-663q.
// ...unless a site admin listed it as an internal destination.
const validation = (await require('/server/webhookInternalHosts').webhookHostIsInternalAllowed(req.body.url))
? { valid: true } : await validateAttachmentUrl(req.body.url);
if (!validation.valid) {
sendJsonResult(res, {
code: 400,
data: { error: 'invalid-webhook-url', reason: validation.reason },
});
return;
}
const id = await Integrations.insertAsync({
userId: req.userId,
boardId: paramBoardId,
url: req.body.url,
});
sendJsonResult(res, {
code: 200,
data: {
_id: id,
},
});
} catch (error) {
sendJsonResult(res, publicErrorData(error));
}
});
WebApp.handlers.put('/api/boards/:boardId/integrations/:intId', async function(req, res) {
try {
const paramBoardId = req.params.boardId;
const paramIntId = req.params.intId;
await Authentication.checkBoardAdmin(req.userId, paramBoardId);
// #3695: how this webhook delivers - { webhook: { text, fields, grouping,
// schedule, ... } }, or null to inherit the board / Admin Panel default
// (models/lib/notificationDelivery.js). Validated before ANY field is
// written, so a refused request changes nothing.
let notificationDelivery;
if (req.body.hasOwnProperty('notificationDelivery')) {
try {
notificationDelivery = normalizeDeliverySettings(req.body.notificationDelivery, ['webhook']);
} catch (e) {
sendJsonResult(res, {
code: 400,
data: { error: 'invalid-notification-delivery', reason: e.message },
});
return;
}
}
if (req.body.hasOwnProperty('enabled')) {
await Integrations.direct.updateAsync(
{ _id: paramIntId, boardId: paramBoardId },
{ $set: { enabled: req.body.enabled } },
);
}
if (req.body.hasOwnProperty('title')) {
await Integrations.direct.updateAsync(
{ _id: paramIntId, boardId: paramBoardId },
{ $set: { title: req.body.title } },
);
}
if (req.body.hasOwnProperty('url')) {
// SSRF protection: this update path uses Integrations.direct, which
// bypasses the schema's url validator, so validate explicitly here.
// See GHSA-hc3x-hq3m-663q.
const validation = (await require('/server/webhookInternalHosts').webhookHostIsInternalAllowed(req.body.url))
? { valid: true } : await validateAttachmentUrl(req.body.url);
if (!validation.valid) {
sendJsonResult(res, {
code: 400,
data: { error: 'invalid-webhook-url', reason: validation.reason },
});
return;
}
await Integrations.direct.updateAsync(
{ _id: paramIntId, boardId: paramBoardId },
{ $set: { url: req.body.url } },
);
}
if (req.body.hasOwnProperty('token')) {
await Integrations.direct.updateAsync(
{ _id: paramIntId, boardId: paramBoardId },
{ $set: { token: req.body.token } },
);
}
if (req.body.hasOwnProperty('notificationDelivery')) {
await Integrations.direct.updateAsync(
{ _id: paramIntId, boardId: paramBoardId },
notificationDelivery ? { $set: { notificationDelivery } } : { $unset: { notificationDelivery: '' } },
);
}
if (req.body.hasOwnProperty('activities')) {
await Integrations.direct.updateAsync(
{ _id: paramIntId, boardId: paramBoardId },
{ $set: { activities: req.body.activities } },
);
}
sendJsonResult(res, {
code: 200,
data: {
_id: paramIntId,
},
});
} catch (error) {
sendJsonResult(res, publicErrorData(error));
}
});
WebApp.handlers.delete(
'/api/boards/:boardId/integrations/:intId/activities',
async function(req, res) {
try {
const paramBoardId = req.params.boardId;
const paramIntId = req.params.intId;
const newActivities = req.body.activities;
await Authentication.checkBoardAdmin(req.userId, paramBoardId);
await Integrations.direct.updateAsync(
{ _id: paramIntId, boardId: paramBoardId },
{ $pullAll: { activities: newActivities } },
);
sendJsonResult(res, {
code: 200,
data: await ReactiveCache.getIntegration(
{ _id: paramIntId, boardId: paramBoardId },
{ fields: { _id: 1, activities: 1 } },
),
});
} catch (error) {
sendJsonResult(res, publicErrorData(error));
}
},
);
WebApp.handlers.post(
'/api/boards/:boardId/integrations/:intId/activities',
async function(req, res) {
try {
const paramBoardId = req.params.boardId;
const paramIntId = req.params.intId;
const newActivities = req.body.activities;
await Authentication.checkBoardAdmin(req.userId, paramBoardId);
await Integrations.direct.updateAsync(
{ _id: paramIntId, boardId: paramBoardId },
{ $addToSet: { activities: { $each: newActivities } } },
);
sendJsonResult(res, {
code: 200,
data: await ReactiveCache.getIntegration(
{ _id: paramIntId, boardId: paramBoardId },
{ fields: { _id: 1, activities: 1 } },
),
});
} catch (error) {
sendJsonResult(res, publicErrorData(error));
}
},
);
WebApp.handlers.delete('/api/boards/:boardId/integrations/:intId', async function(req, res) {
try {
const paramBoardId = req.params.boardId;
const paramIntId = req.params.intId;
await Authentication.checkBoardAdmin(req.userId, paramBoardId);
await Integrations.direct.removeAsync({ _id: paramIntId, boardId: paramBoardId });
sendJsonResult(res, {
code: 200,
data: {
_id: paramIntId,
},
});
} catch (error) {
sendJsonResult(res, publicErrorData(error));
}
});