-
Notifications
You must be signed in to change notification settings - Fork 9.4k
Moving synchronous inline JS into JSON with an external script load. #14376
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
Moving synchronous inline JS into JSON with an external script load. #14376
Conversation
2aa6b9a to
0cf773a
Compare
|
Please, more of this |
a2c33ca to
679d773
Compare
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.
Hello @jonathanKingston. We can't remove public and protected methods from classes that marked as API by backward compatibility reason. We should mark those methods as deprecated.
You can read more about our backward compatibility here
http://devdocs.magento.com/guides/v2.3/contributor-guide/backward-compatible-development/index.html
This aids adoption of CSP by preventing inline JavaScript. However this shouldn't be used elsewhere and should be considered deprecated by default.
679d773 to
18039b9
Compare
|
@VladimirZaets updated the code to mark the functions as deprecated instead of removing them. |
| * @return array | ||
| */ | ||
| public function getGiftOptionsConfigJson() | ||
| public function getGiftOptionsConfig() |
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.
Hi, @jonathanKingston , due to Magento backward-compatible guide we can't rename public methods.
Please create the new method.
|
Hi @jonathanKingston . We don't want to introduce new code that already is deprecated. (It's about |
|
Hi @jonathanKingston, do you have any updates? |
This isn't possible to make backwards compatible at all. All the PRs I have submitted have been rejected over slight minor changes to internal functions which aren't ever documented. However changing this to use init blocks as suggested would make the code async which would cause race conditions on documented functions and variables that are in the global scope. Essentially the reason for this legacy code is to point at the fact this code needs to be rewritten in an async manner and ideally not exposed on the global namespace. This however isn't possible without breaking backwards compat. I'm happy to change |
You are right, we have a lot of limitations regarding backward compatibility, that's the main reason why we still have a lot of legacies code. Due to it, we try to think through about code design and make large refactoring one time. As to this issue, we already have the code design and our core team will make refactoring in the near future |
|
@VladimirZaets I'm not entirely sure why this was closed on the decision that I created a legacy function to allow for backwards compat. This code one of the last blockers e-commerce owners have from removing "unsafe-inline" from script-src in CSP. This vastly reduces the attack vectors of Magento (granted "unsafe-eval" is still needed which is also super bad, however each step helps lock down exploitation). If the answer is that store owners need to refactor and move to PWA or Magento 3.0 to gain this security then this is a long life-cycle of abuse. |
|
Hi @jonathanKingston. In the current situation, I'll be ok if you move inline scripts to the separate file for ensuring the CSP. We can use data attributes for pass the data to js file. |
|
@jonathanKingston |
Removal of synchronous inline JavaScript script tags.
Description
This aids adoption of CSP by preventing inline JavaScript. However this new function shouldn't be used elsewhere and should be considered deprecated when adopted.
Along with #14339 and #14318 I was able to get through the cart process with a CSP without
unsafe-inlinewhich will prevent script injection.Due to these global variables being loaded in many places, the refactoring to make them work with require are out of the scope of this patch, however it would be a good follow up bug to fix this too.
This still requires further work for CSP to be enabled everywhere however this will protect customers if no modules are used.
Fixed Issues (if relevant)
Manual testing scenarios
Header set Content-Security-Policy "default-src 'self' http:; script-src 'self' http: 'unsafe-eval'; style-src 'self' http: 'unsafe-inline'"Contribution checklist