add permission check for target env/path for imports

This commit is contained in:
Maidul Islam
2024-01-17 15:33:55 -05:00
committed by Akhil Mohan
parent 627c8711dc
commit 33c3c5ecc5

View File

@@ -48,11 +48,19 @@ export const secretImportServiceFactory = ({
path
}: TCreateSecretImportDTO) => {
const { permission } = await permissionService.getProjectPermission(actor, actorId, projectId);
// check if user has permission to import into destination path
ForbiddenError.from(permission).throwUnlessCan(
ProjectPermissionActions.Create,
subject(ProjectPermissionSub.Secrets, { environment, secretPath: path })
);
// check if user has permission to import from target path
ForbiddenError.from(permission).throwUnlessCan(
ProjectPermissionActions.Create,
subject(ProjectPermissionSub.Secrets, { environment: data.environment, secretPath: data.path })
);
const folder = await folderDal.findBySecretPath(projectId, environment, path);
if (!folder) throw new BadRequestError({ message: "Folder not found", name: "Create import" });