-
Notifications
You must be signed in to change notification settings - Fork 384
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
Scripts added by PWA plugin on error template are removed by sanitizer #7122
Comments
Having @thelovekesh pick this one up |
Thanks, @maitreyie-chavan! I’ve begun working on this and will aim to send over the PR by Monday. |
@westonruter I think sanitizer should work on both offline and 500 pages as we have added reload script to both. It will result something like: class AMP_PWA_Plugin_Sanitizer extends AMP_Base_Sanitizer {
public function sanitize() {
if (
! ( function_exists( 'is_offline' ) && is_offline() ) &&
! ( function_exists( 'is_500' ) && is_500() )
) {
return;
}
$scripts = $this->dom->getElementsByTagName( Tag::SCRIPT );
foreach ( $scripts as $script ) {
if (
( 'wp-navigation-request-properties' === $script->getAttribute( Attribute::ID ) ) ||
( 'module' === $script->getAttribute( Attribute::TYPE ) && false !== strpos( $script->textContent, 'checkNetworkAndReload()' ) )
) {
ValidationExemption::mark_node_as_px_verified( $script );
}
}
}
} |
@thelovekesh That looks like it will work. I think it could be optimized a bit further by using XPath to query for the two scripts as opposed to looping over all scripts on the page. |
I have tested it and it's working fine. I will optimize it further by using XPath to query. I have named the file |
Let's call it rather |
@westonruter Should I introduce a filter to generate an XPath query? $scripts = array(
'script-id-1',
'script-id-2'
)
$scripts = apply_filters( 'amp-pwa-script-sanitizer', $scripts ) There can be use cases when users want to add more scripts in offline or 500 error pages. Thoughts? |
@thelovekesh nah, I think that would be overkill. |
Bug Description
The PWA plugin adds a couple scripts to the error template:
These are getting stripped from the page when in Moderate/Strict standboxing, and in Loose they are getting retained with a
data-amp-unvalidated-tag
attribute added to them. In Loose mode, this is causing the CSS processing to be disabled, resulting in nostyle[amp-custom]
to be added to the page. Since the PWA plugin relies on the runtime cache to store CSS files, this means that when the Offline page is served to the user, no stylesheets will be available in the cache.The fix is simple: we need to add a PWA sanitizer which adds
data-px-verified-tag
to both of these scripts.Expected Behaviour
Scripts on PWA error template should not trigger the Loose sandboxing level.
Screenshots
PHP Version
No response
Plugin Version
2.3-alpha
AMP plugin template mode
Standard
WordPress Version
6.0
Site Health
No response
Gutenberg Version
No response
OS(s) Affected
No response
Browser(s) Affected
No response
Device(s) Affected
No response
Acceptance Criteria
No response
Implementation Brief
No response
QA Testing Instructions
No response
Demo
No response
Changelog Entry
No response
The text was updated successfully, but these errors were encountered: