Skip to content

Do not attempt to convert nil into PII attributes#6124

Merged
mitchellhenke merged 1 commit intomainfrom
mitchellhenke/no-nil-pii
Mar 30, 2022
Merged

Do not attempt to convert nil into PII attributes#6124
mitchellhenke merged 1 commit intomainfrom
mitchellhenke/no-nil-pii

Conversation

@mitchellhenke
Copy link
Contributor

Follow up to #6121

changelog: Bug Fixes, Account Management, Request password to decrypt PII before regenerating personal key
@mitchellhenke mitchellhenke requested a review from jmhooper March 30, 2022 15:19
@mitchellhenke mitchellhenke merged commit daf7265 into main Mar 30, 2022
@mitchellhenke mitchellhenke deleted the mitchellhenke/no-nil-pii branch March 30, 2022 15:24
mitchellhenke pushed a commit that referenced this pull request Mar 30, 2022
changelog: Bug Fixes, Account Management, Request password to decrypt PII before regenerating personal key
def recover_pii(personal_key)
encryptor = Encryption::Encryptors::PiiEncryptor.new(personal_key)
decrypted_recovery_json = encryptor.decrypt(encrypted_pii_recovery, user_uuid: user.uuid)
return nil if JSON.parse(decrypted_recovery_json).nil?
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could this have been implemented in Pii::Attributes.new_from_json to avoid double-parsing, and since we already have at least one check there already?

Here:

return new if pii_json.blank?
pii = JSON.parse(pii_json, symbolize_names: true)
new_from_hash(pii)

      return new if pii_json.blank?
      pii = JSON.parse(pii_json, symbolize_names: true)
      return new if pii.blank?
      new_from_hash(pii)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It could, yeah

The competing factor is this is so far only known to affect recovery PII, and Pii::Attributes is used in more places and this is a quicker fix, so I opted towards the smaller scope, though it should definitely be given a fuller consideration in the follow-up work.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should we have done a truthiness check? in case the value was a literal false ?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think for the specific case here the problem value is nil, but we could expand it to be anything that is not a Hash since that's really the only valid type (and we could also validate that it has the expected keys, etc. if we wanted as well)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants