Closed oscarssanchez closed 2 years ago
@oscarssanchez Thanks for creating this GitHub issue. Before escalating this for the team to review let's check your site setup. From the codebase checks I've been performing I don't see any errors or descriptions output in H1 tags. Would it be possible for you to open a WordPress support topic, where initial user reported issues are investigated? Within the support topic it would be great if you could state whether you're able to reproduce this consistently. If so we may ask you to perform a check using the Health Check & Troubleshooting plugin, to ensure there are no third party plugins or hosting related features impacting this description being output.
I'll also keep this GitHub issue open while we can perform additional checks and discuss this with the team.
I was able to recreate this on a test site today. The error appears in my case in the below scenarios:
None of the above occur consistently and in my case I tested from a hosting platform whereby a user did report the same previously. Since opening this support topic I no longer encounter the same on this site - which uses a core theme and additional plugins other than SK (SH info below)
Console Errors:
JQMIGRATE: Migrate is installed, version 3.3.2
/wp-json/google-site-kit/v1/modules/analytics/data/report?metrics%5B0%5D%5Bexpression%5D=ga%3Ausers&metrics%5B0%5D%5Balias%5D=Total%20Users&startDate=2021-09-02&endDate=2021-09-29&url=&compareStartDate=2021-08-05&compareEndDate=2021-09-01&_locale=user:1 Failed to load resource: the server responded with a status of 500 ()
/wp-json/google-site-kit/v1/modules/analytics/data/report?metrics%5B0%5D%5Bexpression%5D=ga%3Apageviews&metrics%5B0%5D%5Balias%5D=Pageviews&dimensions%5B0%5D%5Bname%5D=ga%3ApagePath&startDate=2021-09-02&endDate=2021-09-29&orderby%5B0%5D%5BfieldName%5D=ga%3Apageviews&orderby%5B0%5D%5BsortOrder%5D=DESCENDING&limit=10&_locale=user:1 Failed to load resource: the server responded with a status of 500 ()
/wp-json/google-site-kit/v1/modules/pagespeed-insights/data/pagespeed?strategy=mobile&url=https%3A%2F%2Fmytakes.net%2F&_locale=user:1 Failed to load resource: the server responded with a status of 500 ()
/wp-json/google-site-kit/v1/modules/pagespeed-insights/data/pagespeed?strategy=desktop&url=https%3A%2F%2Fmytakes.net%2F&_locale=user:1 Failed to load resource: the server responded with a status of 500 ()
2googlesitekit-api.8da02732db5b91a5377c.js:1 Google Site Kit API Error method:GET datapoint:report type:modules identifier:analytics error:"<h1>Error establishing a database connection</h1>"
(anonymous) @ googlesitekit-api.8da02732db5b91a5377c.js:1
2googlesitekit-api.8da02732db5b91a5377c.js:1 Google Site Kit API Error method:GET datapoint:pagespeed type:modules identifier:pagespeed-insights error:"<h1>Error establishing a database connection</h1>"
(anonymous) @ googlesitekit-api.8da02732db5b91a5377c.js:1
@oscarssanchez I'm going to escalate this based on the information kindly you provided and the additional insights gathered. In the meantime if you could share your current hosting provider and your Site Health information that would be great.
Feel free to share privately if preferred. You will however need to reference a WordPress support forum topic which you can create here.
Hi @jamesozzie ,
Thanks, I have filled the questionnaire.
Personally, I think the error is expected, but what perhaps is not an expected behavior is that the response(?) stored in the description
variable comes with some extra html
Let me know if I can provide more details. I'm also happy to submit a PR if you don't have the bandwidth/resources to tackle it, as It is probably not super concerning.
Many thanks for sharing your Site Health information.
Personally, I think the error is expected, but what perhaps is not an expected behavior is that the response(?) stored in the description variable comes with some extra html
Correct. I'm unsure why the tag is output but the team will review this and provide an update here. They'll also be able to provide any suggestions on a PR, appreciate your assistance on this.
One additional report, for this impacted user this is occurring within the AdSense widget:
As part of some internal testing with free hosting providers I have encountered this error message on two of my test sites hosted with Byet.host & InfinityFreeHosting. Asana task and notes for this can be found here.
In both cases these error messages appear sporadically and are usually cleared with a page refresh. Screenshots of the error messages and console errors can be seen below for both sites.
Byet.host:
InfinityFree:
@tofumatt Assigning over to you per our discussion in today's sprint planning meeting. Thank you!
More specifically, it's likely that the message in https://github.com/google/site-kit-wp/blob/eed009c134ae533e307d65390e3af84d5551a9e7/assets/js/components/ReportError.js#L51 is what's causing this issue.
In summation: the error message sent from WordPress (specifically the WP REST API) here contains an error page with <h1>Some database error</h1>
. That's the message our code is receiving and displaying—the literal "\<h1>"
string appears because React (helpfully) escapes HTML in strings by default. But we should strip HTML tags entirely from error message strings to avoid things like this happening in the future.
I've added as much to the ACs. We should be able to use DOMPurify (our instance is in https://github.com/google/site-kit-wp/blob/eed009c134ae533e307d65390e3af84d5551a9e7/assets/js/util/purify.js#L6) to sanitise HTML strings to regular strings.
Thanks, @kuasha420, but let's better update the ErrorText
component to strip tags from the incoming message
property instead of updating only the ReportError
component.
@eugene-manuilov Than it will not work when there is no reconnectUrl
. See: https://github.com/google/site-kit-wp/blob/b6da750ce6c41ba2b3740874192bdafa82573dca/assets/js/components/ReportError.js#L63-L67
This will leave out the issue raised here unfixed.
Any thoughts?
@kuasha420 ah... yes, you are right. Then let's strip tags from the message too if there is no reconnectURL. So, we need to add sanitization to both ErrorText
and ReportError
components, but for the ReportError
component we need to sanitize the error message only if there is no reconnectionURL.
@eugene-manuilov The ErrorText component already have html sanitization. I have updated the IB to only clean the message when there is no reconnectURL
. Should be good now.
Ok, you are right @kuasha420. 🤦♂️ IB ✔️
@kuasha420 @asvinb please could you suggest how we might:
Ensure tests for ReportError pass.
I've gone into the network tab and selected slow 3G and played around with Chrome settings but I am unable to trigger the reported issue. Reading through the comments if does seem that we've not been able to recreate consistently, so could be down too slow servers on free hosting. Any advice how it could be tested would be appreciated.
@asvinb could you please, help, Darren with his question?
please could you suggest how we might:
Ensure tests for ReportError pass.
I've gone into the network tab and selected slow 3G and played around with Chrome settings but I am unable to trigger the reported issue. Reading through the comments if does seem that we've not been able to recreate consistently, so could be down too slow servers on free hosting. Any advice how it could be tested would be appreciated.
Actually, I think I can help too :smile:. @wpdarren it means that all js tests should pass which has already been confirmed during code review.
@eugene-manuilov so I can assume that it's only the story for me to look at? 👍
Thanks for jumping in @eugene-manuilov . That's correct, I intentionally added the tests even though it was not mentioned in the IB just to make sure that HTML tags are stripped. So the tests passing only should be fine. And you're correct @wpdarren , that's the only story to look at.
Verified:
Checked new stories (ReportError with HTML tags) for ReportError and ensured no HTML tags are displayed.
Bug Description
It looks like the
description
https://github.com/google/site-kit-wp/blob/01e077bfd5a56039942cc010408e257cd006bbc0/assets/js/components/legacy-notifications/cta.js#L51 string comes with an<h1>
tag. This is probably taken as a literal string, but even if it wasn't It probably does not make sense to have an<h1>
inside a<p>
tagSteps to reproduce
Screenshots
Do not alter or remove anything below. The following sections will be managed by moderators only.
Acceptance criteria
Implementation Brief
In
assets/js/components/ReportError.js
:purify
fromassets/js/util/purify.js
.description
, sanitize themessage
variable only when there is noreconnectURL
, using thesanitize
method of the importedDOMPurify
instance and pass the following as options:ALLOWED_TAGS
: Empty array.description
.Test Coverage
QA Brief
Changelog entry