[FEAT] Prisma injection validation ()

check all prisma models/model usage and patch any potential sql injection vulns
This commit is contained in:
Sean Hatfield 2024-07-16 16:40:05 -07:00 committed by GitHub
parent 9b86bbd2b8
commit e909b25b29
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -22,6 +22,15 @@ const User = {
throw new Error(e.message); throw new Error(e.message);
} }
}, },
role: (role = "default") => {
const VALID_ROLES = ["default", "admin", "manager"];
if (!VALID_ROLES.includes(role)) {
throw new Error(
`Invalid role. Allowed roles are: ${VALID_ROLES.join(", ")}`
);
}
return String(role);
},
}, },
// validations for the above writable fields. // validations for the above writable fields.
@ -52,7 +61,7 @@ const User = {
data: { data: {
username: this.validations.username(username), username: this.validations.username(username),
password: hashedPassword, password: hashedPassword,
role: String(role), role: this.validations.role(role),
}, },
}); });
return { user: this.filterFields(user), error: null }; return { user: this.filterFields(user), error: null };