有没有办法在用户注销但点击“后退”按钮后阻止页面呈现? 按钮?

发布于 2024-07-04 21:01:04 字数 348 浏览 6 评论 0 原文

我有一些网站需要登录并显示敏感信息。

用户进入该页面,系统会提示您登录,然后即可查看信息。

该用户注销该站点,并被重定向回登录页面。

然后,该人可以点击“返回”并直接返回到包含敏感信息的页面。 由于浏览器只是将其视为呈现的 HTML,因此向他们显示它没有问题。

有没有办法防止当用户从注销屏幕点击“后退”按钮时显示该信息? 我并不是想禁用后退按钮本身,我只是想阻止敏感信息再次显示,因为该人不再登录该网站。

为了便于讨论,上面的站点/场景是在带有表单身份验证的 ASP.NET 中(因此,当用户转到第一页(他们想要的页面)时,他们会被重定向到登录页面 - 以防万一的差异)。

I have some website which requires a logon and shows sensitive information.

The person goes to the page, is prompted to log in, then gets to see the information.

The person logs out of the site, and is redirected back to the login page.

The person then can hit "back" and go right back to the page where the sensitive information is contained. Since the browser just thinks of it as rendered HTML, it shows it to them no problem.

Is there a way to prevent that information from being displayed when the person hits the "back" button from the logged out screen? I'm not trying to disable the back button itself, I'm just trying to keep the sensitive information from being displayed again because the person is not logged into the site anymore.

For the sake of argument, the above site/scenario is in ASP.NET with Forms Authentication (so when the user goes to the first page, which is the page they want, they're redirected to the logon page - in case that makes a difference).

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(16

一绘本一梦想 2024-07-11 21:01:04

简而言之,它无法安全地完成。

然而,有很多技巧可以使用户难以反击并显示敏感数据。

Response.Cache.SetCacheability(HttpCacheability.NoCache);
Response.Cache.SetExpires(Now.AddSeconds(-1));
Response.Cache.SetNoStore();
Response.AppendHeader("Pragma", "no-cache");

这将禁用客户端的缓存,但是并非所有浏览器都支持

如果您可以选择使用 AJAX,则可以使用从客户端代码更新的更新面板检索敏感数据,因此除非客户端仍处于登录状态,否则在回击时不会显示敏感数据。

The short answer is that it cannot be done securely.

There are, however, a lot of tricks that can be implemented to make it difficult for users to hit back and get sensitive data displayed.

Response.Cache.SetCacheability(HttpCacheability.NoCache);
Response.Cache.SetExpires(Now.AddSeconds(-1));
Response.Cache.SetNoStore();
Response.AppendHeader("Pragma", "no-cache");

This will disable caching on client side, however this is not supported by all browsers.

If you have the option of using AJAX then sensitive data can be retrieved using a updatepanel that is updated from client code and therefore it will not be displayed when hitting back unless client is still logged in.

污味仙女 2024-07-11 21:01:04

缓存和历史记录是独立的,不应影响彼此。

唯一的例外银行< /a> 是 HTTPS 和 Cache-Control: Must-revalidate 的组合,在历史记录中导航时强制刷新。

在纯 HTTP 中,除了利用浏览器错误之外,没有其他方法可以做到这一点。

你可以使用 Javascript 来破解它,检查 document.cookie 并在设置“杀手”cookie 时进行重定向,但我想当浏览器没有完全按照预期设置/清除 cookie 时,这可能会出现严重错误。

Cache and history are independent and one shouldn't affect each other.

The only exception made for banks is that combination of HTTPS and Cache-Control: must-revalidate forces refresh when navigating in history.

In plain HTTP there's no way to do this except by exploiting browser bugs.

You could hack around it using Javascript that checks document.cookie and redirects when a "killer" cookie is set, but I imagine this could go seriously wrong when browser doesn't set/clear cookies exactly as expected.

嘿嘿嘿 2024-07-11 21:01:04

来自 aspdev.org

在顶部添加以下行Page_Load 事件处理程序的值,您的 ASP.NET 页面不会缓存在用户浏览器中:

Response.Cache.SetCacheability(HttpCacheability.NoCache)

设置此属性可确保如果用户点击后退按钮,内容将消失,如果他按“刷新”,他将被重定向到登录页面。

From aspdev.org:

Add the following line on top of the Page_Load event handler and your ASP.NET page will not be cached in the users browsers:

Response.Cache.SetCacheability(HttpCacheability.NoCache)

Settings this property ensures that if the user hits the back-button the content will be gone, and if he presses "refresh" he will be redirected to the login-page.

拥抱没勇气 2024-07-11 21:01:04

丹尼·斯莫夫,<元> 元素在控制缓存方面非常不可靠,尤其是 Pragma 更是如此。 参考

DannySmurf, <meta> elements are extremely unreliable when it comes to controlling caching, and Pragma in particular even more so. Reference.

誰認得朕 2024-07-11 21:01:04

dannyp 等人认为,no-cache 不会阻止缓存存储敏感资源。 它仅意味着缓存无法为其所存储的资源提供服务,除非先重新验证该资源。 如果您希望阻止敏感资源被缓存,则需要使用 no-store 指令。

dannyp and others, no-cache does not stop caches from storing sensitive resources. It merely means that a cache cannot serve a resource it has stored without revalidating it first. If you wish to prevent sensitive resources from being cached, you need to use the no-store directive.

丘比特射中我 2024-07-11 21:01:04

您可以使用 JavaScript 函数进行快速服务器检查(ajax),如果用户未登录,则擦除当前页面并用消息替换它。 显然,对于 JavaScript 已关闭的用户来说,这很容易受到攻击,但这种情况非常罕见。 从好的方面来说,这与浏览器和服务器技术(asp/php 等)无关。

You could have a javascript function does a quick server check (ajax) and if the user is not logged in, erases the current page and replaces it with a message. This would obviously be vulnerable to a user whos javascript is off, but that is pretty rare. On the upside, this is both browser and server technology (asp/php etc) agnostic.

許願樹丅啲祈禱 2024-07-11 21:01:04

您正在寻找一个无缓存指令:

<META HTTP-EQUIV="PRAGMA" CONTENT="NO-CACHE">

如果您正在进行母版页设计,这可能有点麻烦,但我相信您可以将此指令放在一个页面上,而不会影响您的其余部分网站(假设这就是您想要的)。

如果您设置了此指令,浏览器将尽职地返回服务器寻找页面的全新副本,这将导致您的服务器发现用户未经身份验证并将其引导至登录页面。

You are looking for a no-cache directive:

<META HTTP-EQUIV="PRAGMA" CONTENT="NO-CACHE">

If you've got a master page design going, this may be a little bit of a juggle, but I believe you can put this directive on a single page, without affecting the rest of your site (assuming that's what you want).

If you've got this directive set, the browser will dutifully head back to the server looking for a brand new copy of the page, which will cause your server to see that the user is not authenticated and bump him to the login page.

叫思念不要吵 2024-07-11 21:01:04

让注销操作为 POST。 然后浏览器将提示“您确定要重新发布表单吗?” 而不是显示页面。

Have the logout operation be a POST. Then the browser will prompt for "Are you sure you want to re-post the form?" rather than show the page.

淡淡的优雅 2024-07-11 21:01:04

我不知道如何在 ASP.NET 中执行此操作,但在 PHP 中我会执行以下操作:

header("Expires: Mon, 26 Jul 1997 05:00:00 GMT");
header("Cache-Control: no-cache");
header("Pragma: no-cache");

这会强制浏览器重新检查该项目,因此应触发您的身份验证检查,拒绝用户访问。

I don't know how to do it in ASP.NET but in PHP I would do something like:

header("Expires: Mon, 26 Jul 1997 05:00:00 GMT");
header("Cache-Control: no-cache");
header("Pragma: no-cache");

Which forces the browser to recheck that the item, so your authentication checking should be triggered, denying the user access.

烛影斜 2024-07-11 21:01:04

这有点麻烦,但是如果您有一个嵌入的 java applet 或 flash 应用程序,并且通过它们完成身份验证,您可以这样做,以便他们每次都必须与服务器进行“实时”身份验证他们想查看信息。

使用它您还可以加密任何信息。

总是有可能有人可以保存带有敏感信息的页面,没有缓存并不能解决这种情况(但是总是可以对 Flash 或 Java 应用程序进行屏幕截图)。

It's a bit of a strain, but if you had a java applet or a flash application that was embedded and authentication was done through that you could make it so that they had to authenticate in, erm, 'real-time' with the server everytime they wanted to view the information.

Using this you could also encrypt any information.

There's always the possibility that someone can just save the page with the sensitive information on, having no cache isn't going to get around this situation (but then a screenshot can always be taken of a flash or java application).

桃气十足 2024-07-11 21:01:04

为了完整性:

Response.Cache.SetCacheability(HttpCacheability.NoCache);
Response.Cache.SetNoStore();
Response.Cache.SetExpires(DateTime.Now.AddMinutes(-1));

For completeness:

Response.Cache.SetCacheability(HttpCacheability.NoCache);
Response.Cache.SetNoStore();
Response.Cache.SetExpires(DateTime.Now.AddMinutes(-1));
诺曦 2024-07-11 21:01:04

正确的答案涉及在响应上设置 HTTP Cache-Control 标头。 如果您想确保它们从不缓存输出,您可以执行 Cache-Control: no-cache。 这也经常与 no-store 配合使用。

如果您想要有限的缓存,其他选项包括设置过期时间和必须重新验证,但这些都可能会导致缓存的页面再次显示。

请参阅http://www.w3.org/Protocols/rfc2616 /rfc2616-sec14.html#sec14.9.4

The correct answer involves use of setting the HTTP Cache-Control header on the response. If you want to ensure that they never cache the output, you can do Cache-Control: no-cache. This is often used in coordination with no-store as well.

Other options, if you want limited caching, include setting an expires time and must-revalidate, but these could potentially all cause a cached page to be displayed again.

See http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html#sec14.9.4

画尸师 2024-07-11 21:01:04

好吧,在一家以拥有世界上最安全、最高效的家庭银行软件而闻名的巴西大型银行公司(Banco do Brasil)中,他们只是将 History.go(1) 放在每个页面中。所以,如果您点击按后退按钮,您将返回。 简单的。

Well, in a major brazilian bank corporation (Banco do Brasil) which is known by having one of the world´s most secure and efficient home banking software, they simply put history.go(1) in every page.So, if you hit the back button, you will be returned. Simple.

猥︴琐丶欲为 2024-07-11 21:01:04

请查看 HTTP 响应标头。 人们发布的大多数 ASP 代码看起来都是在设置这些。 确定。

O'Reilly 的花栗鼠书是 HTTP 的圣经,而 Chris Shiflett 的 HTTP 书 也不错。

Please look into the HTTP response headers. Most of the ASP code that people are posting looks to be setting those. Be sure.

The chipmunk book from O'Reilly is the bible of HTTP, and Chris Shiflett's HTTP book is good as well.

葬花如无物 2024-07-11 21:01:04

您可以将包含敏感信息的网页作为 HTTP POST 返回,然后在大多数情况下,浏览器会向您显示消息,询问您是否要重新提交数据。 (不幸的是,我找不到这种行为的规范来源。)

You can have the web page with the sensitive be returned as an HTTP POST, then in most cases browsers will give you the message asking if you want want to resubmit the data. (Unfortunately I cannot find a canonical source for this behavior.)

不甘平庸 2024-07-11 21:01:04

我只想到银行业的例子。

我的银行页面上有这样的内容:

<meta http-equiv="expires" content="0" />

我想这应该是关于这个的。

I just had the banking example in mind.

The page of my bank has this in it:

<meta http-equiv="expires" content="0" />

This should be about this I suppose.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文