Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 39 additions & 0 deletions backend/src/services/project/project-service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1976,9 +1976,48 @@ export const projectServiceFactory = ({
});
};

const getProjectByName = async ({
name,
actor,
actorId,
actorOrgId,
actorAuthMethod
}: {
name: string;
actor: ActorType;
actorId: string;
actorOrgId: string;
actorAuthMethod: ActorAuthMethod;
}) => {
const project = await projectDAL.findOne({ name, orgId: actorOrgId });
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

logic: project names are not unique within an org - multiple projects can share the same name. Using findOne with just name and orgId may return an arbitrary project if duplicates exist, potentially granting access to the wrong project. This is a critical security issue.

Verify project name uniqueness constraints in schema, or use slug instead (which is unique).

if (!project) {
throw new NotFoundError({
message: `Project with name '${name}' not found`
});
}

const { permission } = await permissionService.getProjectPermission({
actor,
actorId,
projectId: project.id,
actorAuthMethod,
actorOrgId,
actionProjectType: ActionProjectType.Any
});

ForbiddenError.from(permission).throwUnlessCan(
ProjectPermissionActions.Read,
ProjectPermissionSub.Project
);

return project;
};


return {
createProject,
deleteProject,
getProjectByName,
getProjects,
updateProject,
getProjectUpgradeStatus,
Expand Down