From 61f90b99af8ae1d6baad01568a291f85c5761e9a Mon Sep 17 00:00:00 2001 From: Vinzenz Schroeter Date: Fri, 19 Apr 2024 13:29:51 +0200 Subject: [PATCH] fix crypto.randomUUID() is not a function in an insecure context --- TanksServer/Endpoints.cs | 5 ++++- tank-frontend/src/App.tsx | 3 ++- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/TanksServer/Endpoints.cs b/TanksServer/Endpoints.cs index f139715..a98c351 100644 --- a/TanksServer/Endpoints.cs +++ b/TanksServer/Endpoints.cs @@ -24,7 +24,10 @@ internal static class Endpoints if (name.Length > 12) return Results.BadRequest("name too long"); - var player = playerService.GetOrAdd(name, id ?? Guid.NewGuid()); + if (!id.HasValue || id.Value == Guid.Empty) + id = Guid.NewGuid(); + + var player = playerService.GetOrAdd(name, id.Value); return player != null ? Results.Ok(new NameId(player.Name, player.Id)) : Results.Unauthorized(); diff --git a/tank-frontend/src/App.tsx b/tank-frontend/src/App.tsx index e065fc7..52631e6 100644 --- a/tank-frontend/src/App.tsx +++ b/tank-frontend/src/App.tsx @@ -11,9 +11,10 @@ import Scoreboard from "./Scoreboard.tsx"; import Button from "./components/Button.tsx"; import './App.css'; import {getRandomTheme, useStoredTheme} from "./theme.ts"; +import {EmptyGuid} from "./Guid.ts"; const getNewNameId = () => ({ - id: crypto.randomUUID(), + id: EmptyGuid, name: '' });