Skip to content

Commit

Permalink
Enable csrf protection on put, delete (#6)
Browse files Browse the repository at this point in the history
* Enable csrf protection on put, delete

* allow head, use uuid.v4
  • Loading branch information
caoyangs authored and jchip committed Oct 3, 2016
1 parent 9d3e5d3 commit 003e934
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 4 deletions.
5 changes: 3 additions & 2 deletions lib/csrf-express.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ function csrfMiddleware(options) {
function middleware(req, res, next) {

function createToken() {
const id = uuid.v1();
const id = uuid.v4();
const headerPayload = {type: "header", uuid: id};
const cookiePayload = {type: "cookie", uuid: id};

Expand Down Expand Up @@ -47,7 +47,8 @@ function csrfMiddleware(options) {
});
}

if (req.method === "POST") {
const method = req.method.toUpperCase();
if (method !== "GET" && method !== "HEAD") {
return verifyAndCreateToken();
}

Expand Down
5 changes: 3 additions & 2 deletions lib/csrf-hapi.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ function csrfPlugin(server, options, next) {
server.ext("onPreAuth", (request, reply) => {

function createToken() {
const id = uuid.v1();
const id = uuid.v4();
const headerPayload = {type: "header", uuid: id};
const cookiePayload = {type: "cookie", uuid: id};

Expand Down Expand Up @@ -62,7 +62,8 @@ function csrfPlugin(server, options, next) {
return reply.continue();
}

if (request.method === "post") {
const method = request.method.toUpperCase();
if (method !== "GET" && method !== "HEAD") {
return verifyAndCreateToken();
}

Expand Down

0 comments on commit 003e934

Please sign in to comment.