Created
March 4, 2021 19:41
-
-
Save nnnnathann/29a56e972ee9cbdee93416337c3385f5 to your computer and use it in GitHub Desktop.
security-diagnosis.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// sql is a data store | |
import sql from "./db" | |
// auth identifies and validates requests, and is correctly | |
// implemented | |
import auth from "./auth" | |
import express from "express" | |
const app = express() | |
app.get("/dashboard", auth, (req, res) => { | |
sql.execute("SELECT user, message FROM messages WHERE DATE(timestamp) = DATE(NOW())") | |
.then((rows) => { | |
res.send( | |
`<html> | |
<body> | |
Here's the data from today: | |
${rows.map(([user, message]) => `${user} posted: ${message}`)} | |
</body> | |
</html>` | |
) | |
}) | |
}) | |
app.post("/dashboard/save", auth, (req, res) => { | |
sql.execute(` | |
INSERT INTO messages (user, message) | |
VALUES ("${req.user.username}", "${req.params.message}")`) | |
.then(() => { | |
res.send(`{"saved":true}`) | |
}) | |
}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment