amphtml icon indicating copy to clipboard operation
amphtml copied to clipboard

Race condition in amp-cid-backup experiment deleting parts of the amp-store entry in localStorage

Open lautarorodriguezmrf opened this issue 5 years ago • 3 comments

Description

There seems to be a race condition when restoring client ids using the amp-cid-backup experiment. When using more than a given amount of variable replacement of the CLIENT_ID, part of the amp-store entry in the localStorage is lost.

For this example, I have placed amp-consent to show that the consentString is lost.

In the simple html page below, amp-analytics will try to track an event using seven CLIENT_ID variable replacement when the document is visible. If the event "event": "https://example.com?rand=RANDOM&bar1=CLIENT_ID(bar)&bar2=CLIENT_ID(bar2)&bar3=CLIENT_ID(bar3)&bar4=CLIENT_ID(bar4)&bar5=CLIENT_ID(bar5)&bar6=CLIENT_ID(bar6)&bar7=CLIENT_ID(bar7)" has only 6 CLIENT_ID replacements, the consentString will always be there after refreshing, but it will be gone if we put any more.

Reproduction Steps

  • How to reproduce the issue:
  1. Using the following page, load and accept consent.
  2. Reload the page, check that consentString is gone from the amp-store localStorage entry.
  3. Reload the page, see that consent is requested again.

This can be repeated endlessly, having consent requested every other reload.

  • How to not have the issue

    • Setting the amp-cid-backup experiement off
    • Having 6 or less CLIENT_ID replacements in the event url of the analytics
  • Other scenarios where the issue can be reproduced

    • If more than 6 CLIENT_ID replacements are needed, they don't have to be in the same amp component. Having some replacements in amp-state and others in amp-analytics have also lead into reproducing the issue. For simplicity, the snippet to reproduce it here just uses amp-analytics.
<!doctype html>
<html ⚡ lang=es-ES>
<head>
	<meta charset=utf-8>
	<meta name=viewport content="width=device-width,minimum-scale=1,initial-scale=1">
	<meta name=amp-consent-blocking content>
	<title>CMP issue scenario</title>
	<link rel=canonical href="https://flowcards.mrf.io/cmp-issues.html">
	<script async src="https://cdn.ampproject.org/v0.js"></script>
	<script async src="https://cdn.ampproject.org/v0/amp-analytics-0.1.js" custom-element=amp-analytics></script>
	<script async src="https://cdn.ampproject.org/v0/amp-consent-0.1.js" custom-element=amp-consent></script>
    <style amp-boilerplate>body{-webkit-animation:-amp-start 8s steps(1,end) 0s 1 normal both;-moz-animation:-amp-start 8s steps(1,end) 0s 1 normal both;-ms-animation:-amp-start 8s steps(1,end) 0s 1 normal both;animation:-amp-start 8s steps(1,end) 0s 1 normal both}@-webkit-keyframes -amp-start{from{visibility:hidden}to{visibility:visible}}@-moz-keyframes -amp-start{from{visibility:hidden}to{visibility:visible}}@-ms-keyframes -amp-start{from{visibility:hidden}to{visibility:visible}}@-o-keyframes -amp-start{from{visibility:hidden}to{visibility:visible}}@keyframes -amp-start{from{visibility:hidden}to{visibility:visible}}</style><noscript><style amp-boilerplate>body{-webkit-animation:none;-moz-animation:none;-ms-animation:none;animation:none}</style></noscript>
  </head>
<body>
	<div id=postPromptUI>
		Hello world!
	</div>
​
	<amp-analytics type class="i-amphtml-layout-fixed i-amphtml-layout-size-defined" style="width:1px;height:1px;" i-amphtml-layout=fixed>
		<script type="application/json">
			{
				"requests": {
 				  "event": "https://example.com?rand=RANDOM&bar1=CLIENT_ID(bar)&bar2=CLIENT_ID(bar2)&bar3=CLIENT_ID(bar3)&bar4=CLIENT_ID(bar4)&bar5=CLIENT_ID(bar5)&bar6=CLIENT_ID(bar6)&bar7=CLIENT_ID(bar7)"
				},
				"triggers": {
				  "visile": {
					"on": "visible",
					"request": "event"
				  }
				},
				"transport": {
				  "beacon": false,
				  "xhrpost": true,
				  "image": false
				}
			  }
			</script>
		</amp-analytics>
<amp-consent id=MarfeelCMP layout=nodisplay type=Marfeel class="i-amphtml-layout-nodisplay" hidden=hidden i-amphtml-layout=nodisplay>
<script type="application/json">
			{
				"checkConsentHref": "https://live.mrf.io/cmp/www.santeplusmag.com/amp/check-consent?source=marfeel",
				"promptUISrc": "https://live.mrf.io/cmp/www.santeplusmag.com/amp/index.html?build=25235",
				"postPromptUI": "postPromptUI",
				"uiConfig": {
					"overlay": true
				},
				"policy": {
					"default": {
						"waitFor": { "Marfeel": [] }
					}
				},
				"clientConfig": {
					"vendorListBaseUrl": "https://live.mrf.io/statics/1w/js/ps/vendor-list.consensu.org/v2/",
					"baseUrl": "https://live.mrf.io/cmp/www.santeplusmag.com",
					"consentLanguage": "fr",
					"publisherLogo": "https://www.santeplusmag.com/mrf4u/mstore/9ac49c1/d58b6c06490e56a90124c30a99ae8d9b485f0b7e/logo_carousel.png"
				}
			}
		</script>
</amp-consent>
</body>
</html>

Relevant Logs

No response

Browser(s) Affected

No response

OS(s) Affected

No response

Device(s) Affected

No response

AMP Version Affected

No response

lautarorodriguezmrf avatar Aug 20 '21 16:08 lautarorodriguezmrf

Hello @micajuine-ho @zhouyx

Any chance you had a look at this? Do you think this is related to amp-cid-backup experiment?

oliverfernandez avatar Sep 06 '21 15:09 oliverfernandez

Ok, I think is not an issue, but an expected behaviour, since the maximum number of entries in local storage per domain is 8

https://github.com/ampproject/amphtml/blob/e3f4eda7c73083e73a869e0ff933505bfe9795ec/src/service/storage-impl.js#L14

But then, now that cid are stored in LocalStorage, isn't it quite easy to reach this limit. If a site uses <amp-consent> and 6 analytics providers, then the limit is reached, and cid are not properly stored

oliverfernandez avatar Sep 07 '21 15:09 oliverfernandez

This issue has been automatically marked as stale because it has not had recent activity. It will be closed in 7 days if no further activity occurs. Thank you for your contributions.

stale[bot] avatar Sep 28 '22 03:09 stale[bot]