Page MenuHomePhabricator

'.event.query' should be string
Closed, ResolvedPublicPRODUCTION ERROR

Description

Error

message
'.event.query' should be string

Impact

There were approximately 3800 such errors in the last 24 hour period.

Notes

This is an EventGate validation error affecting the SearchSatisfaction schema, which, AFAICT, has been happening for a long time. See https://logstash.wikimedia.org/goto/b022bd7daf353e0440d0250d475af816.

At the time of writing, this error is the second-most frequent validation error:

Screenshot 2021-03-05 at 10.56.32.png (1×2 px, 414 KB)

Some paths across the Wikipedias appear to result in URLs that have multiple searchTerm parameters when coming from a SERP. If the SearchSatisfaction instrument is enabled, this results in an event with query property of type string[] and not string.

QA Steps

Scenario 1
  1. Navigate to https://wikidata.beta.wmflabs.org/
  2. Disable V2 of Vector, if you're using it
  3. Run the following in your browser's console:
localStorage.setItem( 'wmE-sS--sessionId', 'T276474' );
localStorage.setItem( 'wmE-sS--sessionIdEndTime', Date.now() + 24 * 60 * 60 * 1000 );
  1. Refresh the page
  2. Search for "foo" using the search widget in the top right-hand corner
  3. Wait for ~30s
  4. Observe that a SearchSatisfaction event has been logged with action=searchResultPage and query=foo
Scenario 2
  1. Navigate to https://en.wikipedia.beta.wmflabs.org/
  2. Disable V2 of Vector, if you're using it
  3. Run the following in your browser's console:
localStorage.setItem( 'wmE-sS--sessionId', 'T276474' );
localStorage.setItem( 'wmE-sS--sessionIdEndTime', Date.now() + 24 * 60 * 60 * 1000 );
  1. Refresh the page
  2. Search for "bar" using the search widget in the top right-hand corner
  3. Wait for ~30s
  4. Observe that a SearchSatisfaction event has been logged with action=searchResultPage and query=bar

QA Results - Beta

ACStatusDetails
1T276474#6941413
2T276474#6941413

QA Results - Prod

ACStatusDetails
1T276474#6966514
2T276474#6966514

Details

Event Timeline

What kind of error is this? From what service and program/runtime? Is this server-side EventGate validation?

phuedx updated the task description. (Show Details)
MPhamWMF moved this task from needs triage to Bugs on the Discovery-Search board.

If this is related to searchTerm than it is this code:
https://gerrit.wikimedia.org/g/mediawiki/extensions/WikimediaEvents/+/72cdfdc68a5a4cc652ae3f81ab5bb53d58fc46dc/modules/ext.wikimediaEvents/searchSatisfaction.js#547

		params = {
			query: mw.config.get( 'searchTerm' ),
			hitsReturned: $( '.results-info' ).data( 'mw-num-results-total' ),
			extraParams: JSON.stringify( serpExtras )
		};

Ending in the SearchSatisfaction event

The mw.config part is set in https://gerrit.wikimedia.org/g/mediawiki/core/+/78c1095d35bb3faf33786eadfe1717ccd141bf0e/includes/specials/SpecialSearch.php#666
but SpecialSearch::setupPage is documented to get a string. The value passed to it is running through str_replace, but that supports arrays. The string is coming from $request->getText( 'search' ) which looks safe even for array parameters on GET requests.

Thanks, @Umherirrender.

There are other code paths that set the query property of the SearchSatisfaction events:

  1. https://gerrit.wikimedia.org/g/mediawiki/extensions/WikimediaEvents/+/72cdfdc68a5a4cc652ae3f81ab5bb53d58fc46dc/modules/ext.wikimediaEvents/searchSatisfaction.js#708 for action="searchResultPage" events
  2. https://gerrit.wikimedia.org/g/mediawiki/extensions/WikimediaEvents/+/72cdfdc68a5a4cc652ae3f81ab5bb53d58fc46dc/modules/ext.wikimediaEvents/searchSatisfaction.js#508 for action="visitPage" events

Looking through a sample of EventGate validation errors, the events are action="visitPage" events, i.e. it's #2 that's setting the invalid property to the event. Unless there's a (serious?) bug with mw.Uri, then I'm inclined to think that there's two search query parameters in the referrer.

I noticed that elements of the array are the same string, i.e. the referrer looks like query=foo&query=foo. I tried searching for "foo" on wikidatawiki and was sent to a SERP with a URL like https://www.wikidata.org/w/index.php?search=foo&search=foo&title=Special%3ASearch. I don't see this on enwiki, for example.

Update

There's two fields named "search" in the Wikidata search box:

Screenshot 2021-03-09 at 17.11.18.png (104×493 px, 29 KB)

Wikidata does provide its own implementation of search. There is also evidence of a gadget that completely replaces the form that may be responsible.

Change 670815 had a related patch set uploaded (by Phuedx; owner: Phuedx):
[mediawiki/extensions/WikimediaEvents@master] searchSatisfaction: Handle edge case in referrer URLs

https://gerrit.wikimedia.org/r/670815

Wikidata does provide its own implementation of search. There is also evidence of a gadget that completely replaces the form that may be responsible.

After writing the above patch, I found that the "search" hidden input on wikidatawiki is added by https://gerrit.wikimedia.org/g/mediawiki/extensions/Wikibase/+/87e2b58c8b426c44b84d29beb4526908ce349d71/repo/resources/wikibase.ui.entitysearch.js#15. I suspect this can be removed now since it was added to work around a bug in Firefox (see T60467: Wrong smart keyword on Wikidata).

Edit

I've just tested the Firefox feature on enwiki with JavaScript disabled and it appears to be working.

Change 670815 merged by jenkins-bot:
[mediawiki/extensions/WikimediaEvents@master] searchSatisfaction: Handle edge case in referrer URLs

https://gerrit.wikimedia.org/r/670815

Test Result - Beta

Status: ✅ PASS
Environment: beta
OS: macOS Big Sur
Browser: Chrome
Device: MBP
Emulated Device: NA

Test Artifact(s):

QA Steps
Scenario 1
  1. Navigate to https://wikidata.beta.wmflabs.org/
  2. Disable V2 of Vector, if you're using it
  3. Run the following in your browser's console:
localStorage.setItem( 'wmE-sS--sessionId', 'T276474' );
localStorage.setItem( 'wmE-sS--sessionIdEndTime', Date.now() + 24 * 60 * 60 * 1000 );
  1. Refresh the page
  2. Search for "foo" using the search widget in the top right-hand corner
  3. Wait for ~30s
  4. ✅ AC1: Observe that a SearchSatisfaction event has been logged with action=searchResultPage and query=foo

Screen Shot 2021-03-24 at 6.54.01 AM.png (569×800 px, 102 KB)

Scenario 2
  1. Navigate to https://en.wikipedia.beta.wmflabs.org/
  2. Disable V2 of Vector, if you're using it
  3. Run the following in your browser's console:
localStorage.setItem( 'wmE-sS--sessionId', 'T276474' );
localStorage.setItem( 'wmE-sS--sessionIdEndTime', Date.now() + 24 * 60 * 60 * 1000 );
  1. Refresh the page
  2. Search for "bar" using the search widget in the top right-hand corner
  3. Wait for ~30s
  4. ✅ AC2: Observe that a SearchSatisfaction event has been logged with action=searchResultPage and query=bar

Screen Shot 2021-03-24 at 6.57.36 AM.png (593×730 px, 100 KB)

Edtadros subscribed.

Test Result - Prod

Status: ✅ PASS
Environment: wikidata, enwiki
OS: macOS Big Sur
Browser: Chrome
Device: MBP
Emulated Device: NA

Test Artifact(s):

QA Steps
Scenario 1
  1. Navigate to https://wikidata.org/
  2. Disable V2 of Vector, if you're using it
  3. Run the following in your browser's console:
localStorage.setItem( 'wmE-sS--sessionId', 'T276474' );
localStorage.setItem( 'wmE-sS--sessionIdEndTime', Date.now() + 24 * 60 * 60 * 1000 );
  1. Refresh the page
  2. Search for "foo" using the search widget in the top right-hand corner
  3. Wait for ~30s
  4. ✅ AC1: Observe that a SearchSatisfaction event has been logged with action=searchResultPage and query=foo

Screen Shot 2021-04-01 at 8.21.35 AM.png (568×794 px, 100 KB)

Scenario 2
  1. Navigate to https://en.wikipedia.org/wiki/Main_Page/
  2. Disable V2 of Vector, if you're using it
  3. Run the following in your browser's console:
localStorage.setItem( 'wmE-sS--sessionId', 'T276474' );
localStorage.setItem( 'wmE-sS--sessionIdEndTime', Date.now() + 24 * 60 * 60 * 1000 );
  1. Refresh the page
  2. Search for "bar" using the search widget in the top right-hand corner
  3. Wait for ~30s
  4. ✅ AC2: Observe that a SearchSatisfaction event has been logged with action=searchResultPage and query=bar

Screen Shot 2021-04-01 at 9.20.52 AM.png (571×1 px, 119 KB)

ovasileva subscribed.
Jdlrobson claimed this task.