This commit is contained in:
Stefan Lazic committed 2026-08-04 09:57:58 +01:00
1 parent 546613e677
commit 4785510144
82 files changed
+4903 -287

No files matched your search

@@ -0,0 +1,28 @@
import { describe, expect, it } from "vitest";
import { safeRedirectPath } from "../safe-redirect";
describe("safeRedirectPath", () => {
it("accepts a plain internal path", () => {
expect(safeRedirectPath("/book/details", "/home")).toBe("/book/details");
});
it("falls back for null/undefined/empty input", () => {
expect(safeRedirectPath(null, "/home")).toBe("/home");
expect(safeRedirectPath(undefined, "/home")).toBe("/home");
expect(safeRedirectPath("", "/home")).toBe("/home");
});
it("rejects protocol-relative URLs", () => {
expect(safeRedirectPath("//evil.com", "/home")).toBe("/home");
});
it("rejects absolute URLs to another host", () => {
expect(safeRedirectPath("https://evil.com/phish", "/home")).toBe("/home");
expect(safeRedirectPath("http://evil.com", "/home")).toBe("/home");
});
it("rejects a path not starting with a single slash", () => {
expect(safeRedirectPath("book/details", "/home")).toBe("/home");
expect(safeRedirectPath("javascript:alert(1)", "/home")).toBe("/home");
});
});