Skip to content

Instantly share code, notes, and snippets.

@nnnnathann
Created March 4, 2021 19:41
Show Gist options
  • Save nnnnathann/29a56e972ee9cbdee93416337c3385f5 to your computer and use it in GitHub Desktop.
Save nnnnathann/29a56e972ee9cbdee93416337c3385f5 to your computer and use it in GitHub Desktop.
security-diagnosis.ts
// 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