From 75f3a0ed04672d05be29d63e0fe455bcf898c22f Mon Sep 17 00:00:00 2001 From: Nixyan Date: Wed, 11 Mar 2026 11:48:38 -0300 Subject: [PATCH] feat: enhance security and testing for federation routes. Added routes for uploading files to posts and initial logic of handling it client-side. - Added a new test suite for attack vectors targeting the /discover federation routes, ensuring (known) vulnerabilities are addressed. - Implemented a proxy function to check for blacklisted servers, enhancing security measures. - Introduced URL validation to prevent SSRF attacks by blocking internal addresses. - Updated package.json with a new test command for the attack tests. - Refactored server and route handling to improve type safety and error handling. - Added new middleware for blacklist checks and URL validation to prevent unauthorized access. --- package.json | 1 + playwright.config.ts | 8 - src/app/PostTestForm.tsx | 90 ++++ src/app/discover/rotate/confirm/route.ts | 132 +++-- src/app/discover/rotate/init/route.ts | 17 + src/app/discover/route.ts | 130 +++-- src/app/page.tsx | 3 +- src/lib/auth.ts | 11 +- src/lib/db/schema/index.ts | 34 +- src/lib/federation/blacklist-middleware.ts | 19 + src/lib/federation/url-guard.ts | 76 +++ src/lib/plugins/client/social.ts | 98 +++- .../server/helpers/social/endpoints/index.ts | 4 +- .../server/helpers/social/endpoints/posts.ts | 63 ++- .../plugins/server/helpers/social/social.ts | 4 + .../plugins/server/storage/minio.client.ts | 21 + src/proxy.ts | 49 ++ src/server.ts | 4 +- tests/attacks.test.ts | 459 ++++++++++++++++++ tests/helpers/db.ts | 15 +- 20 files changed, 1086 insertions(+), 152 deletions(-) create mode 100644 src/app/PostTestForm.tsx create mode 100644 src/lib/federation/blacklist-middleware.ts create mode 100644 src/lib/federation/url-guard.ts create mode 100644 src/lib/plugins/server/storage/minio.client.ts create mode 100644 src/proxy.ts create mode 100644 tests/attacks.test.ts diff --git a/package.json b/package.json index dc9f50c..612eea2 100644 --- a/package.json +++ b/package.json @@ -19,6 +19,7 @@ "keygen": "bun run src/lib/federation/keygen.ts", "test:key": "cross-env NODE_ENV=test playwright test tests/key.test.ts", "test:discover": "cross-env NODE_ENV=test playwright test tests/discover.test.ts", + "test:attacks": "cross-env NODE_ENV=test playwright test tests/attacks.test.ts", "build": "next build", "start": "cross-env NODE_ENV=production node src/server.ts", "db:push": "drizzle-kit push", diff --git a/playwright.config.ts b/playwright.config.ts index 7100f36..fe473a3 100644 --- a/playwright.config.ts +++ b/playwright.config.ts @@ -25,13 +25,5 @@ export default defineConfig({ name: 'chromium', use: { ...devices['Desktop Chrome'] }, }, - { - name: 'firefox', - use: { ...devices['Desktop Firefox'] }, - }, - { - name: 'webkit', - use: { ...devices['Desktop Safari'] }, - }, ], }); diff --git a/src/app/PostTestForm.tsx b/src/app/PostTestForm.tsx new file mode 100644 index 0000000..6fcbc8f --- /dev/null +++ b/src/app/PostTestForm.tsx @@ -0,0 +1,90 @@ +"use client"; + +import { authClient } from "@/lib/auth-client"; +import { useState } from "react"; + +export function PostTestForm() { + const [text, setText] = useState(""); + const [files, setFiles] = useState([]); + const [status, setStatus] = useState(null); + + const handleSubmit = async () => { + setStatus("Submitting..."); + try { + const content: { type: "text" | "image"; value: string | File }[] = []; + + if (text.trim()) { + content.push({ type: "text", value: text.trim() }); + } + + for (const file of files) { + content.push({ type: "image", value: file }); + } + + if (content.length === 0) { + setStatus("Add some text or images first."); + return; + } + + const result = await authClient.createPost(content); + setStatus(`Done: ${JSON.stringify(result)}`); + } catch (err) { + setStatus(`Error: ${err instanceof Error ? err.message : String(err)}`); + } + }; + + return ( +
+

Test Post

+ +