From 0b7253bb0caa3f5a51365ca0557681796c2aa264 Mon Sep 17 00:00:00 2001 From: Tom Moor Date: Mon, 16 Oct 2023 19:27:20 -0400 Subject: [PATCH] fix: Tighten valiation around URLs in database fields closes #6012 --- server/models/User.test.ts | 22 ++++++++++++++++++++++ server/models/validators/NotContainsUrl.ts | 2 +- 2 files changed, 23 insertions(+), 1 deletion(-) diff --git a/server/models/User.test.ts b/server/models/User.test.ts index fc82c772e4..5e0c378ad7 100644 --- a/server/models/User.test.ts +++ b/server/models/User.test.ts @@ -13,6 +13,28 @@ afterAll(() => { }); describe("user model", () => { + describe("create", () => { + it("should not allow URLs in name", async () => { + await expect( + buildUser({ + name: "www.google.com", + }) + ).rejects.toThrowError(); + + await expect( + buildUser({ + name: "My name https://malicious.com", + }) + ).rejects.toThrowError(); + + await expect( + buildUser({ + name: "wwwww", + }) + ).resolves.toBeDefined(); + }); + }); + describe("destroy", () => { it("should delete user authentications", async () => { const user = await buildUser(); diff --git a/server/models/validators/NotContainsUrl.ts b/server/models/validators/NotContainsUrl.ts index 63b9aad36e..fffbd0a8df 100644 --- a/server/models/validators/NotContainsUrl.ts +++ b/server/models/validators/NotContainsUrl.ts @@ -8,7 +8,7 @@ export default function NotContainsUrl(target: any, propertyName: string) { return addAttributeOptions(target, propertyName, { validate: { not: { - args: /(www|file:|http:|https:)+[^\s]+[\w]/, + args: /(www\.|file:|http:|https:)[^\s]+[\w]/, msg: "Must not contain a URL", }, },