fix: Enhance UUID validation in ObjectID and ProjectUtil classes

This commit is contained in:
Nawaz Dhandala
2026-01-16 10:29:20 +00:00
parent 3968428f0c
commit 3947b0bba1
2 changed files with 6 additions and 4 deletions

View File

@@ -120,10 +120,10 @@ export default class ObjectID extends DatabaseProperty {
* Check if a string is a valid UUID format
*/
public static isValidUUID(id: string): boolean {
if (!id || typeof id !== "string") {
if (!id) {
return false;
}
return UUID_REGEX.test(id);
return UUID_REGEX.test(id.toString());
}
/**

View File

@@ -20,7 +20,7 @@ export default class ProjectUtil {
`current_project_id`,
) as string;
if (currentProjectId) {
if (currentProjectId && ObjectID.isValidUUID(currentProjectId)) {
return new ObjectID(currentProjectId);
}
@@ -30,7 +30,9 @@ export default class ProjectUtil {
projectId = undefined;
}
if (projectId) {
// Only return the projectId if it's a valid UUID
// This prevents URL path segments like "email", "subscribe" etc. from being used as project IDs
if (projectId && ObjectID.isValidUUID(projectId)) {
return new ObjectID(projectId);
}