r/PHPhelp • u/aliosayle • Feb 08 '25
Security issue with script to fetch data dynamically
Hi,
I'm working on a PHP script to serve as a unified script for all frontend table pages. It functions in a way that the frontend sends the table name and column names, and the backend script then retrieves the data. This approach avoids loading all the data at once, which can be time-consuming for large datasets. The script also supports search and conditional queries.
I posted this on r/php for assistance, but I was informed that the script has several security vulnerabilities. The post request can be intercepted, allowing users to query any table they desire. I'm hoping someone can help me address these issues.
Here's the GitHub repository for the project: https://github.com/aliosayle/php-datatable-with-backed-processing.git
View all comments
1
u/colshrapnel Feb 08 '25
I would also suggest some minor improvements
In the error reporting section, another option has to be added and its value should be changed depends on the environment, 0 in production and 1 in development
The following code code makes no sense and could be safely removed.
log('debug', $searchBuilder);instead offile_put_contents(__DIR__ . '/search_builder.log', print_r($searchBuilder, return: true));. Also you can check a DEBUG constant inside this function to disable the output.