Cleanup "bad" cookies (#102)
* fix: Move cookie-parser to app layer Signed-off-by: Colton Wolkins (Laptop) <colton@indicio.tech> * fix: remove cookies that shouldn't be set Not quite sure if it's possible to check the path of a cookie, but either way, we should remove old "bad" cookies that are set in people's browsers. This cleanup code should assist in that work. Signed-off-by: Colton Wolkins (Laptop) <colton@indicio.tech> --------- Signed-off-by: Colton Wolkins (Laptop) <colton@indicio.tech>
This commit is contained in:
parent
d633e90874
commit
84961b11f7
2 changed files with 11 additions and 1 deletions
11
src/index.js
11
src/index.js
|
@ -98,6 +98,7 @@ app.use((req, res, next) => {
|
|||
})
|
||||
|
||||
app.use(require('body-parser').urlencoded({ extended: true }))
|
||||
app.use(require('cookie-parser')());
|
||||
app.use(session({
|
||||
secret: config.secret,
|
||||
resave: false,
|
||||
|
@ -108,6 +109,16 @@ app.use(session({
|
|||
},
|
||||
name: 'christmas_community.connect.sid'
|
||||
}))
|
||||
app.use((req, res, next) => {
|
||||
let basepath = req.path.substring(0, req.path.lastIndexOf("/"));
|
||||
|
||||
// Clear cookies for paths that are not the base path. See #17
|
||||
if(basepath.length > config.base.length) {
|
||||
res.clearCookie('christmas_community.connect.sid', {path: req.path});
|
||||
res.clearCookie('christmas_community.connect.sid', {path: basepath});
|
||||
}
|
||||
next();
|
||||
});
|
||||
app.use(flash())
|
||||
app.use(passport.initialize())
|
||||
app.use(passport.session())
|
||||
|
|
|
@ -29,7 +29,6 @@ module.exports = ({ db, config }) => {
|
|||
const router = express.Router()
|
||||
|
||||
router.use('/', express.static(path.join(__dirname, '../static')))
|
||||
router.use(require('cookie-parser')())
|
||||
|
||||
router.get('/',
|
||||
async (req, res, next) => {
|
||||
|
|
Loading…
Reference in a new issue