Created
October 26, 2018 15:54
-
-
Save laniltee/29655718f9b7c25bcaceefc83511eda8 to your computer and use it in GitHub Desktop.
double submit 1
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
// Validate Credentials | |
app.post('/home', (req, res) => { | |
const username = req.body.inputUsername; | |
const password = req.body.inputPassword; | |
const sessionID = req.cookies['session-id']; | |
const cookieToken = req.cookies['csrf-token']; | |
if (username === 'root' && password === 'root') { | |
console.log("Home: Logged with valid credentials"); | |
// Generating Session ID and Token | |
const SESSION_ID = uuidv1(); | |
const CSRF_TOKEN = uuidv4(); | |
if (!sessionID && !cookieToken) { | |
console.log(`Generated Session ID: ${SESSION_ID}, CSRF Token: ${CSRF_TOKEN}`); | |
// Setting Cookie on Header | |
res.setHeader('Set-Cookie', [`session-id=${SESSION_ID}`, `time=${Date.now()}`, `csrf-token=${CSRF_TOKEN}`]); | |
} else { | |
console.log('POST /home Some Session ID and CSRF Token Found') | |
} | |
res.sendFile('views/form.html', {root: __dirname}); | |
} else { | |
const error = {status: 401, message: 'Invalid Credentials'}; | |
res.sendFile('views/form-error.html', {root: __dirname}); | |
} | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment