mirror of
https://github.com/wekan/wekan.git
synced 2026-11-25 04:49:41 -05:00
Two separately reported bypasses of the same defence, fixed together because they are the same mistake in the two halves of it: the guard decided from something it did not control. FollowBleed (GHSA-j9p2-jm73-p549, reported by RandomGenerator against v10.53) - the live Trello import validated the attachment URL with validateAttachmentUrl(), which is the fix that closed LiveBleed / CVE-2026-30844, and then downloaded it with the platform fetch(), which FOLLOWS REDIRECTS. So the guard only ever saw the request, and the target gets to answer: 1. the attacker puts http://<public-host>/attachment.txt on a Trello card 2. validateAttachmentUrl() resolves it, sees a public IP, allows it 3. that host answers 302 Location: http://127.0.0.1:18080/secret 4. fetch() follows, and the loopback body is stored as the imported attachment, readable back through WeKan Non-blind SSRF against loopback services, internal admin panels, cloud metadata and anything else reachable from the container - the exact thing the validation was added to stop, reached through the response instead of the request. A guard on the URL alone cannot hold, so fetchSafe() now guards EVERY HOP. `maxRedirects` (default 0) is how many redirects a caller is willing to follow: 0 keeps the old behaviour of refusing any 3xx outright, which is right for outgoing webhooks and avatar downloads because a legitimate one never redirects. A caller that must follow one passes a small number, and each hop goes through the same protocol allowlist, blocked-range check and DNS pinning as the original URL before a packet is sent to it. Credentials are dropped on a cross-origin redirect, so following Trello's 302 to S3 cannot hand the API key and token to whoever the redirect names. All three live-import sinks - downloadAttachmentBase64, inlineBoardBackground, inlineMemberAvatars - download through it. Refusing every redirect was not an option: Trello's own attachment endpoint answers with a 302 to a signed S3 URL, so that would have meant importing no attachments at all. The offline importers had the same hole and were not in the report. They handed the validated URL to Attachments.loadAsync(), and Meteor-Files downloads with the platform fetch() too, so a pasted Trello or WeKan board export reached 127.0.0.1 by exactly the same 302. models/lib/importAttachmentDownload.js validates, downloads through fetchSafe with every hop checked, and hands back the bytes, which are stored with the writeAsync() both importers already use for an attachment that arrived inline. TransitBleed (GHSA-c5xr-mg26-vq5w, reported by tonghuaroot) - isIpBlocked() in models/lib/attachmentUrlValidation.js is the one block-list behind BOTH the input-time validator and the delivery-time guard, and its IPv6 half classified an address by its spelling: startsWith('::ffff:'), startsWith('2001:db8'), and the first hextet parsed out of the string. IPv6 has several standard ways to write "this packet goes to an IPv4 address" and none of them looks like `::ffff:`: 2002:a9fe:a9fe:: 6to4 (RFC 3056) -> 169.254.169.254 64:ff9b::c0a8:101 NAT64 (RFC 6052) -> 192.168.1.1 2001:0:... Teredo (RFC 4380) -> complement of the low 32 bits 0:0:0:0:0:ffff:7f00:1 IPv4-mapped, spelled out -> 127.0.0.1 On a host with a 6to4 relay or a NAT64 gateway, which is ordinary in cloud and Kubernetes networks, the packet arrives at that IPv4 address. So http://[2002:a9fe:a9fe::]/latest/meta-data/ read cloud metadata straight through the guard whose whole job was to stop it, and even a plain IPv4-mapped address written out in full missed the check. The address is EXPANDED to its 16 bytes once and every check reads those bytes, so notation cannot change the answer, and every transition form has its embedded IPv4 extracted and re-checked with the IPv4 rules - 6to4, NAT64 (well-known and RFC 8215 local-use prefixes), Teredo through both its server and its obfuscated client address, IPv4-mapped, IPv4-translated, IPv4-compatible and ISATAP under any routing prefix, not only the link-local one. The deprecated fec0::/10 site-local range is blocked too. A transition address wrapping a PUBLIC IPv4 is still allowed, because a guard that blocks everything gets switched off. Tests. tests/followbleed.test.cjs replays the reported attack against a stubbed transport - a public host that 302s to 127.0.0.1 - and asserts the second hop is never sent, then covers redirects to a hostname resolving to a private IP, to metadata, to a non-http scheme, relative Location, the chain limit, credential stripping across origins, 303/307 method handling, and that a legitimate public-to-public redirect is still followed with each hop pinned. It also pins the sinks: the only bare fetch() left in the live import is the hardcoded api.trello.com call, and neither offline importer uses loadAsync any more. tests/transitbleed.test.cjs checks every transition form in both directions. Both are in the plain-node suite; the guard's own dnsbleed suite gained the same cases. 300 node suites pass. Thanks to RandomGenerator and tonghuaroot for the coordinated disclosures, and xet7 !
72 lines
3.0 KiB
JavaScript
72 lines
3.0 KiB
JavaScript
/**
|
|
* models/lib/importAttachmentDownload.js — downloading an attachment that an
|
|
* IMPORTED BOARD FILE named, safely.
|
|
*
|
|
* An imported board (a Trello export, a WeKan export) can give an attachment a
|
|
* `url` instead of inline bytes, and whoever wrote that file chose the URL. The
|
|
* response is stored as an attachment and can be read back through WeKan, so an
|
|
* unguarded download here is a non-blind SSRF — the issue fixed as
|
|
* CVE-2026-30844, and again as LiveBleed for the live Trello import.
|
|
*
|
|
* Validating the URL is not enough on its own. The importers called
|
|
* `Attachments.loadAsync(url)`, and Meteor-Files downloads with the platform
|
|
* `fetch()`, which FOLLOWS REDIRECTS: a public URL that passes validation can
|
|
* answer `302 Location: http://127.0.0.1:.../secret` and the loopback body is
|
|
* what gets stored. That is FollowBleed (GHSA-j9p2-jm73-p549), reported against
|
|
* the live import; the offline importers reached the same end through
|
|
* Meteor-Files.
|
|
*
|
|
* So the download happens here instead, through fetchSafe: the URL is validated
|
|
* at input time, then EVERY hop — the original and each redirect — is validated
|
|
* and DNS-pinned before a packet is sent to it. The bytes come back to the
|
|
* caller, which stores them with the same writeAsync() it already uses for an
|
|
* attachment that arrived inline.
|
|
*/
|
|
|
|
import { validateAttachmentUrl } from './attachmentUrlValidation';
|
|
|
|
// Trello and S3 style download URLs legitimately redirect once or twice (to a
|
|
// signed URL, to a CDN). Each hop is validated, so following a few is safe;
|
|
// the limit only stops a redirect loop.
|
|
const MAX_IMPORT_REDIRECTS = 5;
|
|
|
|
/**
|
|
* Fetch an attachment URL named by an imported board.
|
|
*
|
|
* @param {string} url
|
|
* @returns {Promise<{blocked: true, reason: string} | {buffer: Buffer, type: string|null}>}
|
|
* `blocked` when the URL — or a redirect it answered with — is not allowed to
|
|
* be contacted; the caller skips that one attachment. Throws on an ordinary
|
|
* download failure (HTTP error, network), which callers already treat as
|
|
* "skip this attachment".
|
|
*/
|
|
export async function fetchImportedAttachment(url) {
|
|
const validation = await validateAttachmentUrl(url);
|
|
if (!validation.valid) {
|
|
return { blocked: true, reason: validation.reason };
|
|
}
|
|
|
|
// Server-only, and required lazily so that importing this module from the
|
|
// isomorphic models/ tree does not pull the guard into the client bundle.
|
|
const { fetchSafe } = require('/server/lib/ssrfGuard');
|
|
|
|
let res;
|
|
try {
|
|
res = await fetchSafe(url, { maxRedirects: MAX_IMPORT_REDIRECTS });
|
|
} catch (error) {
|
|
const message = (error && error.message) || 'download failed';
|
|
if (/^SSRF_GUARD:/.test(message)) {
|
|
return { blocked: true, reason: message };
|
|
}
|
|
throw error;
|
|
}
|
|
|
|
if (!res.ok) {
|
|
throw new Error(`HTTP ${res.status}`);
|
|
}
|
|
|
|
const type =
|
|
((res.headers && res.headers.get('content-type')) || '').split(';')[0].trim() || null;
|
|
return { buffer: Buffer.from(await res.arrayBuffer()), type };
|
|
}
|