Issues (25)

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.

lib/Redmine/Client.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
 * The dashboard-specific functionality of the plugin.
5
 *
6
 * @link       http://example.com
7
 * @since      1.0.0
8
 *
9
 * @package    PluginName
10
 * @subpackage PluginName/admin
11
 */
12
13
namespace logoscon\WP\RedmineEmbed\Redmine;
14
15
use logoscon\WP\RedmineEmbed\Plugin;
16
17
/**
18
 * The dashboard-specific functionality of the plugin.
19
 *
20
 * Defines the plugin name, version, and two examples hooks for how to
21
 * enqueue the dashboard-specific stylesheet and JavaScript.
22
 *
23
 * @package    PluginName
24
 * @subpackage PluginName/admin
25
 * @author     Your Name <[email protected]>
26
 */
27
class Client {
28
29
    /**
30
     * The plugin's instance.
31
     *
32
     * @since  1.0.0
33
     * @access private
34
     * @var    Plugin $plugin This plugin's instance.
35
     */
36
    private $plugin;
37
38
    /**
39
     * Root URL for Redmine.
40
     * @access private
41
     * @var string
42
     */
43
    private $root_url = '';
44
45
    /**
46
     * REST API key for Redmine.
47
     * @var string
48
     */
49
    private $api_key = '';
50
51
    /**
52
     * Initialize the class and set its properties.
53
     *
54
     * @since 1.0.0
55
     *
56
     * @param Plugin $plugin This plugin's instance.
57
     */
58
    public function __construct( Plugin $plugin ) {
59
        $this->plugin   = $plugin;
60
        $this->api_key  = $this->get_api_key();
61
        $this->root_url = \trailingslashit( $plugin->get_option( 'root_url' ) );
62
        $this->url      = new UrlBuilder( $plugin );
0 ignored issues
show
The property url does not exist. Did you maybe forget to declare it?

In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:

class MyClass { }

$x = new MyClass();
$x->foo = true;

Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion:

class MyClass {
    public $foo;
}

$x = new MyClass();
$x->foo = true;
Loading history...
63
    }
64
65
    /**
66
     * Fetch an issue.
67
     * @param  string $id      Issue ID.
68
     * @param  array  $options Request options.
69
     * @param  array  $expires Cache TTL, in seconds (defaults to 3600).
0 ignored issues
show
Should the type for parameter $expires not be integer?

This check looks for @param annotations where the type inferred by our type inference engine differs from the declared type.

It makes a suggestion as to what type it considers more descriptive.

Most often this is a case of a parameter that can be null in addition to its declared types.

Loading history...
70
     * @return mixed           Response data.
71
     */
72
    public function get_issue( $id, $options = array(), $expires = 3600  ) {
73
        $url = $this->url->get_json_resource_url( 'issues', $id );
74
75
        return json_decode( $this->get( $url, $options, $expires ) );
76
    }
77
78
    /**
79
     * Handle GET requests.
80
     * @param  string $resource Resource to fetch
0 ignored issues
show
There is no parameter named $resource. Was it maybe removed?

This check looks for PHPDoc comments describing methods or function parameters that do not exist on the corresponding method or function.

Consider the following example. The parameter $italy is not defined by the method finale(...).

/**
 * @param array $germany
 * @param array $island
 * @param array $italy
 */
function finale($germany, $island) {
    return "2:1";
}

The most likely cause is that the parameter was removed, but the annotation was not.

Loading history...
81
     * @param  array  $options  Request options.
82
     * @param  array  $expires  Cache TTL, in seconds (defaults to 3600).
0 ignored issues
show
Should the type for parameter $expires not be integer?

This check looks for @param annotations where the type inferred by our type inference engine differs from the declared type.

It makes a suggestion as to what type it considers more descriptive.

Most often this is a case of a parameter that can be null in addition to its declared types.

Loading history...
83
     * @return mixed            Response data.
84
     */
85
    public function get( $url, $options = array(), $expires = 3600 ) {
86
        $options = $this->add_credentials( $options );
87
88
        if ( $expires === false ) {
89
            // Bypass cache
90
            return $this->get_body( $url, $options );
91
        }
92
93
        $cache_key = sha1( $url . $this->api_key );
94
95
        return \tlc_transient( $cache_key )
96
            ->updates_with( array( $this, 'get_body' ), array( $url, $options ) )
97
            ->expires_in( $expires )
98
            ->get();
99
    }
100
101
    /**
102
     * Fetch the response body for a GET request.
103
     * @param  string $resource Resource to fetch
0 ignored issues
show
There is no parameter named $resource. Was it maybe removed?

This check looks for PHPDoc comments describing methods or function parameters that do not exist on the corresponding method or function.

Consider the following example. The parameter $italy is not defined by the method finale(...).

/**
 * @param array $germany
 * @param array $island
 * @param array $italy
 */
function finale($germany, $island) {
    return "2:1";
}

The most likely cause is that the parameter was removed, but the annotation was not.

Loading history...
104
     * @param  array  $options  Request options.
105
     * @return string           Request body.
106
     */
107
    public function get_body( $url, $options ) {
108
        $response = \wp_remote_get( $url, $options );
109
        $code     = \wp_remote_retrieve_response_code( $response );
110
        $message  = \wp_remote_retrieve_response_message( $response );
111
112
        if ( substr( $code, 0, 1 ) !== '2' ) {
113
            // A non-2xx class status code means there was an error.
114
            throw new \Exception( $message, (int) $code );
115
        }
116
117
        return \wp_remote_retrieve_body( $response );
118
    }
119
120
    /**
121
     * Add credentials to a set of request options.
122
     * @param array $options Request options.
123
     */
124
    private function add_credentials( $options = array() ) {
125
        if ( ! isset( $options['headers'] ) ) {
126
            $options['headers'] = array();
127
        }
128
129
        $options['headers']['X-Redmine-API-Key'] = $this->api_key;
130
131
        return $options;
132
    }
133
134
    /**
135
     * Get the configured Redmine API key.
136
     *
137
     * Looks for the user key first and falls back to the globally configured one.
138
     *
139
     * @return string Configured Redmine API key.
140
     */
141
    private function get_api_key() {
142
        $user_id = \get_current_user_id();
143
        $api_key = \get_user_option( 'redmine_embed_api_key', $user_id );
144
145
        if ( empty( $api_key ) ) {
146
            $api_key = $this->plugin->get_option( 'api_key' );
147
        }
148
149
        return \sanitize_key( $api_key );
150
    }
151
152
}
153