excessive mysqld usage on big piwigo instances #1226

Closed
opened 2026-10-05 00:36:36 +02:00 by adam · 9 comments
Owner

adding to this forum topic:
https://piwigo.org/forum/viewtopic.php?id=31229

It seems that on some cases Piwigo goes mad and tries to do like 1.5MB mysql query (included in the attachment.)
when the url is like
https://-filtered-/picture.php?/478517
or
https://-filtered-/picture.php?/478517/categories

The picture even HAS CATEGORY, but when someone tampers with the URL and removes it there from there...

it's a 7zip file, not a zip, because github doesn't allow to upload .7z, but 7z file was like 126k, whereas actual zip was 532k.
dafuq.7z.zip

It's like serious DDOS vulnerability in Piwigo 11.4.x
And then when someone lets a crawler bot / script loose into this url that just starts "clicking" the next and previous arrow urls under there it's like game over for the site. It just kills MySQL, 100% CPU usage for hours;
When it was accidental or something, then restarting mysql service helps to stop this, until next bot comes along. Or even site own admin browsers prefetch or whatever.

adding to this forum topic: https://piwigo.org/forum/viewtopic.php?id=31229 It seems that on some cases Piwigo goes mad and tries to do like 1.5MB mysql query (included in the attachment.) when the url is like https://-filtered-/picture.php?/478517 or https://-filtered-/picture.php?/478517/categories The picture even HAS CATEGORY, but when someone tampers with the URL and removes it there from there... it's a 7zip file, not a zip, because github doesn't allow to upload .7z, but 7z file was like 126k, whereas actual zip was 532k. [dafuq.7z.zip](https://github.com/Piwigo/Piwigo/files/6444037/dafuq.7z.zip) It's like serious DDOS vulnerability in Piwigo 11.4.x And then when someone lets a crawler bot / script loose into this url that just starts "clicking" the next and previous arrow urls under there it's like game over for the site. It just kills MySQL, 100% CPU usage for hours; When it was accidental or something, then restarting mysql service helps to stop this, until next bot comes along. Or even site own admin browsers prefetch or whatever. <!-- github-sync-id:879667899 -->
adam closed this issue 2026-10-05 00:36:36 +02:00
Author
Owner

can you show us the SQL queries directly here, simply by replacing the long list of ids with "[...]" ?

can you show us the SQL queries directly here, simply by replacing the long list of ids with "[...]" ? <!-- github-comment-id:834760232 -->
Author
Owner

Hello,

I'm also experiencing this issue. When I skip to the next image it takes
very long to load the page. I switched on SQL traces and could also see a
statement with a list of many, many ids. I would be very interested in
getting this fixed.

Please let me know if you want me to do some tests and traces for you. I'm
still on 2.10.2 with my production site, but my sandbox running 11.4.0 has
the same issue and a similar amount of pictures (5k) and albums (300).

Best regards

Jens

Am 7. Mai 2021 22:12:03 schrieb D33M0N @.***>:

adding to this forum topic:
https://piwigo.org/forum/viewtopic.php?id=31229
It seems that on some cases some piwigo goes mad and tries to do like 1.5MB
mysql query (included in the attachment.)
when the url is like
https:///picture.php?/478517
or
https:///picture.php?/478517/categoriesThe picture even HAS CATEGORY, but
when someone tampers with the URL and removes it there from there...
it's a 7zip file, not a zip, because github doesn't allow to upload .7z,
but 7z file was like 126k, whereas actual zip was 532k.
dafuq.7z.zip
It's like serious DDOS vulnerability in Piwigo 11.4.x
—
You are receiving this because you are subscribed to this thread.
Reply to this email directly, view it on GitHub, or unsubscribe.

Hello, I'm also experiencing this issue. When I skip to the next image it takes very long to load the page. I switched on SQL traces and could also see a statement with a list of many, many ids. I would be very interested in getting this fixed. Please let me know if you want me to do some tests and traces for you. I'm still on 2.10.2 with my production site, but my sandbox running 11.4.0 has the same issue and a similar amount of pictures (5k) and albums (300). Best regards Jens Am 7. Mai 2021 22:12:03 schrieb D33M0N ***@***.***>: > > adding to this forum topic: > https://piwigo.org/forum/viewtopic.php?id=31229 > It seems that on some cases some piwigo goes mad and tries to do like 1.5MB > mysql query (included in the attachment.) > when the url is like > https:///picture.php?/478517 > or > https:///picture.php?/478517/categoriesThe picture even HAS CATEGORY, but > when someone tampers with the URL and removes it there from there... > it's a 7zip file, not a zip, because github doesn't allow to upload .7z, > but 7z file was like 126k, whereas actual zip was 532k. > dafuq.7z.zip > It's like serious DDOS vulnerability in Piwigo 11.4.x > — > You are receiving this because you are subscribed to this thread. > Reply to this email directly, view it on GitHub, or unsubscribe. <!-- github-comment-id:834784433 -->
Author
Owner

can you show us the SQL queries directly here, simply by replacing the long list of ids with "[...]" ?



[1] 
SELECT @@SESSION.sql_mode
(this query time : 0.000 s)
(total SQL time  : 0.000 s)
(total time      : 0.001 s)
(num rows        : 1 )

[2] 

SELECT param, value
 FROM config
 
;
(this query time : 0.000 s)
(total SQL time  : 0.000 s)
(total time      : 0.001 s)
(num rows        : 96 )

[3] 

SELECT data
  FROM sessions
  WHERE id = 'BC00ittjaljbss6q9d4ofm69g3rab2'
;
(this query time : 0.000 s)
(total SQL time  : 0.000 s)
(total time      : 0.001 s)
(num rows        : 1 )

[4] 

SELECT * FROM plugins
  WHERE state='active'
(this query time : 0.000 s)
(total SQL time  : 0.000 s)
(total time      : 0.002 s)
(num rows        : 4 )

[5] 

SELECT id AS id
     , username AS username
     , password AS password
     , mail_address AS email
  FROM users
  WHERE id = '51'
(this query time : 0.000 s)
(total SQL time  : 0.001 s)
(total time      : 0.003 s)
(num rows        : 1 )

[6] 

SELECT
    ui.*,
    uc.*,
    t.name AS theme_name
  FROM user_infos AS ui
    LEFT JOIN user_cache AS uc ON ui.user_id = uc.user_id
    LEFT JOIN themes AS t ON t.id = ui.theme
  WHERE ui.user_id = 51
;
(this query time : 0.000 s)
(total SQL time  : 0.001 s)
(total time      : 0.003 s)
(num rows        : 1 )

[7] 

SELECT *
  FROM user_infos
  WHERE user_id = 2
;
(this query time : 0.000 s)
(total SQL time  : 0.001 s)
(total time      : 0.003 s)
(num rows        : 1 )

[8] 

SELECT id,uppercats,commentable,visible,status,global_rank
  FROM image_category
    INNER JOIN categories ON category_id = id
  WHERE image_id = 478517
AND (id NOT IN (53143,53186,53308,53983,54195,54236,54237,54238,54239,54240,54241,54242,54243,54244,54245,54246,54247,54248,54249,54250,54251,54252,54253,54254,54255,54256,54257,54258,54259,54260,54261,54262,54263,54264,54265,54266,54267,54268,54269,54270,54271,54272,54273,54274,54275,54276,54277,54278,54279,54280,54281,54282,54283,54284,54285,54286,54287,54288,54289,54290,54291,54292,54820,55482,56054,56210,56244,57826,57911,59738))
;
(this query time : 0.000 s)
(total SQL time  : 0.001 s)
(total time      : 0.032 s)
(num rows        : 1 )

[9] 

SELECT *
  FROM images
  WHERE id IN (478517,478516,413509,478518,326189)
;
(this query time : 0.000 s)
(total SQL time  : 0.001 s)
(total time      : 0.033 s)
(num rows        : 5 )

[10] 

SELECT t.*, count(*) AS counter
  FROM image_tag
    INNER JOIN tags t ON tag_id = id
  WHERE image_id IN (478517)
  GROUP BY t.id
  ORDER BY NULL
(this query time : 0.000 s)
(total SQL time  : 0.001 s)
(total time      : 0.033 s)
(num rows        : 0 )

[11] 

SELECT id, name, permalink
  FROM categories
  WHERE id IN (60287)
(this query time : 0.000 s)
(total SQL time  : 0.001 s)
(total time      : 0.033 s)
(num rows        : 1 )

[12] 

SELECT 
  id, name, permalink, nb_images, global_rank,
  date_last, max_date_last, count_images, count_categories
FROM categories INNER JOIN user_cache_categories
  ON id = cat_id and user_id = 51
WHERE 
(id_uppercat is NULL)
;
(this query time : 0.027 s)
(total SQL time  : 0.028 s)
(total time      : 0.077 s)
(num rows        : 4219 )

[13] 

SELECT
    c.id,
    c.uppercats,
    count(*) AS counter
  FROM image_category
    INNER JOIN categories c ON category_id = id
  WHERE image_id IN (ABSURDLY_MASSIVE_LIST_OF_EVERY_PICTURE_ID)
    AND (category_id NOT IN (53143,53186,53308,53983,54195,54236,54237,54238,54239,54240,54241,54242,54243,54244,54245,54246,54247,54248,54249,54250,54251,54252,54253,54254,54255,54256,54257,54258,54259,54260,54261,54262,54263,54264,54265,54266,54267,54268,54269,54270,54271,54272,54273,54274,54275,54276,54277,54278,54279,54280,54281,54282,54283,54284,54285,54286,54287,54288,54289,54290,54291,54292,54820,55482,56054,56210,56244,57826,57911,59738))
  GROUP BY c.id
  ORDER BY NULL
(this query time : 23.292 s)
(total SQL time  : 23.320 s)
(total time      : 23.403 s)
(num rows        : 5502 )

[14] 

SELECT
    id,
    name,
    permalink,
    id_uppercat,
    uppercats,
    global_rank
  FROM categories
  WHERE id IN (ANOTHER_LONG_LIST_but_much_smaller)
;
(this query time : 0.011 s)
(total SQL time  : 23.331 s)
(total time      : 23.428 s)
(num rows        : 5756 )

[15] 

SELECT mail_address
  FROM users
  WHERE id = 1
;
(this query time : 0.000 s)
(total SQL time  : 23.331 s)
(total time      : 23.526 s)
(num rows        : 1 )

> can you show us the SQL queries directly here, simply by replacing the long list of ids with "[...]" ? ``` [1] SELECT @@SESSION.sql_mode (this query time : 0.000 s) (total SQL time : 0.000 s) (total time : 0.001 s) (num rows : 1 ) [2] SELECT param, value FROM config ; (this query time : 0.000 s) (total SQL time : 0.000 s) (total time : 0.001 s) (num rows : 96 ) [3] SELECT data FROM sessions WHERE id = 'BC00ittjaljbss6q9d4ofm69g3rab2' ; (this query time : 0.000 s) (total SQL time : 0.000 s) (total time : 0.001 s) (num rows : 1 ) [4] SELECT * FROM plugins WHERE state='active' (this query time : 0.000 s) (total SQL time : 0.000 s) (total time : 0.002 s) (num rows : 4 ) [5] SELECT id AS id , username AS username , password AS password , mail_address AS email FROM users WHERE id = '51' (this query time : 0.000 s) (total SQL time : 0.001 s) (total time : 0.003 s) (num rows : 1 ) [6] SELECT ui.*, uc.*, t.name AS theme_name FROM user_infos AS ui LEFT JOIN user_cache AS uc ON ui.user_id = uc.user_id LEFT JOIN themes AS t ON t.id = ui.theme WHERE ui.user_id = 51 ; (this query time : 0.000 s) (total SQL time : 0.001 s) (total time : 0.003 s) (num rows : 1 ) [7] SELECT * FROM user_infos WHERE user_id = 2 ; (this query time : 0.000 s) (total SQL time : 0.001 s) (total time : 0.003 s) (num rows : 1 ) [8] SELECT id,uppercats,commentable,visible,status,global_rank FROM image_category INNER JOIN categories ON category_id = id WHERE image_id = 478517 AND (id NOT IN (53143,53186,53308,53983,54195,54236,54237,54238,54239,54240,54241,54242,54243,54244,54245,54246,54247,54248,54249,54250,54251,54252,54253,54254,54255,54256,54257,54258,54259,54260,54261,54262,54263,54264,54265,54266,54267,54268,54269,54270,54271,54272,54273,54274,54275,54276,54277,54278,54279,54280,54281,54282,54283,54284,54285,54286,54287,54288,54289,54290,54291,54292,54820,55482,56054,56210,56244,57826,57911,59738)) ; (this query time : 0.000 s) (total SQL time : 0.001 s) (total time : 0.032 s) (num rows : 1 ) [9] SELECT * FROM images WHERE id IN (478517,478516,413509,478518,326189) ; (this query time : 0.000 s) (total SQL time : 0.001 s) (total time : 0.033 s) (num rows : 5 ) [10] SELECT t.*, count(*) AS counter FROM image_tag INNER JOIN tags t ON tag_id = id WHERE image_id IN (478517) GROUP BY t.id ORDER BY NULL (this query time : 0.000 s) (total SQL time : 0.001 s) (total time : 0.033 s) (num rows : 0 ) [11] SELECT id, name, permalink FROM categories WHERE id IN (60287) (this query time : 0.000 s) (total SQL time : 0.001 s) (total time : 0.033 s) (num rows : 1 ) [12] SELECT id, name, permalink, nb_images, global_rank, date_last, max_date_last, count_images, count_categories FROM categories INNER JOIN user_cache_categories ON id = cat_id and user_id = 51 WHERE (id_uppercat is NULL) ; (this query time : 0.027 s) (total SQL time : 0.028 s) (total time : 0.077 s) (num rows : 4219 ) [13] SELECT c.id, c.uppercats, count(*) AS counter FROM image_category INNER JOIN categories c ON category_id = id WHERE image_id IN (ABSURDLY_MASSIVE_LIST_OF_EVERY_PICTURE_ID) AND (category_id NOT IN (53143,53186,53308,53983,54195,54236,54237,54238,54239,54240,54241,54242,54243,54244,54245,54246,54247,54248,54249,54250,54251,54252,54253,54254,54255,54256,54257,54258,54259,54260,54261,54262,54263,54264,54265,54266,54267,54268,54269,54270,54271,54272,54273,54274,54275,54276,54277,54278,54279,54280,54281,54282,54283,54284,54285,54286,54287,54288,54289,54290,54291,54292,54820,55482,56054,56210,56244,57826,57911,59738)) GROUP BY c.id ORDER BY NULL (this query time : 23.292 s) (total SQL time : 23.320 s) (total time : 23.403 s) (num rows : 5502 ) [14] SELECT id, name, permalink, id_uppercat, uppercats, global_rank FROM categories WHERE id IN (ANOTHER_LONG_LIST_but_much_smaller) ; (this query time : 0.011 s) (total SQL time : 23.331 s) (total time : 23.428 s) (num rows : 5756 ) [15] SELECT mail_address FROM users WHERE id = 1 ; (this query time : 0.000 s) (total SQL time : 23.331 s) (total time : 23.526 s) (num rows : 1 ) ``` <!-- github-comment-id:834818841 -->
Author
Owner

Might as well add, that for now I am using a safeguard in my MariaDB /etc/mysql/my.cnf under [mysqld] section:
max_statement_time = 5

(for actual MySQL you need to use max_execution_time = 5000 instead (mysql value in milliseconds, whereas in MariaDB in seconds)

Might as well add, that for now I am using a safeguard in my MariaDB `/etc/mysql/my.cnf` under `[mysqld]` section: `max_statement_time = 5` (for actual MySQL you need to use `max_execution_time = 5000` instead (mysql value in milliseconds, whereas in MariaDB in seconds) <!-- github-comment-id:834825170 -->
Author
Owner

in [Admin>Configuration>Menu] deactivate the
« related albums » menu for all user status.

Pierrick LE GALL

in [Admin>Configuration>Menu] deactivate the « related albums » menu for all user status. -- Pierrick LE GALL <!-- github-comment-id:835247912 -->
Author
Owner

in [Admin>Configuration>Menu] deactivate the
« related albums » menu for all user status.

Thank you!

You can't "deactivate" it, but only hide it?
I mean, am I in the right spot -- admin.php?page=menubar
Configuration -> Menus -> Related albums (mbRelatedCategories) -> Hide [ v ] (checkbox)

> in [Admin>Configuration>Menu] deactivate the > « related albums » menu for all user status. Thank you! You can't "deactivate" it, but only hide it? I mean, am I in the right spot -- admin.php?page=menubar Configuration -> Menus -> Related albums (mbRelatedCategories) -> Hide [ v ] (checkbox) <!-- github-comment-id:835327209 -->
Author
Owner

Yes, "hide" is the same as "deactivate".

I think you have asked Piwigo to show the menubar on the page of the photo, meaning Piwigo will calculate the related albums. If you (or a robot) use the canonical URL:

<link rel=canonical href="picture.php?/4">

Then Piwigo will search related albums to ALL photos of the gallery (because you're not in an album or in a tag...) and that makes a huge SQL query, very long to compute. That is directly related to #1392

Yes, "hide" is the same as "deactivate". I think you have asked Piwigo to show the menubar on the page of the photo, meaning Piwigo will calculate the related albums. If you (or a robot) use the canonical URL: ``` <link rel=canonical href="picture.php?/4"> ``` Then Piwigo will search related albums to ALL photos of the gallery (because you're not in an album or in a tag...) and that makes a huge SQL query, very long to compute. That is directly related to #1392 <!-- github-comment-id:838148372 -->
Author
Owner

I think Piwigo should even not compute the related albums on the picture.php page. It's not useful at this point.

I think Piwigo should even not compute the related albums on the picture.php page. It's not useful at this point. <!-- github-comment-id:841117047 -->
Author
Owner

related to #1392

related to #1392 <!-- github-comment-id:1081913622 -->
Sign in to join this conversation.
No labels
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: adam/Piwigo#1226