mirror of
https://github.com/hpware/news-analyze.git
synced 2025-06-23 21:14:23 +00:00
Add getUserTokenMinusSQLInjection to prevent SQL Injection in via the
Some checks are pending
Build and Push Docker Image / build-and-push (push) Waiting to run
Some checks are pending
Build and Push Docker Image / build-and-push (push) Waiting to run
cookies (that may be not possible, but it is a safety guard I want to add. (Chat: https://t3.chat/chat/c1883e6a-6c38-4af3-9818-0e927449c61c)
This commit is contained in:
parent
bd3a81dfbc
commit
2895263e52
10 changed files with 90 additions and 54 deletions
|
@ -1,6 +1,34 @@
|
|||
import sql from "~/server/components/postgres";
|
||||
import getUserTokenMinusSQLInjection from "~/server/components/getUserToken";
|
||||
export default defineEventHandler(async (event) => {
|
||||
const userToken = getCookie(event, "token");
|
||||
return {
|
||||
token: userToken,
|
||||
};
|
||||
try {
|
||||
const userToken = await getUserTokenMinusSQLInjection(event);
|
||||
if (userToken.error.length !== 0) {
|
||||
return {
|
||||
error: userToken.error,
|
||||
};
|
||||
}
|
||||
// REMOVE OLD TOKENS
|
||||
const removeToken = await sql`
|
||||
DELETE FROM usertokens
|
||||
WHERE username = ${userToken.user}
|
||||
`;
|
||||
console.log(removeToken);
|
||||
// DELETE USER
|
||||
const deleteUserAccount = await sql`
|
||||
DELETE FROM users
|
||||
WHERE username = ${userToken.user}
|
||||
`;
|
||||
console.log(deleteUserAccount);
|
||||
deleteCookie(event, "token");
|
||||
return {
|
||||
success: true,
|
||||
};
|
||||
} catch (e) {
|
||||
console.log(e);
|
||||
return {
|
||||
error: "INTERNAL_SERVER_ERROR",
|
||||
e: e.message,
|
||||
};
|
||||
}
|
||||
});
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue