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

Solution apps a1 tictactoe - Broken Access Token #640

Open
wants to merge 3 commits into
base: master
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
16 changes: 16 additions & 0 deletions owasp-top10-2021-apps/a1/tictactoe/src/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,9 @@ app.get('/healthcheck', (req, res) => {
app.post('/game', verifyJWT, async (req, res) => {
const user = req.body.user
const result = req.body.result

verifyCurrentUser(req, user, res)

let statistics = await db.getStatisticsFromUser(user)
if (statistics === null){
return res.sendStatus(400)
Expand Down Expand Up @@ -120,6 +123,7 @@ app.post('/create', async (req, res) => {

app.get('/statistics/data', verifyJWT, async (req, res) => {
const user = req.query.user
verifyCurrentUser(req, user, res)

let statistics = await db.getStatisticsFromUser(user)
if (statistics === undefined){
Expand Down Expand Up @@ -176,6 +180,18 @@ app.post('/login', async (req, res) => {
.redirect('/game')
});

// Access control
function verifyCurrentUser(req, user, res) {
var token = req.cookies.tictacsession
var currentUser = jwt.decode(token).username

if (currentUser != user){
res
.status(403)
.json({msg: "Do no have permission!"})
}
}

function verifyJWT(req, res, next){
var token = req.cookies.tictacsession
if (!token){
Expand Down