fix: clean up request interceptor in recyclePage to prevent pool contamination
All checks were successful
Build & Deploy to Staging / Build & Deploy to Staging (push) Successful in 13m17s

When renderUrlPdf() sets up request interception for SSRF DNS pinning,
the interceptor and event listener were never cleaned up in recyclePage().
This could cause subsequent HTML-to-PDF conversions on the same pooled
page to have external resources blocked by the stale interceptor.

- Export recyclePage for testability
- Add removeAllListeners('request') + setRequestInterception(false)
- Add browser-recycle.test.ts with TDD (red→green verified)

Tests: 443 passing (was 442)
This commit is contained in:
DocFast CEO 2026-03-02 17:05:45 +01:00
parent b05bd44432
commit 024fa0084d
2 changed files with 62 additions and 1 deletions

View file

@ -40,11 +40,14 @@ export function getPoolStats() {
};
}
async function recyclePage(page: Page): Promise<void> {
export async function recyclePage(page: Page): Promise<void> {
try {
const client = await page.createCDPSession();
await client.send("Network.clearBrowserCache").catch(() => {});
await client.detach().catch(() => {});
// Clean up request interception (set by renderUrlPdf for SSRF protection)
page.removeAllListeners("request");
await page.setRequestInterception(false).catch(() => {});
const cookies = await page.cookies();
if (cookies.length > 0) {
await page.deleteCookie(...cookies);