SQL Injection 'may' be possible through filenames #504

Closed
opened 2026-10-05 00:01:31 +02:00 by adam · 3 comments
Owner

Hello, I thought I'd let you know of a problem I just encountered.

While my suggestion is a long shot, I had the following set of errors while attempting to do a "Database synchronisation with files: ./galleries/"

Warnings from the program.

[./galleries/all_low/29_Tel_Beit_She'an_(Decapolis)] PWG-UPDATE-1 (wrong filename)
[./galleries/all_low/51_Hezekiah's_Tunnel] PWG-UPDATE-1 (wrong filename)
[./galleries/all_low/73_Pre-Dinner_stop_(Al_Hasa,_Jordan)] PWG-UPDATE-1 (wrong filename)
[./galleries/all_low/Items_From_31_Qasr_El_Yahud_(Jordan_Baptism_Site)] PWG-UPDATE-1 (wrong filename)
[./galleries/all_low/Items_From_31_Qasr_El_Yahud_(Jordan_Baptism_Site)/31_Qasr_El_Yahud_(Jordan_Baptism_Site)] PWG-UPDATE-1 (wrong filename)

The actual SQL Error:

Warning: [mysql error 1064] You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near 'an_(Decapolis)/2016_09_18_-_Day_06/2016-09-18_20160918_055416.jpg',NULL,'286','1' at line 1084


INSERT  INTO piwigo_images
  (id,file,name,date_available,path,representative_ext,storage_category_id,added_by)
  VALUES('713','2016-09-13_0K3A0165.jpg','2016-09-13 0K3A0165','2016-10-28 15:12:51','./galleries/all_low/00_Transit/2016_09_13_-_Day_01/2016-09-13_0K3A0165.jpg',NULL,'331','1')
  , ('714','2016-09-13_0K3A0167.jpg','2016-09-13 0K3A0167','2016-10-28 15:12:51','./galleries/all_low/00_Transit/2016_09_13_-_Day_01/2016-09-13_0K3A0167.jpg',NULL,'331','1')
  , ('715','2016-09-13_20160913_145837.jpg','2016-09-13 20160913 145837','2016-10-28 15:12:51','./galleries/all_low/00_Transit/2016_09_13_-_Day_01/2016-09-13_20160913_145837.jpg',NULL,'331','1')
  , ('716','2016-09-13_20160913_153852_HDR.jpg','2016-09-13 20160913 153852 HDR','2016-10-28 15:12:51','./galleri in /var/www/html/a_server.com/public_html/israel/gallery/include/dblayer/functions_mysqli.inc.php on line 832

While the DB entry didn't go through because the file had an ' in it as did another prior also, it seems that this isn't being detected early enough, and it still tried to push in through the DB, yet failed. So it seems the query failed, because it there was an error in the structure of the query. My guess is it shouldn't have even got the filename to the query in the first place, or it should have at least been escaped.

Just my thoughts.

Using Piwigo 2.8.2.

Hello, I thought I'd let you know of a problem I just encountered. While my suggestion is a long shot, I had the following set of errors while attempting to do a "Database synchronisation with files: ./galleries/" Warnings from the program. ``` [./galleries/all_low/29_Tel_Beit_She'an_(Decapolis)] PWG-UPDATE-1 (wrong filename) [./galleries/all_low/51_Hezekiah's_Tunnel] PWG-UPDATE-1 (wrong filename) [./galleries/all_low/73_Pre-Dinner_stop_(Al_Hasa,_Jordan)] PWG-UPDATE-1 (wrong filename) [./galleries/all_low/Items_From_31_Qasr_El_Yahud_(Jordan_Baptism_Site)] PWG-UPDATE-1 (wrong filename) [./galleries/all_low/Items_From_31_Qasr_El_Yahud_(Jordan_Baptism_Site)/31_Qasr_El_Yahud_(Jordan_Baptism_Site)] PWG-UPDATE-1 (wrong filename) ``` The actual SQL Error: `Warning: [mysql error 1064] You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near 'an_(Decapolis)/2016_09_18_-_Day_06/2016-09-18_20160918_055416.jpg',NULL,'286','1' at line 1084` ``` INSERT INTO piwigo_images (id,file,name,date_available,path,representative_ext,storage_category_id,added_by) VALUES('713','2016-09-13_0K3A0165.jpg','2016-09-13 0K3A0165','2016-10-28 15:12:51','./galleries/all_low/00_Transit/2016_09_13_-_Day_01/2016-09-13_0K3A0165.jpg',NULL,'331','1') , ('714','2016-09-13_0K3A0167.jpg','2016-09-13 0K3A0167','2016-10-28 15:12:51','./galleries/all_low/00_Transit/2016_09_13_-_Day_01/2016-09-13_0K3A0167.jpg',NULL,'331','1') , ('715','2016-09-13_20160913_145837.jpg','2016-09-13 20160913 145837','2016-10-28 15:12:51','./galleries/all_low/00_Transit/2016_09_13_-_Day_01/2016-09-13_20160913_145837.jpg',NULL,'331','1') , ('716','2016-09-13_20160913_153852_HDR.jpg','2016-09-13 20160913 153852 HDR','2016-10-28 15:12:51','./galleri in /var/www/html/a_server.com/public_html/israel/gallery/include/dblayer/functions_mysqli.inc.php on line 832 ``` While the DB entry didn't go through because the file had an ' in it as did another prior also, it seems that this isn't being detected early enough, and it still tried to push in through the DB, yet failed. So it seems the query failed, because it there was an error in the structure of the query. My guess is it shouldn't have even got the filename to the query in the first place, or it should have at least been escaped. Just my thoughts. Using Piwigo 2.8.2. <!-- github-sync-id:185836256 -->
adam closed this issue 2026-10-05 00:01:31 +02:00
Author
Owner

As per the screen shot.
screen shot 2016-10-28 at 15 29 30

As per the screen shot. ![screen shot 2016-10-28 at 15 29 30](https://cloud.githubusercontent.com/assets/5615487/19795035/7dae6e8a-9d23-11e6-8cb0-5c5766d0c5fd.png) <!-- github-comment-id:256833910 -->
Author
Owner

related to #250

related to #250 <!-- github-comment-id:1200120774 -->
Author
Owner
Fixed by https://github.com/Piwigo/Piwigo/commit/e8bef0cf23d1a1549de17f9c9598333bf78bd29f while fixing #250 <!-- github-comment-id:1243686926 -->
Sign in to join this conversation.
No labels
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: adam/Piwigo#504