NodeJS - 注销用户但浏览器后退按钮允许我进入上一个会话

问题描述 投票:0回答:1
    // Disable caching for sensitive pages
    app.use((req, res, next) => {
    res.header('Cache-Control', 'private, no-cache, no-store, must-revalidate');
    res.header('Expires', '-1');
    res.header('Pragma', 'no-cache');
    next();
    });


    // Passport authentication
    app.post('/login',
    passport.authenticate('local', {
    successRedirect: '/dashboard',
    failureRedirect: '/login',
    failureFlash: true  
    })
    );

    // Middleware for session handling
    app.use(session({
    secret: process.env.SESSION_SECRET || process.env.DEFAULT_SESSION_SECRET,
    resave: false,
    saveUninitialized: true,
    cookie: {
        maxAge: 60 * 60 * 1000, // 1 hour
        secure: process.env.NODE_ENV === 'production',
        httpOnly: true,
        sameSite: 'strict',
    },
    }));


    // Logout route
    app.get('/logout', (req, res) => {
    req.flash('success', 'Logged out successfully');
    req.session.destroy(err => {
            if (err) {
                console.error('Error destroying session:', err);
            }
            res.redirect('/');
        });
    });

大家好,

我登录到我的应用程序,单击注销后,我仍然可以返回到之前的会话,这对我来说是一个安全问题。我什至手动关闭浏览器,然后重新打开它,如果我复制并粘贴上一个会话的 URL,我仍然可以看到它。

我正在禁用缓存,使用 Passport 本地策略对用户进行身份验证,使用中间件进行会话处理,并在成功注销后销毁会话。 我附上了相关的代码,我通过在线查看建议尝试了很多解决方案,但没有任何效果,这让我发疯。

我做错了什么?

session logout
1个回答
0
投票

那块饼干呢?您是否也在注销时销毁它?

© www.soinside.com 2019 - 2024. All rights reserved.