From c73cab2d03bb351ca65fdb9b7956307dca566ca2 Mon Sep 17 00:00:00 2001 From: Flam3rboy <34555296+Flam3rboy@users.noreply.github.com> Date: Sun, 8 Aug 2021 00:27:23 +0200 Subject: [PATCH] :lock: fix exposing user in channel.recipients --- src/models/Channel.ts | 4 ++-- src/models/Invite.ts | 10 ++-------- 2 files changed, 4 insertions(+), 10 deletions(-) diff --git a/src/models/Channel.ts b/src/models/Channel.ts index a77e492d..1dd05896 100644 --- a/src/models/Channel.ts +++ b/src/models/Channel.ts @@ -1,7 +1,7 @@ import { Schema, model, Types, Document } from "mongoose"; import db from "../util/Database"; import toBigInt from "../util/toBigInt"; -import { UserModel } from "./User"; +import { PublicUserProjection, UserModel } from "./User"; // @ts-ignore export interface AnyChannel extends Channel, DMChannel, TextChannel, VoiceChannel { @@ -42,7 +42,7 @@ ChannelSchema.virtual("recipients", { localField: "recipient_ids", foreignField: "id", justOne: false, - autopopulate: true, + autopopulate: { select: PublicUserProjection }, }); ChannelSchema.set("removeResponse", ["recipient_ids"]); diff --git a/src/models/Invite.ts b/src/models/Invite.ts index d6e8536e..01f12003 100644 --- a/src/models/Invite.ts +++ b/src/models/Invite.ts @@ -1,7 +1,7 @@ import { Schema, Document, Types } from "mongoose"; import db from "../util/Database"; import { ChannelModel } from "./Channel"; -import { UserModel } from "./User"; +import { PublicUserProjection, UserModel } from "./User"; import { GuildModel } from "./Guild"; export interface Invite { @@ -60,13 +60,7 @@ InviteSchema.virtual("inviter", { foreignField: "id", justOne: true, autopopulate: { - select: { - id: true, - username: true, - avatar: true, - discriminater: true, - public_flags: true, - }, + select: PublicUserProjection, }, });