Reader small image

You're reading from  JavaScript Security

Product typeBook
Published inNov 2014
Reading LevelIntermediate
Publisher
ISBN-139781783988006
Edition1st Edition
Languages
Tools
Right arrow
Author (1)
Eugene Liang
Eugene Liang
author image
Eugene Liang

Y.E Liang is a researcher, author, web developer, and business developer. He has experience in both frontend and backend development, particularly in engineering, user experience using JavaScript/CSS/HTML, and performing social network analysis. He has authored multiple books and research papers.
Read more about Eugene Liang

Right arrow

Basic defense against similar attacks


First and foremost, we need to prevent cross-origin posting of form values unless we are absolutely sure that we have a way to control (or at least know who can do it) the POST. For a start, we can prevent cross-origin posting without permissions.

For instance, here's what we can do to prevent cross-origin posting: we first need to install cookie-session (https://github.com/expressjs/cookie-session) and CSRF (https://github.com/expressjs/csurf) and then apply them in our server.js file.

To install CSRF, simply run the command npm install –g csrf.

The settings of our server.js file now look like this:

var express    = require('express');
var bodyParser = require('body-parser');
var app        = express();
var session    = require('cookie-session');
var csrf    = require('csrf');

app.use(csrf());
app.use(bodyParser());

var port     = process.env.PORT || 8080; // set our port

var mongoose   = require('mongoose');
mongoose.connect('mongodb://127.0.0.1/todos...
lock icon
The rest of the page is locked
Previous PageNext Page
You have been reading a chapter from
JavaScript Security
Published in: Nov 2014Publisher: ISBN-13: 9781783988006

Author (1)

author image
Eugene Liang

Y.E Liang is a researcher, author, web developer, and business developer. He has experience in both frontend and backend development, particularly in engineering, user experience using JavaScript/CSS/HTML, and performing social network analysis. He has authored multiple books and research papers.
Read more about Eugene Liang