Skip to content

Commit

Permalink
sanitize create project name
Browse files Browse the repository at this point in the history
  • Loading branch information
hahn-kev committed Jun 14, 2024
1 parent 64c53e7 commit fef78c6
Showing 1 changed file with 3 additions and 2 deletions.
5 changes: 3 additions & 2 deletions backend/LocalWebApp/Routes/ProjectRoutes.cs
Original file line number Diff line number Diff line change
Expand Up @@ -46,15 +46,14 @@ public static IEndpointConventionBuilder MapProjectRoutes(this WebApplication ap

return projects.Values;
});
Regex alphaNumericRegex = ProjectName();
group.MapPost("/project",
async (ProjectsService projectService, string name) =>
{
if (string.IsNullOrWhiteSpace(name))
return Results.BadRequest("Project name is required");
if (projectService.ProjectExists(name))
return Results.BadRequest("Project already exists");
if (!alphaNumericRegex.IsMatch(name))
if (!ProjectName().IsMatch(name))
return Results.BadRequest("Only letters, numbers, '-' and '_' are allowed");
await projectService.CreateProject(name, afterCreate: AfterCreate);
return TypedResults.Ok();
Expand Down Expand Up @@ -82,6 +81,8 @@ public static IEndpointConventionBuilder MapProjectRoutes(this WebApplication ap
string newProjectName
) =>
{
if (!ProjectName().IsMatch(newProjectName))
return Results.BadRequest("Project name is invalid");
var foundProjectGuid = await lexboxProjectService.GetLexboxProjectId(newProjectName);
if (foundProjectGuid is null)
return Results.BadRequest($"Project code {newProjectName} not found on lexbox");
Expand Down

0 comments on commit fef78c6

Please sign in to comment.