Page MenuHomePhabricator

Unexpected "isTrusted" value showing up in some author diff output
Closed, ResolvedPublicBUG REPORT

Description

This has been seen by both @Slst2020 and @bd808 in local testing of T301206: Structured diff UI assumes all members are scalars or arrays:

Screenshot 2022-02-16 at 11.46.24.png (1,982×768 px, 117 KB)

It is currently a mystery where this isTrusted attribute is coming from. git grep isTrusted returns no hits in the entire project. Is it added to the backend response somehow on the UI side? Is it in the API response via currently unexplained means?

Event Timeline

I think this value is actually starts on UI side when creating a new author value and then it is accepted on the backend. Once that happens it is reflected from the backend. I need to do a bit of deeper digging to prove this, but I can already verify seeing isTrusted: true as part of the PUT payload sent from the frontend to the backend when adding a new author.

Things to investigate:

  • How are we serializing the author in js and does that add the unexpected value?
  • How can the backend ensure that unexpected keys are either silently discarded or raise an error?

Things to investigate:

  • How are we serializing the author in js and does that add the unexpected value?

It is not a serialization problem. The isTrusted property is added by the watch of authorEdit. When the dialog is shown as a result of clicking the parent widget the value of newVal.author in the watch callback is an Event object giving the click event information. This object has an isTrusted=true property which then gets copied into this.authorFields via the object merge (this.authorFields = { ...this.authorFields, ...newVal.author }). When the dialog is shown as a result of clicking a chip, an existing author object is passed instead of the Event.

Adding !( newVal.author instanceof Event ) to the existing guard conditions prevents the unwanted property copying. The caller in InputWidget can also be changed to explicitly pass a null initial value instead of letting the event propagate in as the implicit argument (@click="addAuthor( null )" instead of @click="addAuthor").

bd808 changed the task status from Open to In Progress.Feb 18 2022, 12:34 AM
bd808 claimed this task.
bd808 triaged this task as Medium priority.
bd808 moved this task from Backlog to In Progress on the Toolhub board.

Change 763628 had a related patch set uploaded (by BryanDavis; author: Bryan Davis):

[wikimedia/toolhub@main] ui: protect against adding extra 'isTrusted' property to authors

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

Change 763628 merged by jenkins-bot:

[wikimedia/toolhub@main] ui: protect against adding extra 'isTrusted' property to authors

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

I want to follow up on figuring out why the extra 'isTrusted' property passed through the API's serializer and into the database. I would have expected it to either be stripped out by the serializer or raise an error.

I want to follow up on figuring out why the extra 'isTrusted' property passed through the API's serializer and into the database. I would have expected it to either be stripped out by the serializer or raise an error.

ok, yes the behaviour was enabled by a double bug

I want to follow up on figuring out why the extra 'isTrusted' property passed through the API's serializer and into the database. I would have expected it to either be stripped out by the serializer or raise an error.

The answer here is that the JSON Schema validation is working to spec, but that the spec behavior is different than my expectation. Per the upstream documentation, there are two settings that can be used to disallow properties that do not match any of the declared property names for an object, and by default any additional properties are allowed.

I am going to close this issue as resolved, and also open a new issue about adding "additionalProperties": false to various object fields in the toolinfo.json spec.

Change 770638 had a related patch set uploaded (by BryanDavis; author: Bryan Davis):

[operations/deployment-charts@master] toolhub: Bump container version to 2022-03-15-002555-production

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

Change 770638 merged by jenkins-bot:

[operations/deployment-charts@master] toolhub: Bump container version to 2022-03-15-002555-production

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