New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
🐛Restrict checking cached ampDoc reference to AMP elements. #25000
Conversation
This fixes a bug where the compiled (renamed) property for `ampDoc_` could conflict with a form field name. Rather than blacklist `form`, whitelist `amp-` elements in case anything else has this behavior (like `window` and Element `id`s).
Woohoo PR number 25000 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Interesting bug, thanks for investigating and fixing. 👍
The way we fixed a similar DOM clobbering issue was to use property names that the validator bans in form[name]
, [id]
, etc. I.e.
const cached = node['__amp_doc']; // __amp_* is an invalid value for form[name].
We can try extending the window-property-name.js eslint rule to try to catch these generally, though it may have precision problems.
I considered using a string constant, but the problem here is that we are relying on the fact that we are relying on this matching the Lines 171 to 175 in b6bd628
Since this is set on an Perhaps calling it a cached value is not quite correct, since it isn't cached after a lookup. Rather, it is saved when the element is upgraded as we already know which |
Another alternative is to avoid accessing private ivars. const cached = typeof node.getAmpDoc === 'function' ? node.getAmpDoc() : null; Would need a change to dodge the |
I'm not sure how much of a problem this is, since |
Changed to use |
…ct#25000) This fixes a bug where the compiled (renamed) property for `ampDoc_` could conflict with a form field name.
…ct#25000) This fixes a bug where the compiled (renamed) property for `ampDoc_` could conflict with a form field name.
This fixes a bug where the compiled (renamed) property for
ampDoc_
could conflict with a form field name. Rather than blacklist
form
,whitelist
amp-
elements in case anything else has this behavior (likewindow
and Elementid
s).Fixes #24995