Skip to content

Instantly share code, notes, and snippets.

@laniltee
Created October 26, 2018 16:19
Show Gist options
  • Save laniltee/aafdb11893f7116db9e845e9461996c1 to your computer and use it in GitHub Desktop.
Save laniltee/aafdb11893f7116db9e845e9461996c1 to your computer and use it in GitHub Desktop.
validation in double submit
// Submit Form Data
app.post('/posts', (req, res) => {
const inputTitle = req.body.inputTitle;
const inputContent = req.body.inputContent;
const inputToken = req.body.inputToken;
const cookieToken = req.cookies['csrf-token'];
// Checking if Cookie Token matches CSRF Token Submitted
if (cookieToken === inputToken) {
console.log("Post Content: Valid CSRF Tokens Received !");
res.sendFile('views/form-success.html', {root: __dirname});
} else {
console.error("Post Content: No Valid CSRF Tokens Received ! !");
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