mirror of
https://github.com/OneUptime/oneuptime.git
synced 2026-04-06 00:32:12 +02:00
fix: Enhance UUID validation in ObjectID and ProjectUtil classes
This commit is contained in:
@@ -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());
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user