Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix code scanning alert no. 1: Database query built from user-controlled sources #100

Open
wants to merge 1 commit into
base: staging
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions pages/api/v1/certificates/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,10 @@ export default async function handler(req, res) {
if (req.method === "POST") {
const { email, event, type } = req.body;

if (!email || !event || !type) {
if (!email || !event || !type || typeof email !== "string") {
return res
.status(400)
.json({ success: false, error: "All fields are required." });
.json({ success: false, error: "All fields are required and email must be a string." });
}

try {
Expand Down Expand Up @@ -59,7 +59,7 @@ export default async function handler(req, res) {
});

const User = db.model(eventData.collection[type], userSchema);
const userData = await User.findOne({ email });
const userData = await User.findOne({ email: { $eq: email } });

if (!userData || !userData.checkin) {
return res.status(404).json({
Expand Down