Skip to content

armgit / kaneo

Public Imported from GitHub
0

⚡ Project management that doesn't become the project. Boards, Gantt charts, and GitHub integration. Self-host it or use Kaneo Cloud.

fix(web): avoid crypto.randomUUID on plain-HTTP origins

man-singh-devcd4313c10937
diff --git a/apps/web/src/components/project/gitea-integration/gitea-repository-picker.test.tsx b/apps/web/src/components/project/gitea-integration/gitea-repository-picker.test.tsx
index 39ec8cc3c..5157be1da 100644
--- a/apps/web/src/components/project/gitea-integration/gitea-repository-picker.test.tsx
+++ b/apps/web/src/components/project/gitea-integration/gitea-repository-picker.test.tsx
@@ -133,6 +133,22 @@ describe("Gitea repository credential isolation", () => {
expect(screen.queryByText("owner/new-session-repo")).toBeNull();
});
+ it("loads repositories on plain-HTTP origins without crypto.randomUUID", async () => {
+ const original = Object.getOwnPropertyDescriptor(crypto, "randomUUID");
+ Object.defineProperty(crypto, "randomUUID", {
+ value: undefined,
+ configurable: true,
+ });
+ try {
+ m.list.mockResolvedValueOnce(result("lan-repo"));
+ show();
+ await screen.findByText("owner/lan-repo");
+ } finally {
+ if (original) Object.defineProperty(crypto, "randomUUID", original);
+ else delete (crypto as { randomUUID?: unknown }).randomUUID;
+ }
+ });
+
it("filters the loaded repositories and uses the confirmed selection", async () => {
m.list.mockResolvedValueOnce({
repositories: [
diff --git a/apps/web/src/components/project/gitea-integration/gitea-repository-picker.tsx b/apps/web/src/components/project/gitea-integration/gitea-repository-picker.tsx
index f596a190f..fee248930 100644
--- a/apps/web/src/components/project/gitea-integration/gitea-repository-picker.tsx
+++ b/apps/web/src/components/project/gitea-integration/gitea-repository-picker.tsx
@@ -12,6 +12,10 @@ import { authClient } from "@/lib/auth-client";
type GiteaRepository = ListGiteaRepositoriesResponse["repositories"][number];
+// A fresh id per token keeps repositories cached for one token out of another.
+// A counter instead of crypto.randomUUID(), which is missing on plain-HTTP origins.
+let credentialCacheId = 0;
+
type GiteaRepositoryPickerProps = {
open: boolean;
projectId: string;
@@ -36,7 +40,7 @@ export function GiteaRepositoryPicker({
const [selected, setSelected] = useState<GiteaRepository | null>(null);
const { data: session } = authClient.useSession();
const credentials = useMemo(
- () => ({ accessToken, cacheId: crypto.randomUUID() }),
+ () => ({ accessToken, cacheId: ++credentialCacheId }),
[accessToken],
);
const canFetch =
diff --git a/apps/web/src/lib/utils/create-workspace-slug.test.ts b/apps/web/src/lib/utils/create-workspace-slug.test.ts
new file mode 100644
index 000000000..294177c4d
--- /dev/null
+++ b/apps/web/src/lib/utils/create-workspace-slug.test.ts
@@ -0,0 +1,31 @@
+import { describe, expect, it } from "vite-plus/test";
+import { createUniqueWorkspaceSlug } from "./create-workspace-slug";
+
+describe("createUniqueWorkspaceSlug", () => {
+ it("keeps the base slug when it is free", () => {
+ expect(createUniqueWorkspaceSlug("My Team", [])).toBe("my-team");
+ });
+
+ it("adds a 12-character hex suffix when the slug is taken", () => {
+ expect(createUniqueWorkspaceSlug("My Team", ["my-team"])).toMatch(
+ /^my-team-[0-9a-f]{12}$/,
+ );
+ });
+
+ it("adds a suffix on plain-HTTP origins without crypto.randomUUID", () => {
+ const original = Object.getOwnPropertyDescriptor(crypto, "randomUUID");
+ Object.defineProperty(crypto, "randomUUID", {
+ value: undefined,
+ configurable: true,
+ });
+ try {
+ // "api" is reserved, so a random suffix is always required.
+ expect(createUniqueWorkspaceSlug("api", [])).toMatch(
+ /^api-[0-9a-f]{12}$/,
+ );
+ } finally {
+ if (original) Object.defineProperty(crypto, "randomUUID", original);
+ else delete (crypto as { randomUUID?: unknown }).randomUUID;
+ }
+ });
+});
diff --git a/apps/web/src/lib/utils/create-workspace-slug.ts b/apps/web/src/lib/utils/create-workspace-slug.ts
index 5edf5a932..cf78685b6 100644
--- a/apps/web/src/lib/utils/create-workspace-slug.ts
+++ b/apps/web/src/lib/utils/create-workspace-slug.ts
@@ -29,8 +29,14 @@ export function createWorkspaceBaseSlug(value: string): string {
return createSlug(value) || "workspace";
}
+// getRandomValues, unlike randomUUID, also works on plain-HTTP origins.
function createRandomSuffix(): string {
- return crypto.randomUUID().replace(/-/g, "").slice(0, RANDOM_SUFFIX_LENGTH);
+ const bytes = crypto.getRandomValues(
+ new Uint8Array(RANDOM_SUFFIX_LENGTH / 2),
+ );
+ return Array.from(bytes, (byte) => byte.toString(16).padStart(2, "0")).join(
+ "",
+ );
}
export function createUniqueWorkspaceSlug(