mirrored from git://develop.git.wordpress.org/
-
Notifications
You must be signed in to change notification settings - Fork 2.7k
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
Script Modules: Add data server->client data passing #6433
Closed
Closed
Changes from 8 commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
83218e1
Add Script Module hooks registration on admin_footer
sirreal c0d71ac
Remove empty line in PHPDoc
sirreal 70780de
add data passing for script modules
sirreal 2c052a1
Fix filters and ID
sirreal 3dc7e5f
Replace array_merge with assignment
sirreal 4fa47e3
Merge branch 'fix/script-modules-admin-hooks' into add/script-module-…
sirreal e7c4afc
Print script data in admin_footer
sirreal 21d006d
DROPME: Enqueue api-fetch module dependent
sirreal d36e0c2
Merge fix/script-modules-admin-hooks
sirreal d185ac6
Improve data encoding
sirreal File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Any reason not to include
JSON_UNESCAPED_SLASHES
here too? I suspect URLs of endpoints will be relatively common data, and avoiding the leaning toothpick syndrome would be nice. HavingJSON_HEX_TAG
should be sufficient to avoid problems with</script>
that the default escaping of slashes was added to avoid.JSON_UNESCAPED_UNICODE
is another one to consider, but that would need testing for whether it breaks if pages are served with an encoding other than UTF-8.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.
I didn't consider this at all, it's copied from how the Interactivity API implements the same thing:
wordpress-develop/src/wp-includes/interactivity-api/class-wp-interactivity-api.php
Lines 170 to 179 in 473e255
I did some testing and it seems like we should be able to add
JSON_UNESCAPED_SLASHES
in both of these places, thanks!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.
JSON_UNESCAPED_UNICODE
might also be nice to add, but as you mention it might need to be behind a UTF-8 check:It looks like it would certainly improve readability and potentially size:
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.
I'll follow up for Interactivity API here: #6520
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.
In some quick experimenting, I find Firefox 125 and Chromium 124 both do need the document to be utf-8 to interpret unescaped Unicode properly.
Also they seem to use the actual
Content-Type
HTTP header over<meta>
tags if both specify a different charset, but they'll use<meta>
tags if the HTTP header doesn't specify a charset. The deprecatedcharset
attribute on a<script>
tag doesn't seem to be used by either.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.
It is vital that
JSON_UNESCAPED_SLASHES
not be added, as it avoids a security vulnerability when encoding a string that includes</script>
. When slashes are escaped, this becomes<\/script>
and the browser won't prematurely close the script tag.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.
Thanks for flagging that! I'd like to continue discussing on #6520 (comment), where I've replied. That PR is likely to land sooner, and whatever implementation is used there should also be used here. (In fact, I'd expect Interactivity API to use this proposal to print its data.)
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.
@westonruter I already addressed that concern
Is there any reason to think that's not accurate?
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.
Ah, yes. As long as
JSON_HEX_TAG
is present, then it seems safe to includeJSON_UNESCAPED_SLASHES
. Sorry I missed that. Maybe add a comment explaining why the particular set of flags are used, noting the security implications.