Skip to content

Commit 838b40b

Browse files
authored
Restrict User Info endpoints to specific roles (#382)
Also cleanup role definitions for meta-roles. <!-- This is an auto-generated comment: release notes by coderabbit.ai --> ## Summary by CodeRabbit * **Security** * Enhanced authorization requirements for user lookup functionality, now requiring specific access roles. * **Refactor** * Restructured role management system to support improved permission control and maintainability. <!-- end of auto-generated comment: release notes by coderabbit.ai -->
1 parent 1a9f8ef commit 838b40b

File tree

2 files changed

+20
-6
lines changed

2 files changed

+20
-6
lines changed

src/api/routes/user.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ import { FastifyZodOpenApiTypeProvider } from "fastify-zod-openapi";
1717
import { QueryCommand } from "@aws-sdk/client-dynamodb";
1818
import { genericConfig } from "common/config.js";
1919
import { unmarshall } from "@aws-sdk/util-dynamodb";
20+
import { AppRoles } from "common/roles.js";
2021

2122
const userRoute: FastifyPluginAsync = async (fastify, _options) => {
2223
await fastify.register(rateLimiter, {
@@ -29,7 +30,11 @@ const userRoute: FastifyPluginAsync = async (fastify, _options) => {
2930
"/findUserByUin",
3031
{
3132
schema: withRoles(
32-
[],
33+
[
34+
AppRoles.VIEW_USER_INFO,
35+
AppRoles.TICKETS_MANAGER,
36+
AppRoles.TICKETS_SCANNER,
37+
],
3338
withTags(["Generic"], {
3439
summary: "Find a user by UIN.",
3540
body: searchUserByUinRequest,

src/common/roles.ts

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,9 @@ import { AllOrganizationNameList } from "@acm-uiuc/js-shared";
33
/* eslint-disable import/prefer-default-export */
44
export const runEnvironments = ["dev", "prod"] as const;
55
export type RunEnvironment = (typeof runEnvironments)[number];
6-
export enum AppRoles {
6+
export const META_ROLE_PREFIX = "__metaRole:"
7+
8+
export enum BaseRoles {
79
EVENTS_MANAGER = "manage:events",
810
TICKETS_SCANNER = "scan:tickets",
911
TICKETS_MANAGER = "manage:tickets",
@@ -21,19 +23,25 @@ export enum AppRoles {
2123
VIEW_EXTERNAL_MEMBERSHIP_LIST = "view:externalMembershipList",
2224
MANAGE_EXTERNAL_MEMBERSHIP_LIST = "manage:externalMembershipList",
2325
ALL_ORG_MANAGER = "manage:orgDefinitions",
24-
AT_LEAST_ONE_ORG_MANAGER = "manage:someOrg" // THIS IS A FAKE ROLE - DO NOT ASSIGN IT MANUALLY - only used for permissioning
26+
VIEW_USER_INFO = "view:userInfo",
27+
}
28+
29+
export enum MetaRoles {
30+
AT_LEAST_ONE_ORG_MANAGER = `${META_ROLE_PREFIX}manage:someOrg`,
2531
}
26-
export const PSUEDO_ROLES = [AppRoles.AT_LEAST_ONE_ORG_MANAGER]
32+
33+
export const AppRoles = { ...BaseRoles, ...MetaRoles } as const;
34+
export type AppRoles = BaseRoles | MetaRoles;
2735
export const orgRoles = ["LEAD", "MEMBER"] as const;
2836
export type OrgRole = typeof orgRoles[number];
2937
export type OrgRoleDefinition = {
3038
org: typeof AllOrganizationNameList[number],
3139
role: OrgRole
3240
}
3341

34-
export const allAppRoles = Object.values(AppRoles).filter(
42+
export const allAppRoles = Object.values(BaseRoles).filter(
3543
(value) => typeof value === "string",
36-
).filter(value => !PSUEDO_ROLES.includes(value)); // don't assign psuedo roles by default
44+
);
3745

3846
export const AppRoleHumanMapper: Record<AppRoles, string> = {
3947
[AppRoles.EVENTS_MANAGER]: "Events Manager",
@@ -54,4 +62,5 @@ export const AppRoleHumanMapper: Record<AppRoles, string> = {
5462
[AppRoles.MANAGE_EXTERNAL_MEMBERSHIP_LIST]: "External Membership List Manager",
5563
[AppRoles.ALL_ORG_MANAGER]: "Organization Definition Manager",
5664
[AppRoles.AT_LEAST_ONE_ORG_MANAGER]: "Manager of at least one org",
65+
[AppRoles.VIEW_USER_INFO]: "User Information Viewer"
5766
}

0 commit comments

Comments
 (0)