mirror of
https://github.com/XFox111/backbone.git
synced 2026-04-22 07:17:59 +03:00
chore: validation improvements and fixes
This commit is contained in:
+9
-2
@@ -40,11 +40,18 @@ app.MapHub<WsHub>("/ws", options =>
|
|||||||
app.MapPost("/send",
|
app.MapPost("/send",
|
||||||
static async (
|
static async (
|
||||||
[FromServices] IHubContext<WsHub> hubContext, [FromServices] ILogger<Program> logger,
|
[FromServices] IHubContext<WsHub> hubContext, [FromServices] ILogger<Program> logger,
|
||||||
[FromQuery] string id, [FromBody] string data
|
[FromQuery] string? id, [FromBody] string? data
|
||||||
) =>
|
) =>
|
||||||
{
|
{
|
||||||
|
if (string.IsNullOrWhiteSpace(id) || id.Length > 64)
|
||||||
|
return Results.BadRequest("Connection ID is required and must be at most 64 characters long.");
|
||||||
|
|
||||||
|
foreach (char c in id)
|
||||||
|
if (!char.IsLetterOrDigit(c) && c != '-' && c != '_')
|
||||||
|
return Results.BadRequest("Connection ID contains invalid characters.");
|
||||||
|
|
||||||
if (string.IsNullOrWhiteSpace(data) || data.Length > 66_560)
|
if (string.IsNullOrWhiteSpace(data) || data.Length > 66_560)
|
||||||
return Results.BadRequest();
|
return Results.BadRequest("Body is required and must be at most 66,560 characters long.");
|
||||||
|
|
||||||
logger.LogDebug("Received payload for connection '{id}' (package length: {len})", id, data.Length);
|
logger.LogDebug("Received payload for connection '{id}' (package length: {len})", id, data.Length);
|
||||||
await hubContext.Clients.Client(id).SendAsync("ReceiveData", data);
|
await hubContext.Clients.Client(id).SendAsync("ReceiveData", data);
|
||||||
|
|||||||
Reference in New Issue
Block a user