-
Notifications
You must be signed in to change notification settings - Fork 9.4k
Add Inline Form Key Updater to Page Cache | Fix Issue #13746 #27647
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
Changes from all commits
f0f1869
69ccbb8
d82e8d0
500f52b
9951677
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||
|---|---|---|---|---|
| @@ -0,0 +1,25 @@ | ||||
| <?php | ||||
| /** | ||||
| * | ||||
| * Copyright © Magento, Inc. All rights reserved. | ||||
| * See COPYING.txt for license details. | ||||
| */ | ||||
|
|
||||
| namespace Magento\PageCache\Plugin\Framework\View\Element; | ||||
|
|
||||
|
|
||||
| class InlineFormKeyUpdater | ||||
| { | ||||
| public function afterToHtml(\Magento\Framework\View\Element\FormKey $subject, $result) | ||||
| { | ||||
| return $result.$this->getInlineJavaScript(); | ||||
| } | ||||
|
|
||||
| private function getInlineJavaScript() | ||||
| { | ||||
| $uniqueId = uniqid(); | ||||
|
|
||||
| return '<script id="'.$uniqueId.'">document.getElementById("'.$uniqueId.'").previousSibling.value = formKey;</script>'; | ||||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. As Magento introduced CSP, we need to replace this code with something like this:
|
||||
| } | ||||
| } | ||||
| ?> | ||||
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| @@ -0,0 +1,21 @@ | ||||||||||||||||||||
|
|
||||||||||||||||||||
| <?php | ||||||||||||||||||||
| /** | ||||||||||||||||||||
| * Copyright © Magento, Inc. All rights reserved. | ||||||||||||||||||||
| * See COPYING.txt for license details. | ||||||||||||||||||||
| */ | ||||||||||||||||||||
|
|
||||||||||||||||||||
| /** @var \Magento\Framework\View\Element\Template $block */ | ||||||||||||||||||||
| ?> | ||||||||||||||||||||
| <script> | ||||||||||||||||||||
| var formKey = (function () { | ||||||||||||||||||||
|
|
||||||||||||||||||||
| var value = "; " + document.cookie; | ||||||||||||||||||||
| var parts = value.split("; " + 'form_key' + "="); | ||||||||||||||||||||
|
|
||||||||||||||||||||
| if (parts.length == 2) { | ||||||||||||||||||||
| return parts.pop().split(";").shift(); | ||||||||||||||||||||
| } | ||||||||||||||||||||
|
|
||||||||||||||||||||
| })(); | ||||||||||||||||||||
| </script> | ||||||||||||||||||||
|
Comment on lines
+10
to
+21
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||||||||||||||||||||
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.
Seems like this shouldn't happen in case if FPC is disabled. Am I correct?