Skip to content

Commit

Permalink
Fix: API admin permission
Browse files Browse the repository at this point in the history
  • Loading branch information
atsu1125 committed Dec 27, 2023
1 parent 602fcaf commit ec657c5
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 3 deletions.
8 changes: 8 additions & 0 deletions src/server/api/call.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,14 @@ export default async (endpoint: string, user: User | null | undefined, token: Ac
});
}

if (token && ep.meta.requireAdmin) {
throw new ApiError(accessDenied, { reason: 'Apps cannot use admin privileges.' });
}

if (token && ep.meta.requireModerator) {
throw new ApiError(accessDenied, { reason: 'Apps cannot use moderator privileges.' });
}

if (ep.meta.requireCredential && ep.meta.limit && !user!.isAdmin && !user!.isModerator) {
// Rate limit
await limiter(ep, user!).catch(e => {
Expand Down
3 changes: 2 additions & 1 deletion src/server/api/endpoints/admin/accounts/create.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,12 @@ export const meta = {
}
};

export default define(meta, async (ps, me) => {
export default define(meta, async (ps, me, token) => {
const noUsers = (await Users.count({
host: null,
})) === 0;
if (!noUsers && !me?.isAdmin) throw new Error('access denied');
if (token) throw new Error('access denied');

const { account, secret } = await signup(ps.username, ps.password);

Expand Down
4 changes: 2 additions & 2 deletions src/server/api/endpoints/meta.ts
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ export const meta = {
}
};

export default define(meta, async (ps, me) => {
export default define(meta, async (ps, me, token) => {
const instance = await fetchMeta(true);

const emojis = await Emojis.find({
Expand Down Expand Up @@ -181,7 +181,7 @@ export default define(meta, async (ps, me) => {
miauth: true,
};

if (me && me.isAdmin) {
if (me && me.isAdmin && !token) {
response.useStarForReactionFallback = instance.useStarForReactionFallback;
response.pinnedUsers = instance.pinnedUsers;
response.hiddenTags = instance.hiddenTags;
Expand Down

0 comments on commit ec657c5

Please sign in to comment.