Skip to content

⚡️⚡️⚡️ Self-hosted collaborative bookmark manager to collect, read, annotate, and fully preserve what matters, all in one place.

bug fix

daniel31x13b3ba2efde065
diff --git a/apps/worker/lib/protectPageRequests.ts b/apps/worker/lib/protectPageRequests.ts
index e78b97d8..29f9cad9 100644
--- a/apps/worker/lib/protectPageRequests.ts
+++ b/apps/worker/lib/protectPageRequests.ts
@@ -1,5 +1,8 @@
import { BrowserContext, Route } from "playwright";
-import { UnsafeUrlError } from "@linkwarden/lib/ssrf";
+import {
+ assertUrlIsSafeForServerSideFetch,
+ UnsafeUrlError,
+} from "@linkwarden/lib/ssrf";
import { safeFetch } from "@linkwarden/lib/safeFetch";
function isNonNetworkUrl(url: string) {
@@ -11,6 +14,8 @@ function isNonNetworkUrl(url: string) {
}
export default async function protectPageRequests(context: BrowserContext) {
+ const remoteBrowser = Boolean(process.env.PLAYWRIGHT_WS_URL);
+
await context.route("**/*", async (route: Route) => {
const request = route.request();
@@ -19,6 +24,18 @@ export default async function protectPageRequests(context: BrowserContext) {
return;
}
+ if (remoteBrowser) {
+ try {
+ await assertUrlIsSafeForServerSideFetch(request.url());
+ await route.continue();
+ } catch (error) {
+ await route.abort(
+ error instanceof UnsafeUrlError ? "blockedbyclient" : "failed"
+ );
+ }
+ return;
+ }
+
try {
const headers = request.headers();
delete headers["accept-encoding"];
diff --git a/apps/worker/workers/linkProcessing.ts b/apps/worker/workers/linkProcessing.ts
index fc2f38be..550d234c 100644
--- a/apps/worker/workers/linkProcessing.ts
+++ b/apps/worker/workers/linkProcessing.ts
@@ -17,6 +17,11 @@ const BROWSER_IDLE_TIMEOUT_MS = 60_000;
// Blue console output
const logInfo = (message: string) => console.log("\x1b[34m%s\x1b[0m", message);
+const launchingMessage = () =>
+ process.env.PLAYWRIGHT_WS_URL
+ ? `Connecting to remote browser (${process.env.PLAYWRIGHT_WS_URL}).`
+ : "Launching browser.";
+
export async function linkProcessing(interval = 10) {
logInfo("Starting link processing...");
@@ -119,7 +124,7 @@ async function linkProcessingOnDemand(interval: number) {
}
}
- logInfo("Launching browser.");
+ logInfo(launchingMessage());
browser = await launchBrowser();
browserStartTs = Date.now();
return browser;