phpmyadmin / phpmyadmin/phpmyadmin
"Create PHP code" creates broken code and encourages SQL injection
Nobody has claimed this yet.
- Dominant language
- PHP
- Stars
- 7.9k
- Forks
- 3.6k
- Avg merge
- 4d 18h
- Merged PRs (30d)
- 36
Description
Describe the bug
There exists a button that enables the user to convert an SQL query into a PHP variable. When you click "Create PHP code" a box will show up with PHP code containing a single variable called $sql which has a value assigned of the SQL being executed earlier.
To Reproduce
Steps to reproduce the behavior:
- Go to browse table
- Add a
WHERE 'asd' = 'foo'clause - Click on "Create PHP code"
- See broken code
Expected behavior
There should exist no such button. Creation of PHP code should be the responsibility of the PHP developer who will take care of proper parameterization and proper PHP/SQL syntax. The only benefit this button provides is the automatic addslashes which actually creates invalid SQL.
SELECT * FROM `sequence` WHERE \'asd\' = \'foo\';
This button promotes insecure PHP coding practices as inexperienced users may use this to create hardcoded queries and later replace the constant value with interpolated PHP variable creating SQL injection.
I suggest that this feature be removed from PMA in the next major version.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start in the Browse table flow and reproduce the issue by adding WHERE 'asd' = 'foo', then using the "Create PHP code" button. Locate the button and the code-generation entry point by searching for that label. Done means the insecure PHP-generation feature is removed without leaving the broken output path available.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- mysql, php
- Domain
- database, security
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100