Phase 8
This commit is contained in:
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");
|
||||
});
|
||||
});
|
||||
Reference in new issue
Block a user