From 9bb620a4a31473385af6ffd32d2b7d7c5affd415 Mon Sep 17 00:00:00 2001 From: whoswhip Date: Tue, 30 Dec 2025 20:28:00 -0500 Subject: [PATCH] fix: add validation for display name length in user creation and update requests --- SharpbinV3.Client/src/routes/+page.svelte | 8 ++++---- SharpbinV3.Client/src/routes/layout.css | 4 ++++ SharpbinV3.Client/vite.config.ts | 6 ++++++ SharpbinV3.Server/Controllers/AuthController.cs | 2 ++ SharpbinV3.Server/DTOs/UpdateUserRequest.cs | 2 +- 5 files changed, 17 insertions(+), 5 deletions(-) diff --git a/SharpbinV3.Client/src/routes/+page.svelte b/SharpbinV3.Client/src/routes/+page.svelte index 40a6298..181fe41 100644 --- a/SharpbinV3.Client/src/routes/+page.svelte +++ b/SharpbinV3.Client/src/routes/+page.svelte @@ -12,12 +12,12 @@ let error = ''; let title = ''; let content = ''; - let selectedSyntax = data.options.syntaxes[0]; + let selectedSyntax = data.options?.syntaxes[0]; let expiresIn: number = 0; - let selectedVisibility = data.options.visibilities[0].value; + let selectedVisibility = data.options?.visibilities[0].value; let password = ''; - const syntaxOptions = data.options.syntaxes.map((lang: string) => ({ + const syntaxOptions = data.options?.syntaxes.map((lang: string) => ({ value: lang, label: displayNames[lang] ?? lang.charAt(0).toUpperCase() + lang.slice(1) })); @@ -38,7 +38,7 @@ { value: 315360000000, label: 'Expire in 10 Years' } ]; - const visibilityOptions = data.options.visibilities.map( + const visibilityOptions = data.options?.visibilities.map( (visibility: { value: number; displayName: string }) => ({ value: visibility.value, label: visibility.displayName diff --git a/SharpbinV3.Client/src/routes/layout.css b/SharpbinV3.Client/src/routes/layout.css index 9e593ee..971af39 100644 --- a/SharpbinV3.Client/src/routes/layout.css +++ b/SharpbinV3.Client/src/routes/layout.css @@ -5,6 +5,10 @@ box-sizing: border-box; } +body { + background-color: black; +} + body, h1, h2, diff --git a/SharpbinV3.Client/vite.config.ts b/SharpbinV3.Client/vite.config.ts index b17ce86..855cfa6 100644 --- a/SharpbinV3.Client/vite.config.ts +++ b/SharpbinV3.Client/vite.config.ts @@ -3,6 +3,9 @@ import { sveltekit } from '@sveltejs/kit/vite'; import { defineConfig } from 'vite'; const apiUrl = process.env.VITE_API_URL || 'http://localhost:5050'; +const allowedHosts = process.env.VITE_ALLOWED_HOSTS + ? process.env.VITE_ALLOWED_HOSTS.split(',') + : ['localhost']; export default defineConfig({ plugins: [tailwindcss(), sveltekit()], @@ -10,5 +13,8 @@ export default defineConfig({ proxy: { '/api': apiUrl } + }, + preview: { + allowedHosts: allowedHosts } }); diff --git a/SharpbinV3.Server/Controllers/AuthController.cs b/SharpbinV3.Server/Controllers/AuthController.cs index 21030c0..25f0b5a 100644 --- a/SharpbinV3.Server/Controllers/AuthController.cs +++ b/SharpbinV3.Server/Controllers/AuthController.cs @@ -32,6 +32,8 @@ namespace SharpbinV3.Server.Controllers } if (!IsValidPassword(request.Password)) return BadRequest(new { message = "Password should have at least 8 characters, including uppercase, lowercase, and digits." }); + if (!string.IsNullOrEmpty(request.DisplayName) && request.DisplayName.Length > 26) + return BadRequest(new { message = "Display name should not exceed 26 characters." }); var user = await _authService.CreateUser(request.Username, request.Password, request.Email, request.DisplayName); return Ok(new diff --git a/SharpbinV3.Server/DTOs/UpdateUserRequest.cs b/SharpbinV3.Server/DTOs/UpdateUserRequest.cs index 334041b..ee034dc 100644 --- a/SharpbinV3.Server/DTOs/UpdateUserRequest.cs +++ b/SharpbinV3.Server/DTOs/UpdateUserRequest.cs @@ -14,7 +14,7 @@ namespace SharpbinV3.Server.DTOs if (DisplayName != null) { if (DisplayName.Length < 3 || DisplayName.Length > 26) { - results.Add(new ValidationResult("DisplayName must be between 3 and 50 characters.", [nameof(DisplayName)])); + results.Add(new ValidationResult("DisplayName must be between 3 and 26 characters.", [nameof(DisplayName)])); } } if (Email != null)