forked from mirrors/gecko-dev
		
	Bug 968273 - Only persist permanent redirects for HTTPS, r=necko-reviewers,jesup
Differential Revision: https://phabricator.services.mozilla.com/D210483
This commit is contained in:
		
							parent
							
								
									9a3d8766df
								
							
						
					
					
						commit
						4bd1a86fd4
					
				
					 9 changed files with 142 additions and 1 deletions
				
			
		|  | @ -13366,6 +13366,11 @@ | |||
|   value: 10 | ||||
|   mirror: always | ||||
| 
 | ||||
| - name: network.cache.persist_permanent_redirects_http | ||||
|   type: bool | ||||
|   value: false | ||||
|   mirror: always | ||||
| 
 | ||||
| # This is used for a temporary workaround for a web-compat issue. If pref is | ||||
| # true CORS preflight requests are allowed to send client certificates. | ||||
| - name: network.cors_preflight.allow_client_cert | ||||
|  |  | |||
|  | @ -5091,7 +5091,17 @@ nsresult nsHttpChannel::InitCacheEntry() { | |||
| void nsHttpChannel::UpdateInhibitPersistentCachingFlag() { | ||||
|   // The no-store directive within the 'Cache-Control:' header indicates
 | ||||
|   // that we must not store the response in a persistent cache.
 | ||||
|   if (mResponseHead->NoStore()) mLoadFlags |= INHIBIT_PERSISTENT_CACHING; | ||||
|   if (mResponseHead->NoStore()) { | ||||
|     mLoadFlags |= INHIBIT_PERSISTENT_CACHING; | ||||
|     return; | ||||
|   } | ||||
| 
 | ||||
|   if (!StaticPrefs::network_cache_persist_permanent_redirects_http() && | ||||
|       mURI->SchemeIs("http") && | ||||
|       nsHttp::IsPermanentRedirect(mResponseHead->Status())) { | ||||
|     mLoadFlags |= INHIBIT_PERSISTENT_CACHING; | ||||
|     return; | ||||
|   } | ||||
| 
 | ||||
|   // Only cache SSL content on disk if the pref is set
 | ||||
|   if (!gHttpHandler->IsPersistentHttpsCachingEnabled() && | ||||
|  |  | |||
|  | @ -73,6 +73,11 @@ support-files = [ | |||
|   "test_1629307.html", | ||||
|   "file_link_header.sjs", | ||||
|   "file_link_dns_prefetch.sjs", | ||||
|   "bug968273_new.html", | ||||
|   "bug968273_redirect.html", | ||||
|   "bug968273_redirect.html^headers^", | ||||
|   "file_bug968273.html", | ||||
|   "test_bug968273.html", | ||||
| ] | ||||
| 
 | ||||
| prefs = [ | ||||
|  | @ -193,3 +198,5 @@ support-files = [ | |||
| skip-if = ["socketprocess_networking"] | ||||
| 
 | ||||
| ["browser_test_offline_tab.js"] | ||||
| 
 | ||||
| ["browser_bug968273.js"] | ||||
|  |  | |||
							
								
								
									
										70
									
								
								netwerk/test/browser/browser_bug968273.js
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										70
									
								
								netwerk/test/browser/browser_bug968273.js
									
									
									
									
									
										Normal file
									
								
							|  | @ -0,0 +1,70 @@ | |||
| /* This Source Code Form is subject to the terms of the Mozilla Public | ||||
|  * License, v. 2.0. If a copy of the MPL was not distributed with this | ||||
|  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 | ||||
| 
 | ||||
| function OpenCacheEntry(key, flags, lci) { | ||||
|   return new Promise(resolve => { | ||||
|     key = Services.io.newURI(key); | ||||
|     function CacheListener() {} | ||||
|     CacheListener.prototype = { | ||||
|       QueryInterface: ChromeUtils.generateQI(["nsICacheEntryOpenCallback"]), | ||||
| 
 | ||||
|       onCacheEntryCheck() { | ||||
|         return Ci.nsICacheEntryOpenCallback.ENTRY_WANTED; | ||||
|       }, | ||||
| 
 | ||||
|       onCacheEntryAvailable(entry) { | ||||
|         resolve(entry); | ||||
|       }, | ||||
| 
 | ||||
|       run() { | ||||
|         let storage = Services.cache2.diskCacheStorage(lci); | ||||
|         storage.asyncOpenURI(key, "", flags, this); | ||||
|       }, | ||||
|     }; | ||||
| 
 | ||||
|     new CacheListener().run(); | ||||
|   }); | ||||
| } | ||||
| 
 | ||||
| async function do_test_cache_persistent(https) { | ||||
|   let scheme = https ? "https" : "http"; | ||||
|   let url = | ||||
|     scheme + "://example.com/browser/netwerk/test/browser/test_bug968273.html"; | ||||
|   let redirectUrl = | ||||
|     scheme + | ||||
|     "://example.com/browser/netwerk/test/browser/bug968273_redirect.html"; | ||||
|   let tab = await BrowserTestUtils.openNewForegroundTab(gBrowser, url); | ||||
| 
 | ||||
|   let loadContextInfo = Services.loadContextInfo.custom(false, { | ||||
|     partitionKey: `(${scheme},example.com)`, | ||||
|   }); | ||||
| 
 | ||||
|   let entry = await OpenCacheEntry( | ||||
|     redirectUrl, | ||||
|     Ci.nsICacheStorage.OPEN_NORMALLY, | ||||
|     loadContextInfo | ||||
|   ); | ||||
| 
 | ||||
|   Assert.ok( | ||||
|     entry.persistent == https, | ||||
|     https | ||||
|       ? "Permanent redirects over HTTPS can be persistent" | ||||
|       : "Permanent redirects over HTTP cannot be persistent" | ||||
|   ); | ||||
| 
 | ||||
|   BrowserTestUtils.removeTab(tab); | ||||
|   gBrowser.removeCurrentTab(); | ||||
|   Services.cache2.clear(); | ||||
| } | ||||
| 
 | ||||
| add_task(async function setupTestingPref() { | ||||
|   await SpecialPowers.pushPrefEnv({ | ||||
|     set: [["network.cache.persist_permanent_redirects_http", false]], | ||||
|   }); | ||||
| }); | ||||
| 
 | ||||
| add_task(async function test_cache_persistent() { | ||||
|   await do_test_cache_persistent(true); | ||||
|   await do_test_cache_persistent(false); | ||||
| }); | ||||
							
								
								
									
										1
									
								
								netwerk/test/browser/bug968273_new.html
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										1
									
								
								netwerk/test/browser/bug968273_new.html
									
									
									
									
									
										Normal file
									
								
							|  | @ -0,0 +1 @@ | |||
| <html><body>This is bug968273_new.html.</body></html> | ||||
							
								
								
									
										1
									
								
								netwerk/test/browser/bug968273_redirect.html
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										1
									
								
								netwerk/test/browser/bug968273_redirect.html
									
									
									
									
									
										Normal file
									
								
							|  | @ -0,0 +1 @@ | |||
| <html><body>This document is redirected to bug968273_new.html.</body></html> | ||||
							
								
								
									
										3
									
								
								netwerk/test/browser/bug968273_redirect.html^headers^
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										3
									
								
								netwerk/test/browser/bug968273_redirect.html^headers^
									
									
									
									
									
										Normal file
									
								
							|  | @ -0,0 +1,3 @@ | |||
| HTTP 301 Moved Permanently | ||||
| Location: bug968273_new.html | ||||
| Cache-Control: max-age=3600 | ||||
							
								
								
									
										19
									
								
								netwerk/test/browser/file_bug968273.html
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										19
									
								
								netwerk/test/browser/file_bug968273.html
									
									
									
									
									
										Normal file
									
								
							|  | @ -0,0 +1,19 @@ | |||
| <!DOCTYPE HTML> | ||||
| <html> | ||||
| <!-- | ||||
| https://bugzilla.mozilla.org/show_bug.cgi?id=968273 | ||||
| 
 | ||||
| If a load has redirects, reloading the page will load the page starting with the original | ||||
| URI and do the redirects again. | ||||
| --> | ||||
| <head> | ||||
|   <title>Test for Bug 968273</title> | ||||
| <script> | ||||
| </script> | ||||
| </head> | ||||
| <body> | ||||
| <div id="frames"> | ||||
| <iframe name="child0" id="myIframe" src="bug968273_redirect.html"></iframe> | ||||
| </div> | ||||
| </body> | ||||
| </html> | ||||
							
								
								
									
										25
									
								
								netwerk/test/browser/test_bug968273.html
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										25
									
								
								netwerk/test/browser/test_bug968273.html
									
									
									
									
									
										Normal file
									
								
							|  | @ -0,0 +1,25 @@ | |||
| <!DOCTYPE HTML> | ||||
| <html> | ||||
| <!-- | ||||
| https://bugzilla.mozilla.org/show_bug.cgi?id=968273 | ||||
| 
 | ||||
| If a load has redirects, reloading the page will load the page starting with the original | ||||
| URI and do the redirects again. | ||||
| --> | ||||
| <head> | ||||
|   <title>Test for Bug 968273</title> | ||||
| </head> | ||||
| <body> | ||||
| <a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=968273">Mozilla Bug 968273</a> | ||||
| <p id="display"></p> | ||||
| <div id="content" style="display: none"> | ||||
| 
 | ||||
| </div> | ||||
| <pre id="test"> | ||||
| 
 | ||||
| <script type='application/javascript'> | ||||
| window.open("file_bug968273.html"); | ||||
| </script> | ||||
| </pre> | ||||
| </body> | ||||
| </html> | ||||
		Loading…
	
		Reference in a new issue
	
	 Kershaw Chang
						Kershaw Chang