fix: don't save a masked custom field over the secret it stands for - #861
Merged
Conversation
A custom field of type password is rendered with `value="***"` when the viewer lacks CUSTOMFIELD_VIEW_PASS (aux-customfields.inc), and the browser posts that back verbatim whenever the form is saved without the field being touched. Nothing on the save path recognised it, so the mask was encrypted and stored over the real value — which is not recoverable. The consequence is not limited to custom field forms. Every item that carries custom fields goes through this trait, so editing anything at all about an account, user, client, category, group, profile or auth token destroyed every custom field secret on it that the editor was not allowed to see. The editor got no indication: the save succeeded, and the field still showed `***` afterwards, because that is what it now contained. The rule was already settled here. ConfigLdap, ConfigGeneral and ConfigMail each refuse the same value on the way in before saving a password, and the mask itself already has a name — CustomField::MASKED — used by the API adapter that produces it. This applies it at the door that had never been given it, comparing against that constant rather than a fourth copy of the literal. Both paths are guarded, not just the update. A copy is created rather than updated, and the copy form is prefilled from the original, so a secret the copier may not see arrives at the create path masked and would become the new item's stored value. The cost is that a custom field cannot deliberately be set to exactly three asterisks. That is the trade the three config forms already make. Checked by removing both guards: all three new tests fail. The first attempt at the create test did not — it asserted on updateOrCreate, which is the update path's method; the create path calls create(). It is included as written now, asserting the method that is actually reached, and the third test pins that the fields either side of a masked one are still saved, so a guard that dropped everything would not satisfy these.
This file contains hidden or 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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
A custom field of type password is rendered with
value="***"when the viewer lacksCUSTOMFIELD_VIEW_PASS (aux-customfields.inc), and the browser posts that back verbatim
whenever the form is saved without the field being touched. Nothing on the save path
recognised it, so the mask was encrypted and stored over the real value — which is not
recoverable.
The consequence is not limited to custom field forms. Every item that carries custom
fields goes through this trait, so editing anything at all about an account, user,
client, category, group, profile or auth token destroyed every custom field secret on
it that the editor was not allowed to see. The editor got no indication: the save
succeeded, and the field still showed
***afterwards, because that is what it nowcontained.
The rule was already settled here. ConfigLdap, ConfigGeneral and ConfigMail each refuse
the same value on the way in before saving a password, and the mask itself already has
a name — CustomField::MASKED — used by the API adapter that produces it. This applies
it at the door that had never been given it, comparing against that constant rather
than a fourth copy of the literal.
Both paths are guarded, not just the update. A copy is created rather than updated, and
the copy form is prefilled from the original, so a secret the copier may not see arrives
at the create path masked and would become the new item's stored value.
The cost is that a custom field cannot deliberately be set to exactly three asterisks.
That is the trade the three config forms already make.
Checked by removing both guards: all three new tests fail. The first attempt at the
create test did not — it asserted on updateOrCreate, which is the update path's method;
the create path calls create(). It is included as written now, asserting the method that
is actually reached, and the third test pins that the fields either side of a masked one
are still saved, so a guard that dropped everything would not satisfy these.