magnusmanske / magnusmanske/quickstatements

Code vulnerable for SQL injections

Open
#28 4 comments 1 reaction 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
PHP
Stars
58
Forks
21
PR merge metrics
No merged PRs in 30d

Description

Hi,

I see a lot of lines like this function:
```php
public function getBatch ( $id ) {
$id *= 1 ;
$ret = array('commands'=>array()) ;
$db = $this->getDB() ;
$sql = "SELECT * FROM command WHERE batch_id=$id" ;
if(!$result = $db->query($sql)) return $this->setErrorMessage ( 'There was an error running the query [' . $db->error . ']'."\n$sql" ) ;
while ( $o = $result->fetch_object() ) {
$j = json_decode ( $o->json ) ;
$j->_meta = $o ;
unset ( $j->_meta->json ) ;
$ret['commands'][$o->num] = $j ;
}
return $ret ;
}
```

If one would simply set $id to `0;DROP TABLE COMMAND;`, the command table will be gone. Easy as that.. Please, for the love of god; use SQL prepared statements. See: https://www.w3schools.com/php/php_mysql_prepared_statements.asp

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

The report points to getBatch($id) and shows a raw SQL query; start by locating that function and reviewing the other similar query constructions. No file or test is named, so trace the affected call paths and verify that injected input is treated as data; done means the reported queries no longer allow SQL injection.

Written by the indexing model from the issue text.

Assessment

Tech stack
php, sql
Domain
database, security
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.