2020-12-21 15:38:52 +01:00
|
|
|
include::../description.adoc[]
|
|
|
|
|
|
|
|
== Noncompliant Code Example
|
|
|
|
|
|
|
|
For http://www.passportjs.org/[Passport.js]:
|
|
|
|
|
|
|
|
----
|
|
|
|
app.post('/login',
|
|
|
|
passport.authenticate('local', { failureRedirect: '/login' }),
|
|
|
|
function(req, res) {
|
|
|
|
// Sensitive - no session.regenerate after login
|
|
|
|
res.redirect('/');
|
|
|
|
});
|
|
|
|
----
|
|
|
|
|
|
|
|
== Compliant Solution
|
|
|
|
|
|
|
|
For http://www.passportjs.org/[Passport.js]:
|
|
|
|
|
|
|
|
----
|
|
|
|
app.post('/login',
|
|
|
|
passport.authenticate('local', { failureRedirect: '/login' }),
|
|
|
|
function(req, res) {
|
|
|
|
let prevSession = req.session;
|
|
|
|
req.session.regenerate((err) => { // Compliant
|
|
|
|
Object.assign(req.session, prevSession);
|
|
|
|
res.redirect('/');
|
|
|
|
});
|
|
|
|
});
|
|
|
|
----
|
|
|
|
|
|
|
|
include::../see.adoc[]
|
2021-06-02 20:44:38 +02:00
|
|
|
|
|
|
|
ifdef::rspecator-view[]
|
|
|
|
== Comments And Links
|
|
|
|
(visible only on this page)
|
|
|
|
|
|
|
|
include::../comments-and-links.adoc[]
|
|
|
|
endif::rspecator-view[]
|