CVE-2015-10070 (published 2023-01-19T10:15Z)

A vulnerability was found in copperwall Twiddit. It has been rated as critical. This issue affects some unknown processing of the file index.php. The manipulation leads to sql injection. The identifier of the patch is 2203d4ce9810bdaccece5c48ff4888658a01acfc. It is recommended to apply a patch to fix this issue. The identifier VDB-218897 was assigned to this vulnerability.

CVSS v3 base score: 9.8, CRITICAL (CVSS:3.1/AV:N/AC:L/PR:N/UI:N/S:U/C:H/I:H/A:H)

Weakness information:
cwe_id: CWE-89
cwe_name: Improper Neutralization of Special Elements used in an SQL Command ('SQL Injection')
description: The product constructs all or part of an SQL command using externally-influenced input from an upstream component, but it does not neutralize or incorrectly neutralizes special elements that could modify the intended SQL command when it is sent to a downstream component. Without sufficient removal or quoting of SQL syntax in user-controllable inputs, the generated SQL query can cause those inputs to be interpreted as SQL instead of ordinary user data.
extended_description: 
            
            
         
         

Fix information:
repo_url: https://github.com/copperwall/twiddit
commit_details: repo_url: https://github.com/copperwall/twiddit
author: Chris Opperwall
author_date: 2015-03-15 20:54:14+00:00
msg: Parameterize queries to prevent against SQL injection
repository: repo_url: https://github.com/copperwall/twiddit
repo_name: copperwall/twiddit
description: Follow people on Reddit
repo_language: PHP
owner: copperwall
file_changes: filename: index.php
change_type: ModificationType.MODIFY
diff: @@ -37,10 +37,17 @@ $app->get('/signin', function()  use ($app) {
 $app->get('/feed', function() use ($app) {
    $db = TwidditDB::db();
    $username = $_COOKIE['user'];
-   $query = "select redditor 
-            from followingRedditors 
-            where '$username' = userName";
-   $result = $db->query($query);
+   $query = <<<EOT
+      SELECT `redditor`
+      FROM `followingRedditors`
+      WHERE `userName` = :username
+EOT;
+
+   $statement = $db->prepare($query);
+   $statement->bindParam(':username', $username);
+   $statement->execute();
+   $result = $statement->fetchAll(PDO::FETCH_ASSOC);
+
    $users = [];
    foreach ($result as $row) {
       $users[] = $row['redditor'];
@@ -50,18 +57,26 @@ $app->get('/feed', function() use ($app) {
 
    echo json_encode($comments);
 });
+
 $app->get('/subreddits', function() use ($app) {
    $db = TwidditDB::db();
    $username = $_COOKIE['user'];
-   $query = "select subreddit 
-            from followingSubreddit 
-            where '$username' = userName";
-   $result = $db->query($query);
-   $subreddit = [];
-   foreach ($result as $row) {
-      $subreddit[] = $row['subreddit'];
+   $query = <<<EOT
+      SELECT `subreddit`
+      FROM `followingSubreddit`
+      WHERE `userName` = :username
+EOT;
+
+   $statement = $db->prepare($query);
+   $statement->bindParam(':username', $username);
+   $statement->execute();
+   $results = $statement->fetchAll(PDO::FETCH_ASSOC);
+
+   $subreddits = [];
+   foreach ($results as $row) {
+      $subreddits[] = $row['subreddit'];
    }
-   $data = Reddit::getSubredditPosts($subreddit);
+   $data = Reddit::getSubredditPosts($subreddits);
 
    echo json_encode($data);
 });
@@ -107,7 +122,6 @@ $app->post('/login', function() use ($app) {
    }
 });
 
-
 $app->post('/signup', function() use ($app) {
    $db = TwidditDB::db();
    $username = $app->request->post('username');

programming_language: PHP