core: limit sdoc payload

This commit is contained in:
undefined committed 2022-07-27 21:40:12 +08:00
1 parent 22201794ce
commit 340b02bbf2
3 files changed
+7 -10

No files matched your search

+1 -1
View File
@@ -1,6 +1,6 @@
{
"name": "hydrooj",
"version": "3.14.19",
"version": "3.14.20",
"bin": "bin/hydrooj.js",
"main": "src/loader",
"module": "src/loader",
+1 -7
View File
@@ -294,7 +294,7 @@ class UserDetailHandler extends Handler {
const isSelfProfile = this.user._id === uid;
const [udoc, sdoc, union] = await Promise.all([
user.getById(domainId, uid),
token.getMostRecentSessionByUid(uid),
token.getMostRecentSessionByUid(uid, ['createAt', 'updateAt']),
domain.getUnion(domainId),
]);
if (!udoc) throw new UserNotFoundError(uid);
@@ -319,12 +319,6 @@ class UserDetailHandler extends Handler {
}
}
const tags = Object.entries(acInfo).sort((a, b) => b[1] - a[1]).slice(0, 20);
// Remove sensitive data
if (!isSelfProfile && sdoc) {
sdoc.createIp = '';
sdoc.updateIp = '';
sdoc._id = '';
}
this.response.template = 'user_detail.html';
this.response.body = {
isSelfProfile, udoc, sdoc, pdocs, tags,
+5 -2
View File
@@ -82,8 +82,11 @@ class TokenModel {
}
@ArgMethod
static async getMostRecentSessionByUid(uid: number) {
return await TokenModel.coll.findOne({ uid, tokenType: TokenModel.TYPE_SESSION }, { sort: { updateAt: -1 } });
static async getMostRecentSessionByUid(uid: number, projection: string[]) {
return await TokenModel.coll.findOne(
{ uid, tokenType: TokenModel.TYPE_SESSION },
{ projection: { _id: 0, ...Object.fromEntries(projection.map((i) => [i, 1])) }, sort: { updateAt: -1 } },
);
}
@ArgMethod