prevent deleting address from other domains
All checks were successful
ci/woodpecker/push/woodpecker Pipeline was successful

This commit is contained in:
Sergo 2023-07-30 01:44:41 +03:00
parent 3a5f8ed6d6
commit 56f5871d8e

View File

@ -110,6 +110,16 @@ export class AliasesService<ServiceParams extends AliasesParams = AliasesParams>
}
async remove(id: NullableId, params: ServiceParams): Promise<Alias[]> {
const { data: addressInfoResponse } = await wildDuckClient.get<Alias>(
`addresses/resolve/${id}`,
);
const allowedDomain: string = config.get("wildDuck.domain");
// If address does not match the allowed domain, throw an error
if (!addressInfoResponse.address.endsWith(allowedDomain)) {
throw new BadRequest("Unable to delete address");
}
await wildDuckClient.delete<Alias>(`/addresses/${id}`);
const userId = await this.getUserIdByEmailAddress(params);