Laravel-auditing: Getting: String data, right truncated: 1406 Data too long for column 'user_agent'

Created on 29 Nov 2017  路  10Comments  路  Source: owen-it/laravel-auditing

| Q | A
| ----------------- | ---
| Bug? | yes
| New Feature? | no
| Framework | Laravel
| Framework version | 5.5
| Package version | 4.1
| PHP version | 7.1

Actual Behaviour

When a user with a long User Agent string creates an auditable event, we get an Exception. Redacted some elements:

SQLSTATE[22001]: String data, right truncated: 1406 Data too long for column 'user_agent' at row 1 (SQL: insert into audits (old_values, new_values, event, auditable_id, auditable_type, user_id, url, ip_address, user_agent, updated_at, created_at) values ([], {"name":"[REDACTED]","first_name":"[REDACTED]","middle_name":"[REDACTED]","last_name":"[REDACTED]","email":"[REDACTED]","password":"[REDACTED]","status_code":"[REDACTED]","tfa":"[REDACTED]","id":[REDACTED]}, created, [REDACTED], AppUser, , https://[REDACTED]/register, [IP ADDRESS REDACTED], Mozilla/5.0 (iPhone; CPU iPhone OS 11_0_1 like Mac OS X) AppleWebKit/604.1.38 (KHTML, like Gecko) Mobile/15A402 [FBAN/FBIOS [REDACTED 39 CHARACTERS] iPhone9,4;FBMD/iPhone;FBSN/iOS;FBSV/11.0.1;FBSS/3;FBCR/vodaAU;FBID/phone;FBLC/en_GB;FBOP/5;FBRV/0], 2017-11-30 07:49:05, 2017-11-30 07:49:05))

Expected Behaviour

Expecting this to store correctly or for the column :D

Steps to Reproduce

  1. Install Auditing
  2. Pray for a user with a long User Agent string

Possible Solutions

Increase column's allowable length

Most helpful comment

This also occurs in cases where you need LONGTEXT but have only declared TEXT for the column type.

What the fuck are you using for an user agent, a string with all the passages from the bible?

All 10 comments

Update your table?

Thanks, I already did this and it of course solved the problem. I'm only reporting it for other people's sake :D

This issue with the user agent is now referenced in the Audit Migration section.

This also occurs in cases where you need LONGTEXT but have only declared TEXT for the column type.

This also occurs in cases where you need LONGTEXT but have only declared TEXT for the column type.

What the fuck are you using for an user agent, a string with all the passages from the bible?

I've set the column up as LONGTEXT and am still getting this error. It happens occasionally when people use mobile devices.

I've set the column up as LONGTEXT and am still getting this error. It happens occasionally when people use mobile devices.

According to this, the LONGTEXT type on MySQL is supposed to be able to store 4GB (FOUR GIGABYTES!) of text. So how on earth do you get such error, specially on mobile, where connections are usually shit?

The 64KB the TEXT type holds should be more than enough, given that most web servers will have a limit for the size of the HTTP headers, which goes below 64KB. And if you consider that only the User-Agent header is being stored and not the whole bunch, well...

Check your DB schema first, because what you're reporting makes no sense.

@quetzyg I agree that it doesn't make sense, but its happening lol.

screen shot 2018-09-21 at 8 31 21 am

Here is the user agent thats showing up in the error. I assume this isn't even all of it.

Mozilla/5.0 (iPhone; CPU iPhone OS 11_4_1 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) Mobile/15G77 [FBAN/FBIOS;FBAV/180.0.0.37.85;FBBV/116915501;FBDV/iPhone8,4;FBMD/iPhone;FBSN/iOS;FBSV/11.4.1;FBSS/2;FBCR/T-Mobile;FBID/phone;FBLC/en_US;FBOP/5;FBRV/0]

Wrong table/database? In any case, I'm unable to reproduce such issue.

@quetzyg lol I only have one production database. Like I said it only occurs once in a blue moon and only on mobile devices. The lady that it happened to today couldn't log in today because of it so I ended up removing it for now.

Was this page helpful?
0 / 5 - 0 ratings