verbb / formie

The most user-friendly forms plugin for Craft CMS.
Other
94 stars 72 forks source link

Encrypted Field Data Too Long #2036

Open joelzerner opened 4 weeks ago

joelzerner commented 4 weeks ago

Describe the bug

I've noticed this error occurring after updating to v2.1.26 - when submitting a phone number to an encrypted field, the encrypted data that's trying to save to the database is too long for the VARCHAR field at 255 characters. For now I've manually boosted this to 500 to avoid errors. I've done this for the encrypted email field too. Is 255 the intended length for an encrypted field? Should we increase this to avoid the errors? Happy to provide further details if needed.

SQLSTATE[22001]: String data, right truncated: 1406 Data too long for column 'field_phone_qdxwmyno' at row 1

Steps to reproduce

  1. Create a form with an encrypted phone number field
  2. Test form submission with a phone number between 12-15 digits/characters long

Form settings

Craft CMS version

4.11.4

Plugin version

2.1.26

Multi-site?

No

Additional context

No response

engram-design commented 4 weeks ago

For now, I'd recommend setting the enableLargeFieldStorage configuration setting that will bump up the column to TEXT.

However, what's a bit odd is that we already have this handling setup for when you use content encryption.

joelzerner commented 4 weeks ago

Thanks. I may be missing it in an obvious spot but I cannot find the enableLargeFieldStorage setting on the page you linked to or anywhere when searching the docs?

Ok, if you've already got the field conversion to text handled for content encryption then I'm happy to see this as a one-off random occurrence and I will just update them manually.

engram-design commented 4 weeks ago

It's more of a hidden setting at the moment, as it's been removed in Formie 3 for Craft 5 (it's no longer required), but it's not going anywhere for Formie 2/Craft 4.

But yes, re-saving the form should re-save each field, and update the content column used. But it should've done that anyway when you saved the form with the content encryption. Unless this was a recent upgrade and the field hasn't been updated for some time.

joelzerner commented 4 weeks ago

We were running v2.1.3 previously and only just updated to v2.1.26 yesterday, so that may explain it?

I tried re-saving a form with an encrypted field and checked to see if it had automatically updated the table column but it was still a VARCHAR not a TEXT unfortunately.

engram-design commented 3 weeks ago

I don't believe there's been any changes since then, so you should be all good on that front.

So that's odd behaviour. I've created a new form, and toggling on/off the "Enable Content Encryption" setting is changing the column in the content table from TEXT to VARCHAR as I'd expect (I don't have enableLargeFieldStorage enabled just for testing). You're not seeing that? What's your database engine and version?

joelzerner commented 3 weeks ago

MariaDB 11.5.2 I did the same on a form with two encrypted fields - email and phone. I converted them back to normal fields and saved the form. They were both VARCHAR. Then I converted them back to encrypted fields and saved the form. Email is still VARCHAR but Phone has changed to TEXT.

engram-design commented 3 weeks ago

Right, so Phone fields are working now, but not Email fields. We have the very same handling setup for all fields, including an Email field, so I'm not sure what's going on there...

joelzerner commented 3 weeks ago

All good. I'm happy to leave it and I can do it manually. It seems it's set up correctly in the codebase!