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/Request/AbstractBattleNetAuth.php (4 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
namespace Jleagle\BattleNet\Request;
3
4
use Jleagle\BattleNet\Enums\AuthScopes;
5
use Jleagle\BattleNet\Enums\ServerLocations;
6
use Jleagle\BattleNet\Exceptions\BattleNetException;
7
use Jleagle\CurlWrapper\Curl;
8
use Jleagle\CurlWrapper\Exceptions\CurlException;
9
use Jleagle\CurlWrapper\Exceptions\CurlInvalidJsonException;
10
11
abstract class AbstractBattleNetAuth
12
{
13
  use BattleNetTrait;
14
15
  protected $_apiSecret;
16
  protected $_redirectUrl;
17
  protected $_scopes;
18
19
  /**
20
   * @param string   $apiKey
21
   * @param string   $apiSecret
22
   * @param string   $redirectUrl
23
   * @param string[] $scopes
24
   * @param string   $serverLocation
25
   * @param string   $responseLocale
26
   */
27
  public function __construct(
28
    $apiKey, $apiSecret, $redirectUrl, $scopes = [],
29
    $serverLocation = ServerLocations::US, $responseLocale = null
30
  )
31
  {
32
    $this->_apiKey = $apiKey;
0 ignored issues
show
The property _apiKey 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...
33
    $this->_apiSecret = $apiSecret;
34
    $this->_redirectUrl = $redirectUrl;
35
    $this->_scopes = $scopes;
36
    $this->_serverLocation = $serverLocation;
37
    $this->_responseLocale = $responseLocale;
0 ignored issues
show
The property _responseLocale 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...
38
  }
39
40
  /**
41
   * @return string
42
   */
43
  private function _getScopes()
44
  {
45
    $scopes = $this->_scopes;
46
    if(!$scopes)
0 ignored issues
show
Bug Best Practice introduced by
The expression $scopes of type string[] is implicitly converted to a boolean; are you sure this is intended? If so, consider using empty($expr) instead to make it clear that you intend to check for an array without elements.

This check marks implicit conversions of arrays to boolean values in a comparison. While in PHP an empty array is considered to be equal (but not identical) to false, this is not always apparent.

Consider making the comparison explicit by using empty(..) or ! empty(...) instead.

Loading history...
47
    {
48
      $scopes = [AuthScopes::WOW, AuthScopes::SC2];
49
    }
50
    return implode(' ', $scopes);
51
  }
52
53
  /**
54
   * @param string|null $state
55
   * @param bool        $redirect
56
   *
57
   * @return string[]
58
   */
59
  public function getCode($state = null, $redirect = false)
60
  {
61
    if(!$state)
0 ignored issues
show
Bug Best Practice introduced by
The expression $state of type string|null is loosely compared to false; this is ambiguous if the string can be empty. You might want to explicitly use === null instead.

In PHP, under loose comparison (like ==, or !=, or switch conditions), values of different types might be equal.

For string values, the empty string '' is a special case, in particular the following results might be unexpected:

''   == false // true
''   == null  // true
'ab' == false // false
'ab' == null  // false

// It is often better to use strict comparison
'' === false // false
'' === null  // false
Loading history...
62
    {
63
      $state = rand(11111, 99999);
64
    }
65
66
    $params = http_build_query(
67
      [
68
        'client_id'     => $this->_apiKey,
69
        'scope'         => $this->_getScopes(),
70
        'state'         => $state,
71
        'redirect_uri'  => $this->_redirectUrl,
72
        'response_type' => 'code',
73
      ]
74
    );
75
    $url = 'https://' . $this->_serverLocation . '.battle.net/oauth/authorize?' . $params;
76
77
    if($redirect)
78
    {
79
      header('Location: ' . $url);
80
      exit;
81
    }
82
83
    return ['redirectUrl' => $url, 'state' => $state];
84
  }
85
86
  /**
87
   * Each code can only be used once
88
   *
89
   * @param string $code
90
   *
91
   * @return array
92
   *
93
   * @throws CurlException
94
   * @throws CurlInvalidJsonException
95
   */
96
  public function getAccessToken($code)
97
  {
98
    $url = 'https://' . $this->_serverLocation . '.battle.net/oauth/token';
99
100
    $data = [
101
      'redirect_uri' => $this->_redirectUrl,
102
      'scope'        => $this->_getScopes(),
103
      'grant_type'   => 'authorization_code',
104
      'code'         => $code,
105
    ];
106
107
    return Curl::post($url, $data)
108
      ->setBasicAuth($this->_apiKey, $this->_apiSecret)
109
      ->run()
110
      ->getJson();
111
  }
112
113
  /**
114
   * @param string $path
115
   * @param string $accessToken
116
   *
117
   * @return array
118
   * @throws BattleNetException
119
   */
120
  protected function _get($path, $accessToken)
121
  {
122
    $data = ['access_token' => $accessToken];
123
124
    try
125
    {
126
      return Curl::get($this->_makeApiUrl($path), $data)->run()->getJson();
127
    }
128
    catch(CurlException $e)
129
    {
130
      $json = $e->getResponse()->getJson();
131
      $message = isset($json['reason']) ? $json['reason'] : $e->getMessage();
132
      throw new BattleNetException($message);
133
    }
134
  }
135
}
136