Our investigations have shown us that not all browsers respect the http cache directives in a uniform manner. For security reasons we do not want certain pages in our application to cached, ever, by the web browser. This must work for at least the following browsers:
Our requirement came from a security test. After logging out from our website you could press the back button and view cached pages. | ||||
|
The correct minimum set of headers that works across all mentioned browsers:
Using PHP:
Using Java Servlet:
Using ASP.NET:
Using ASP:
Using Ruby on Rails:
Using Google Go:
Using HTML:
The Note that when the page is served over HTTP and a header is present in both the HTTP response headers and the HTML meta tags, then the one specified in the response header will get precedence over the HTML meta tag. The HTML meta tag will only be used when the page is viewed from local disk file system. See also W3 HTML spec chapter 5.2.2. Take care with this when you don't specify them programmatically, because the webserver can namely include some default values. To verify the one and other, you can see/debug them using Firebug Net panel. | |||||||||||||||||||||
|
(hey, everyone: please don't just mindlessly copy&paste all headers you can find) First of all, what you're trying to achieve should not be possible according to HTTP spec, because Back button history is not a cache:
Back is supposed to go back in time (to the time when user was logged in), it does not navigate forward to previously opened URL. However, it is possible in practice, exactly due to "back after logout" panic. It works reliably in very specific circumstances:
You never need any of:
If you want, you could add:
| |||||||||||||||||||||
|
As porneL stated, what you want is not to deactivate the cache, but to deactivate the history buffer. Different browsers have their own subtle ways to disable the history buffer. In Chrome (v28.0.1500.95 m) we can do this only by In FireFox (v23.0.1) any one of these will work:
In Opera (v12.15) we only can do this by In Safari (v5.1.7, 7534.57.2) any one of these will work:
In IE8 (v8.0.6001.18702IC) any one of these will work:
Combining the above gives us this solution which works for Chrome 28, FireFox 23, IE8, Safari 5.1.7, and Opera 12.15: Note that https is needed because Opera wouldn't deactivate history buffer for plain http pages. If you really can't get https and you are prepared to ignore Opera, the best you can do is this:
Below shows the raw logs of my tests: HTTP:
HTTPS:
| |||
|
After a bit of research we came up with the following list of headers that seemed to cover most browsers:
In ASP.NET we added these using the following snippet:
Found from: http://forums.asp.net/t/1013531.aspx | |||||||||||||||||
|
I found that all of the answers on this page still had problems. In particular, I noticed that none of them would stop IE8 from using a cached version of the page when you accessed it by hitting the back button. After much research and testing, I found that the only two headers I really needed were:
For an explanation of the Vary header, check out http://www.w3.org/Protocols/rfc2616/rfc2616-sec13.html#sec13.6 On IE6-8, FF1.5-3.5, Chrome 2-3, Safari 4, and Opera 9-10, these headers caused the page to be requested from the server when you click on a link to the page, or put the URL directly in the address bar. That covers about 99% of all browsers in use as of Jan '10. On IE6, and Opera 9-10, hitting the back button still caused the cached version to be loaded. On all other browsers I tested, they did fetch a fresh version from the server. So far, I haven't found any set of headers that will cause those browsers to not return cached versions of pages when you hit the back button. Update: After writing this answer, I realized that our web server is identifying itself as an HTTP 1.0 server. The headers I've listed are the correct ones in order for responses from an HTTP 1.0 server to not be cached by browsers. For an HTTP 1.1 server, look at BalusC's answer. | |||||||||||||||||||||
|
DISCLAIMER: I strongly suggest reading @BalusC's answer. After reading the following caching tutorial: http://www.mnot.net/cache_docs/ (I recommend you read it, too), I believe it to be correct. However, for historical reasons (and because I have tested it myself), I will include my original answer below: I tried the 'accepted' answer for PHP, which did not work for me. Then I did a little research, found a slight variant, tested it, and it worked. Here it is:
That should work. The problem was that when setting the same part of the header twice, if the
See more complete documentation here. | |||||||||||||||||||||
|
There's a bug in IE6 Content with "Content-Encoding: gzip" is always cached even if you use "Cache-Control: no-cache". http://support.microsoft.com/kb/321722 You can disable gzip compression for IE6 users (check the user agent for "MSIE 6") | ||||
|
These directives does not mitigate any security risk. They are really intended to force UA's to refresh volatile information, not keep UA's from being retaining information. See this similar question. At the very least, there is no guarantee that any routers, proxies, etc. will not ignore the caching directives as well. On a more positive note, policies regarding physical access to computers, software installation, and the like will put you miles ahead of most firms in terms of security. If the consumers of this information are members of the public, the only thing you can really do is help them understand that once the information hits their machine, that machine is their responsibility, not yours. | ||||
|
The PHP documentation for the header function has a rather complete example (contributed by a third party):
| |||||||||||||
|
The use of the pragma header in the response is a wives tale. RFC2616 only defines it as a request header | |||||
|
If you're facing download problems with IE6-IE8 over SSL and cache:no-cache header (and similar values) with MS Office files you can use cache:private,no-store header and return file on POST request. It works. | |||
|
in my case i fix the problem in chrome with this
where i need to clear the content of a previus form data when the users click button back for security reasons | |||||
|
The RFC for HTTP 1.1 says the proper method is to add an HTTP Header for: Cache-Control: no-cache Older browsers may ignore this if they are not properly compliant to HTTP 1.1. For those you can try the header: Pragma: no-cache This is also supposed to work for HTTP 1.1 browsers. | |||||
|
Setting the modified http header to some date in 1995 usually does the trick. Here's an example: Expires: Wed, 15 Nov 1995 04:58:08 GMT Last-Modified: Wed, 15 Nov 1995 04:58:08 GMT Cache-Control: no-cache, must-revalidate | |||||||||
|
I found the web.config route useful (tried to add it to the answer but doesn't seem to have been accepted so posting here)
And here is the express / node.js way of doing the same:
| ||||
|
I've had best and most consistent results across all browsers by setting Pragma: no-cache | |||
|
In addition to the headers consider serving your page via https. Many browsers will not cache https by default. | |||
|
The headers in the answer provided by BalusC does not prevent Safari 5 (and possibly older versions as well) from displaying content from the browser cache when using the browser's back button. A way to prevent this is to add an empty onunload event handler attribute to the body tag:
This hack apparently breaks the back-forward cache in Safari: Cross-browser onload event and the Back button | |||||
|
'Hacking' 카테고리의 다른 글
Must-Have Tools: Software mobile (0) | 2014.04.19 |
---|---|
Background Monitoring on Non-Jailbroken iOS 7 Devices — and a Mitigation (0) | 2014.02.26 |
pen test poster (mind map) vulnerable practice sites, OS builds, web apps (0) | 2013.12.03 |
Web Vulnerable Test Sites (0) | 2013.12.02 |
wifi password cracker (0) | 2013.10.09 |