Recurring incorrect string value in useragent causing PHP fatal errors
#1
We have seen a gigantic uptick in PHP fatal errors caused in the forum code due to 'bad' characters in the useragent, which is used in the session manager in MyBB. We tried to wrap the forum in cloudflare with "Under Attack" mode on, thinking they are garbage bots, but it has not stopped anything. So we don't understand why now, after all this time with MyBB, this is happening.


MyBB forum version 1.8.39
PHP 8.1.33
SQL Engine MySQLi 8.0.43
Mysql tables setup as utf8mb4, InnoDB

The continuous errors logged:

PHP Fatal error:  Uncaught mysqli_sql_exception: Incorrect string value: '\xC0\xA7\xC0\xA2%2...' for column 'useragent' at row 1 in /htdocs/forum/inc/db_mysqli.php:335


The stack trace:

Stack trace:
#0 /htdocs/forum/inc/db_mysqli.php(335): mysqli_query()
#1 /htdocs/forum/inc/db_mysqli.php(378): DB_MySQLi->query()
#2 /htdocs/forum/inc/db_mysqli.php(956): DB_MySQLi->write_query()
#3 /htdocs/forum/inc/class_session.php(522): DB_MySQLi->update_query()
#4 /htdocs/forum/inc/class_session.php(415): session->update_session()
#5 /htdocs/forum/inc/class_session.php(116): session->load_guest()
#6 /htdocs/forum/global.php(49): session->init()
#7 /htdocs/forum/showthread.php(28): require_once('...')
#8 {main}
  thrown in /htdocs/forum/inc/db_mysqli.php on line 335
Reply
#2
What about this one?
-Ben
Reply
#3
I have not been able to look into figuring out a way to safely, or properly, clean the useragent string on a global level so that this sort of thing doesn't even reach MyBB. Its invalid binary which has no place in a useragent, so clearly its malicious in nature.
Reply
#4
Maybe related :
https://stackoverflow.com/a/47672108
Send me a DM or PM if you want to sponsor any update or addition to my plugins.

[Image: signature.png]

Discord omar.gonzalez (Omar G.#6117); Telegram at @omarugc;
Reply
#5
Ultimately, it would seem that the code allows much freedom to what the $_SERVER['HTTP_USER_AGENT'] is allowed to pass over.
https://github.com/mybb/mybb/blob/a79d62...on.php#L62
Send me a DM or PM if you want to sponsor any update or addition to my plugins.

[Image: signature.png]

Discord omar.gonzalez (Omar G.#6117); Telegram at @omarugc;
Reply
#6
(2025-11-23, 06:56 AM)Omar G. Wrote: Maybe related :
https://stackoverflow.com/a/47672108


Yeah. Thats where I was spiraling on coming up with a clean solution, when sometimes its actually not malicious, its just some weird browser agent adding something that isn't typically there.

However in our logged cases above, those bytes it was trying to do, weren't the case of just and umlaut, or other accent character. As xC0 is a forbidden control character if I'm not mistaken.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)