#1850·linkwarden

远程浏览器 TOCTOU SSRF 和无限制的工作进程内存 DoS

作者: codeCraft-Ritik创建于 2026年9月28日更新于 2026年9月28日
标签bug

Overview

In apps/worker/lib/protectPageRequests.ts and apps/worker/lib/preservationScheme/handleScreenshotAndPdf.ts:

  1. Remote Browser TOCTOU/SSRF Rebinding: When running with PLAYWRIGHT_WS_URL (the standard Docker/production architecture for remote Chromium browsers), assertUrlIsSafeForServerSideFetch(request.url()) validates the URL on the Linkwarden worker host. Once validated, route.continue() instructs the remote Chromium instance to fetch the asset. Chromium performs its own DNS lookup. An attacker using DNS rebinding (low TTL DNS pointing to a public IP first, then resolving to 127.0.0.1 or 169.254.169.254) bypasses SSRF restrictions and accesses internal networks and cloud instance metadata.
  2. Worker Memory Exhaustion (OOM DoS): In local browser mode, all sub-resources on an archived page are intercepted and fetched via safeFetch, followed by await response.buffer(). There is no response size limit or streaming cap. Any webpage embedding large assets (such as multiple 4K videos or large binary blobs) forces the worker process to buffer hundreds of megabytes directly into Node.js heap memory, leading to JavaScript heap out of memory process crashes.
  3. Leaked Interval in autoScroll: In handleScreenshotAndPdf.ts, when timeoutPromise resolves in Promise.race([scrollingPromise, timeoutPromise]), clearInterval(scrollDown) is never called. The timer continues executing window.scrollBy every 100ms in the page background while screenshots and PDFs are actively captured, causing visual tearing and resource leakage.

Impact

  • Security: Private network and cloud metadata access via remote Playwright browser workers.
  • Reliability: Uncontrolled Node.js worker crashes resulting in stuck queues and unarchived links for all users.
  • Preservation Quality: Corrupted screenshots and fragmented PDF archives due to scrolling races during rendering.

Affected Files & Locations

  • apps/worker/lib/protectPageRequests.ts (Lines 27–65)
  • apps/worker/lib/preservationScheme/handleScreenshotAndPdf.ts (Lines 96–119)
typescript
// apps/worker/lib/protectPageRequests.ts
27: if (remoteBrowser) {
28:   try {
29:     await assertUrlIsSafeForServerSideFetch(request.url());
30:     await route.continue(); // ❌ TOCTOU: Remote browser re-resolves DNS independently!
31:   } catch (error) { ... }
...
45: const response = await safeFetch(request.url(), { ... });
...
56: await route.fulfill({
57:   status: response.status,
58:   headers: responseHeaders,
59:   body: await response.buffer(), // ❌ UNBOUNDED BUFFER: Can exhaust Node.js heap!
60: });
typescript
// apps/worker/lib/preservationScheme/handleScreenshotAndPdf.ts
96: const autoScroll = async (AUTOSCROLL_TIMEOUT: number) => {
97:   const timeoutPromise = new Promise<void>((resolve) => {
98:     setTimeout(() => resolve(), AUTOSCROLL_TIMEOUT * 1000);
99:   });
100:  const scrollingPromise = new Promise<void>((resolve) => {
...
106:
…

内容来源: linkwarden/linkwarden