2020-06-30 14:41:58 +02:00
|
|
|
include::../description.adoc[]
|
|
|
|
|
|
|
|
include::../ask-yourself.adoc[]
|
|
|
|
|
|
|
|
include::../recommended.adoc[]
|
|
|
|
|
|
|
|
== Sensitive Code Example
|
|
|
|
|
|
|
|
https://www.npmjs.com/package/csurf[Express.js CSURF middleware] protection is not found on an unsafe HTTP method like POST method:
|
|
|
|
|
|
|
|
----
|
|
|
|
let csrf = require('csurf');
|
|
|
|
let express = require('express');
|
|
|
|
|
|
|
|
let csrfProtection = csrf({ cookie: true });
|
|
|
|
|
|
|
|
let app = express();
|
|
|
|
|
|
|
|
// Sensitive: this operation doesn't look like protected by CSURF middleware (csrfProtection is not used)
|
|
|
|
app.post('/money_transfer', parseForm, function (req, res) {
|
|
|
|
res.send('Money transferred');
|
|
|
|
});
|
|
|
|
----
|
|
|
|
|
|
|
|
Protection provided by https://www.npmjs.com/package/csurf[Express.js CSURF middleware] is globally disabled on unsafe methods:
|
|
|
|
|
|
|
|
----
|
|
|
|
let csrf = require('csurf');
|
|
|
|
let express = require('express');
|
|
|
|
|
|
|
|
app.use(csrf({ cookie: true, ignoreMethods: ["POST", "GET"] })); // Sensitive as POST is unsafe method
|
|
|
|
----
|
|
|
|
|
2020-12-21 15:38:52 +01:00
|
|
|
== Compliant Solution
|
|
|
|
|
|
|
|
https://www.npmjs.com/package/csurf[Express.js CSURF middleware] protection is used on unsafe methods:
|
|
|
|
|
2022-02-04 17:28:24 +01:00
|
|
|
[source,javascript]
|
2020-12-21 15:38:52 +01:00
|
|
|
----
|
|
|
|
let csrf = require('csurf');
|
|
|
|
let express = require('express');
|
|
|
|
|
|
|
|
let csrfProtection = csrf({ cookie: true });
|
|
|
|
|
|
|
|
let app = express();
|
|
|
|
|
|
|
|
app.post('/money_transfer', parseForm, csrfProtection, function (req, res) { // Compliant
|
|
|
|
res.send('Money transferred')
|
|
|
|
});
|
|
|
|
----
|
|
|
|
|
|
|
|
Protection provided by https://www.npmjs.com/package/csurf[Express.js CSURF middleware] is enabled on unsafe methods:
|
|
|
|
|
2022-02-04 17:28:24 +01:00
|
|
|
[source,javascript]
|
2020-12-21 15:38:52 +01:00
|
|
|
----
|
|
|
|
let csrf = require('csurf');
|
|
|
|
let express = require('express');
|
|
|
|
|
|
|
|
app.use(csrf({ cookie: true, ignoreMethods: ["GET"] })); // Compliant
|
|
|
|
----
|
|
|
|
|
2020-06-30 14:41:58 +02:00
|
|
|
include::../see.adoc[]
|
2021-06-02 20:44:38 +02:00
|
|
|
|
2021-06-03 09:05:38 +02:00
|
|
|
ifdef::env-github,rspecator-view[]
|
2021-09-20 15:38:42 +02:00
|
|
|
|
|
|
|
'''
|
|
|
|
== Implementation Specification
|
|
|
|
(visible only on this page)
|
|
|
|
|
|
|
|
include::../message.adoc[]
|
|
|
|
|
2021-06-08 15:52:13 +02:00
|
|
|
'''
|
2021-06-02 20:44:38 +02:00
|
|
|
== Comments And Links
|
|
|
|
(visible only on this page)
|
|
|
|
|
|
|
|
include::../comments-and-links.adoc[]
|
2021-06-03 09:05:38 +02:00
|
|
|
endif::env-github,rspecator-view[]
|