Skip to content

Commit 8f05208

Browse files
committed
Reject staff self-delete unless it comes from the CMS.
deleteOwnAccount still works for readers and for staff signed in on cms.lap.onl.
1 parent 36a07be commit 8f05208

1 file changed

Lines changed: 22 additions & 0 deletions

File tree

functions/src/index.ts

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -150,6 +150,18 @@ function getRequestIp(rawRequest: { ip?: string; headers?: Record<string, unknow
150150
return isIP(normalized) ? normalized : "";
151151
}
152152

153+
const CMS_CALLABLE_ORIGINS = new Set(["https://cms.lap.onl"]);
154+
155+
function getRequestOrigin(rawRequest: { headers?: Record<string, unknown> }) {
156+
const value = rawRequest.headers?.origin ?? rawRequest.headers?.Origin;
157+
if (Array.isArray(value)) return String(value[0] || "").trim();
158+
return String(value || "").trim();
159+
}
160+
161+
function isStaffAuthorRole(role: unknown) {
162+
return typeof role === "string" && RESERVABLE_TEAM_ROLES.includes(role);
163+
}
164+
153165
function isAccountAllowedToParticipate(data: admin.firestore.DocumentData | undefined) {
154166
if (!data) return false;
155167
if (data.status === "banned" || data.bannedAt != null) return false;
@@ -2229,6 +2241,16 @@ export const deleteOwnAccount = onCall(
22292241
);
22302242
}
22312243

2244+
const author = await getDb().collection("authors").doc(request.auth.uid).get();
2245+
if (isStaffAuthorRole(author.data()?.role)) {
2246+
if (!CMS_CALLABLE_ORIGINS.has(getRequestOrigin(request.rawRequest))) {
2247+
throw new HttpsError(
2248+
"failed-precondition",
2249+
"Staff accounts can only be deleted from the CMS."
2250+
);
2251+
}
2252+
}
2253+
22322254
await deleteAccountData(request.auth.uid, true);
22332255
return { deleted: true };
22342256
}

0 commit comments

Comments
 (0)