Issues (11)

Security Analysis    no request data  

This project does not seem to handle request data directly as such no vulnerable execution paths were found.

  Cross-Site Scripting
Cross-Site Scripting enables an attacker to inject code into the response of a web-request that is viewed by other users. It can for example be used to bypass access controls, or even to take over other users' accounts.
  File Exposure
File Exposure allows an attacker to gain access to local files that he should not be able to access. These files can for example include database credentials, or other configuration files.
  File Manipulation
File Manipulation enables an attacker to write custom data to files. This potentially leads to injection of arbitrary code on the server.
  Object Injection
Object Injection enables an attacker to inject an object into PHP code, and can lead to arbitrary code execution, file exposure, or file manipulation attacks.
  Code Injection
Code Injection enables an attacker to execute arbitrary code on the server.
  Response Splitting
Response Splitting can be used to send arbitrary responses.
  File Inclusion
File Inclusion enables an attacker to inject custom files into PHP's file loading mechanism, either explicitly passed to include, or for example via PHP's auto-loading mechanism.
  Command Injection
Command Injection enables an attacker to inject a shell command that is execute with the privileges of the web-server. This can be used to expose sensitive data, or gain access of your server.
  SQL Injection
SQL Injection enables an attacker to execute arbitrary SQL code on your database server gaining access to user data, or manipulating user data.
  XPath Injection
XPath Injection enables an attacker to modify the parts of XML document that are read. If that XML document is for example used for authentication, this can lead to further vulnerabilities similar to SQL Injection.
  LDAP Injection
LDAP Injection enables an attacker to inject LDAP statements potentially granting permission to run unauthorized queries, or modify content inside the LDAP tree.
  Header Injection
  Other Vulnerability
This category comprises other attack vectors such as manipulating the PHP runtime, loading custom extensions, freezing the runtime, or similar.
  Regex Injection
Regex Injection enables an attacker to execute arbitrary code in your PHP process.
  XML Injection
XML Injection enables an attacker to read files on your local filesystem including configuration files, or can be abused to freeze your web-server process.
  Variable Injection
Variable Injection enables an attacker to overwrite program variables with custom data, and can lead to further vulnerabilities.
Unfortunately, the security analysis is currently not available for your project. If you are a non-commercial open-source project, please contact support to gain access.

src/EoC/Command/MapDocCmd.php (5 issues)

Upgrade to new PHP Analysis Engine

These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more

1
<?php
2
3
4
/**
5
 * @file MapDocCmd.php
6
 * @brief This file contains the MapDocCmd class.
7
 * @details
8
 * @author Filippo F. Fadda
9
 */
10
11
12
namespace EoC\Command;
13
14
15
/**
16
 * @brief Maps a document against every single map function stored into the server.
17
 * @details When the view function is stored in the server, CouchDB starts sending in all the documents in the
18
 * database, one at a time. The server calls the previously stored functions one after another with the document
19
 * and stores its result. When all functions have been called, the result is returned as a JSON string.\n\n
20
 * The argument provided by CouchDB has the following structure:
21
 @code
22
   Array
23
   (
24
       [0] => Array
25
       (
26
           [_id] => 32012
27
           [_rev] => 1-f19919e544340438babac6cc86ec61d5
28
           [title] => Visual Modelling with Rational Rose 2000 and UML
29
       )
30
   )
31
 @endcode
32
 */
33
final class MapDocCmd extends AbstractCmd {
34
  use CmdTrait;
35
36
37
  public static function getName() {
38
    return "map_doc";
39
  }
40
41
42
  // @brief Converts the array to an object.
43
  // @return object
44
  public static function arrayToObject($array) {
45
    return is_array($array) ? (object)array_map(__METHOD__, $array) : $array;
46
  }
47
48
49
  public function execute() {
50
    $doc = self::arrayToObject(reset($this->args));
51
52
    $this->server->getMonolog()->addDebug("MAP ".$doc->_id);
53
54
    // We use a closure here, so we can just expose the emit() function to the closure provided by the user. We have
55
    // another advantage: the $map variable is defined inside execute(), so we don't need to declare it as class member.
56
    $emit = function($key = NULL, $value = NULL) use (&$map) {
0 ignored issues
show
$emit is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
57
      $map[] = array($key, $value);
58
    };
59
60
    $closure = NULL; // This initialization is made just to prevent a lint error during development.
61
62
    $result = []; // Every time we map a document against all the registered functions we must reset the result.
63
64 View Code Duplication
    foreach ($this->server->getFuncs() as $fn) {
0 ignored issues
show
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
65
      $map = []; // Every time we map a document against a function we must reset the map.
0 ignored issues
show
Consider using a different name than the imported variable $map, or did you forget to import by reference?

It seems like you are assigning to a variable which was imported through a use statement which was not imported by reference.

For clarity, we suggest to use a different name or import by reference depending on whether you would like to have the change visibile in outer-scope.

Change not visible in outer-scope

$x = 1;
$callable = function() use ($x) {
    $x = 2; // Not visible in outer scope. If you would like this, how
            // about using a different variable name than $x?
};

$callable();
var_dump($x); // integer(1)

Change visible in outer-scope

$x = 1;
$callable = function() use (&$x) {
    $x = 2;
};

$callable();
var_dump($x); // integer(2)
Loading history...
66
67
      // Here we call the closure function stored in the view. The $closure variable contains the function implementation
68
      // provided by the user. You can have multiple views in a design document and for every single view you can have
69
      // only one map function.
70
      // The closure must be declared like:
71
      //
72
      //     function($doc) use ($emit) { ... };
0 ignored issues
show
Unused Code Comprehensibility introduced by
67% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
73
      //
74
      // This technique let you use the syntax '$emit($key, $value);' to emit your record. The function doesn't return
75
      // any value. You don't need to include any files since the closure's code is executed inside this method.
76
      eval("\$closure = ".$fn);
0 ignored issues
show
It is generally not recommended to use eval unless absolutely required.

On one hand, eval might be exploited by malicious users if they somehow manage to inject dynamic content. On the other hand, with the emergence of faster PHP runtimes like the HHVM, eval prevents some optimization that they perform.

Loading history...
77
78
      if (is_callable($closure)) {
79
        call_user_func($closure, $doc);
80
        $result[] = $map;
81
      }
82
      else
83
        throw new \BadFunctionCallException("The map function is not callable.");
84
    }
85
86
    // Sends mappings to CouchDB.
87
    $this->server->writeln(json_encode($result));
88
  }
89
90
}