Skip to content

Commit

Permalink
minecraft uuid thing is slightly broken
Browse files Browse the repository at this point in the history
  • Loading branch information
C4illin committed Mar 25, 2024
1 parent 7aa854f commit f6f176b
Showing 1 changed file with 60 additions and 2 deletions.
62 changes: 60 additions & 2 deletions backend/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -80,12 +80,28 @@ app.post("/register", async (req, res) => {
const response = await fetch(
`https://api.mojang.com/users/profiles/minecraft/${username}`,
);

if (response.status === 404) {
console.log(`Failed to get uuid for ${username}`);
res.status(400).send("Username doesn't exist");
return;
}

// check if response is valid json
if (!response.ok) {
console.log(`Failed to get uuid for ${username}`);
res.status(500).send("Failed to check username");
return;
}

const uuid = await response.json().id;

if (!uuid || uuid == null) {
console.log(`Failed to get uuid for ${username}: ${uuid}`);
res.status(500).send("Failed to get UUID, try again later");
return;
}

const token = crypto.randomBytes(32).toString("hex");

let conn;
Expand All @@ -98,7 +114,9 @@ app.post("/register", async (req, res) => {

if (rows.length > 0) {
console.log(
`User with email ${userEmail} already exists: ${rows[0].toString()}`,
`User with email ${userEmail} already exists: ${JSON.stringify(
rows[0],
)}`,
);
// If the account is not active, resend the confirmation email
if (!rows[0].active) {
Expand All @@ -124,7 +142,6 @@ app.post("/register", async (req, res) => {
);
}
} else {

res.status(400).send("Account already exists and is active.");
}
return;
Expand Down Expand Up @@ -181,6 +198,47 @@ If you did not request this, please ignore this email.`,
});
}

// This path could perhaps be exploited
app.get("/updateUUID/:username", async (req, res) => {
const username = req.params.username.toLowerCase();
const response = await fetch(
`https://api.mojang.com/users/profiles/minecraft/${username}`,
);

if (response.status === 404) {
console.log(`Failed to get uuid for ${username}`);
res.status(400).send("Username doesn't exist");
return;
}

if (!response.ok) {
console.log(`Failed to get uuid for ${username}`);
res.status(500).send("Failed to check username");
return;
}

const uuid = await response.json().id;

if (!uuid || uuid == null) {
console.log(`Failed to get uuid for ${username}: ${uuid}`);
res.status(500).send("Failed to get UUID, try again later");
return;
}

let conn;
try {
conn = await pool.getConnection();
const sql = "UPDATE users SET uuid = ? WHERE username = ?";
await conn.query(sql, [uuid, username]);
} catch (err) {
console.error(err);
} finally {
if (conn) conn.end();
}

res.send(`Updated UUID for ${username} to ${uuid}`);
});

app.get("/confirm/:token", async (req, res) => {
const token = req.params.token;
let conn;
Expand Down

0 comments on commit f6f176b

Please sign in to comment.