Skip to content

shanebo/csrf

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

17 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

CSRF

Middleware for Dylan which can generate csrf tokens and protect from csrf attacks.

Install

npm install @dylan/csrf

Usage

const dylan = require('dylan');
const session = require('@dylan/session');
const csrf = require('@dylan/csrf');
const app = dylan();

app.use(session({
  cookie: 'foo',
  secret: 'boo'
}));

app.use(csrf());

app.get('/contact', (req, res) => {
  res.send(`
    <form method="post" action="/contact">
      <input type="hidden" name="csrf-token" value="${res.locals.csrfToken}">
      <input type="text" name="message" value="hello world">
      <button>Talk</button>
    </form>
  `);
});

app.post('/contact', (req, res) => {
  console.log(req.body.message); // hello world
  res.end('safely handled');
});

About

Middleware for Dylan which can generate csrf tokens and protect from csrf attacks.

Resources

License

Stars

Watchers

Forks

Packages

No packages published