Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Expected behavior when Clear-Site-Data header is set?

According to the docs:

Clear-Site-Data header clears browsing data (cookies, storage, cache) associated with the requesting website

Now trying it, you can see in the screenshot (Firefox v76) that in the Response section, Clear-Site-Data was set in the browser, but, you can still see the assets as "cached":

Note: Even after navigating back/forth after some time, the cached assets doesn't seem to get cleared.

enter image description here

I'm under the impression this will happen instantly but I can't get it to work. Is this suppose to happen instantly or after some time, or I am just missing some else?


Update for those who care:

Clear-Site-Data appears to only work on localhost or https

like image 345
IMB Avatar asked May 11 '20 19:05

IMB


People also ask

What does clearing site data do?

Browsing history: Clearing your browsing history deletes the following: Web addresses you've visited are removed from the History page. Shortcuts to those pages are removed from the New Tab page. Address bar predictions for those websites are no longer shown.

Should I clear all site data?

Your browser tends to hold onto information, and over time this can cause problems with logging in to or loading websites. It is always a good idea to clear out your cache, or browser history, and clear cookies on a regular basis.

How do I clear HTTP headers?

Open the site which you would like to open and then click on the HTTP Response Headers option. Click on the X-Powered-By header and then click Remove on the Actions Pane to remove it from the response.

How do I clear data stored in my browser?

To find your browser history, press Ctrl+Shift+Del, type "edge://settings/clearBrowserData" in the address bar, or go to the three-dot menu > Settings > Privacy, search and services > Clear Browsing Data and click Choose what to clear.

What is the purpose of clear-site-Data Header?

This header is used in deleting the browsing data which is in the requesting website. These browsing data includes cache, cookies, storage and executionContents. It helps the web developers to have an improved level of control over data stored by the browser locally. Clear-Site-Data: "cache"|"cookies"|"storage"|"executionContexts"|"*"

What is the purpose of a website header?

The goal of the header is to provide a mechanism which allows developers to instruct a browser to clear a site’s data. This can be useful for example upon sign out, to ensure that locally stored data is removed.

Is it possible to clear site data in HTTP response?

The (draft) spec states: If the Clear-Site-Data header is present in an HTTP response received from the network, then data MUST be cleared before rendering the response to the user. Additionally, as you mention in this comment it is only supported when a request is secure (either https or localhost ).

Why do we put expect in the header field?

If the data provided in the header field meets the expectation value, then the server responds with 100 indicating that it is a success, else it responds with status 417 specifying that the expectation has failed. The reason behind putting the Expect, that would be to work around broken web servers.


1 Answers

Is this suppose to happen instantly or after some time, or I am just missing some else?

It is supposed to happen instantly. The (draft) spec states:

If the Clear-Site-Data header is present in an HTTP response received from the network, then data MUST be cleared before rendering the response to the user.

Additionally, as you mention in this comment it is only supported when a request is secure (either https or localhost).

I prepared a simple test, with two resources:

  • index.html -- a page that links to a CSS file, and also accepts a ?clear query parameter to include a CSD header in the response
  • style.css -- a CSS page with random colours, to make clear when it has been regenerated, that declares itself as cacheable

This behaved as specified with Firefox 76.0.1; on receiving a resource with Clear-Site-Data: "cache", the cache is cleared before fetching its subresources.

Without Clear-Site-Data:

  • Fetch index.html by entering the URL and hitting Enter
  • Repeat this. Note that the referenced style.css is served from the cache, and the page colour doesn't change

With Clear-Site-Data:

  • Fetch index.html?clear by entering the URL and hitting Enter
  • Repeat this. Note that the referenced style.css is not served from the cache, and the page colour changes

Code:

#!/usr/bin/python3

import http.server
import socketserver

import random

PORT = 8000

class SampleDataHandler(http.server.SimpleHTTPRequestHandler):

    def do_GET(self):
        if ".css" in self.path:
            self.send_response(200)
            self.send_header('Content-Type', 'text/css')
            self.send_header('Cache-Control', 'max-age=3600')
            self.end_headers()
            color = b"%06x" % random.randint(0, 0xFFFFFF)
            self.wfile.write(b"html{background-color: " + color + b";}\n")
        else:
            self.send_response(200)
            if '?clear' in self.path:
                self.send_header('Clear-Site-Data', '"cache"')
            self.end_headers()
            self.wfile.write(b"<link rel=stylesheet href=style.css>This is the content.\n")


httpd = socketserver.TCPServer(("", PORT), SampleDataHandler)

httpd.serve_forever()
like image 69
Joe Avatar answered Oct 23 '22 12:10

Joe