From 569ba8bf2d164a9337783f0c5876b639290eee39 Mon Sep 17 00:00:00 2001 From: Jesse Wierzbinski Date: Fri, 22 Nov 2024 15:06:46 +0100 Subject: [PATCH] fix(api): :lock: Correctly put all URIs in profiles through proxy --- .../accounts/update_credentials/index.test.ts | 68 +++++++++++++++++++ classes/database/note.ts | 13 +--- utils/sanitization.ts | 10 +++ 3 files changed, 79 insertions(+), 12 deletions(-) create mode 100644 api/api/v1/accounts/update_credentials/index.test.ts diff --git a/api/api/v1/accounts/update_credentials/index.test.ts b/api/api/v1/accounts/update_credentials/index.test.ts new file mode 100644 index 00000000..9f9545f2 --- /dev/null +++ b/api/api/v1/accounts/update_credentials/index.test.ts @@ -0,0 +1,68 @@ +import { afterAll, describe, expect, test } from "bun:test"; +import type { Account as APIAccount } from "@versia/client/types"; +import { config } from "~/packages/config-manager/index.ts"; +import { fakeRequest, getTestUsers } from "~/tests/utils"; +import { meta } from "./index.ts"; + +const { tokens, deleteUsers } = await getTestUsers(1); + +afterAll(async () => { + await deleteUsers(); +}); + +// /api/v1/accounts/update_credentials +describe(meta.route, () => { + describe("HTML injection testing", () => { + test("should not allow HTML injection", async () => { + const response = await fakeRequest(meta.route, { + method: "PATCH", + headers: { + Authorization: `Bearer ${tokens[0].data.accessToken}`, + }, + body: new URLSearchParams({ + note: "Hi! ", + }), + }); + + expect(response.status).toBe(200); + expect(response.headers.get("content-type")).toContain( + "application/json", + ); + + const object = (await response.json()) as APIAccount; + + expect(object.note).toBe( + "

Hi! <script>alert('Hello, world!');</script>

\n", + ); + }); + + test("should rewrite all image and video src to go through proxy", async () => { + const response = await fakeRequest(meta.route, { + method: "PATCH", + headers: { + Authorization: `Bearer ${tokens[0].data.accessToken}`, + }, + body: new URLSearchParams({ + note: "