Issues (20)

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/Github/GithubAPI.php (1 issue)

Labels
Severity

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
namespace Acacha\Llum\Github;
4
5
use Acacha\Llum\Filesystem\Filesystem;
6
use Acacha\Llum\Github\Exceptions\CredentialsException;
7
use GuzzleHttp\Client;
8
9
/**
10
 * Class GithubAPI
11
 * @package Acacha\Llum\Github
12
 */
13
class GithubAPI
14
{
15
    /**
16
     * Guzzle http client.
17
     *
18
     * @var Client
19
     */
20
    protected $client;
21
22
    /**
23
     * Github API URL.
24
     *
25
     * @var string
26
     */
27
    protected $api_url = "https://api.github.com";
28
29
    /**
30
     * Authorization URI in github API.
31
     *
32
     * @var string
33
     */
34
    protected $authorizations_uri = "/authorizations";
35
36
    /**
37
     * Authorization URI in github API.
38
     *
39
     * @var string
40
     */
41
    protected $repos_uri = "/user/repos";
42
43
44
    /**
45
     * Acacha Llum Filesystem.
46
     *
47
     * @var Filesystem
48
     */
49
    protected $filesystem;
50
51
    /**
52
     * Token name;
53
     *
54
     * @var
55
     */
56
    protected $tokenName;
57
58
    /**
59
     * GithubAPI constructor.
60
     */
61
    public function __construct(Filesystem $filesystem)
62
    {
63
        $this->client = new Client();
64
        $this->filesystem = $filesystem;
65
    }
66
67
    /**
68
     * Path to repo.json stub
69
     *
70
     * @return string
71
     */
72
    protected function repo_json_stub() {
73
        return __DIR__ . '/stubs/repo_json.stub';
74
    }
75
76
    /**
77
     * Authorization URL.
78
     *
79
     * @return string
80
     */
81
    protected function authorization_url() {
82
        return $this->api_url . $this->authorizations_uri;
83
    }
84
85
    /**
86
     * Create repo URL.
87
     *
88
     * @return string
89
     */
90
    protected function create_repo_url() {
91
        return $this->api_url . $this->repos_uri;
92
    }
93
94
    /**
95
     * Obtain personal token.
96
     *
97
     * @param $username
98
     * @param $password
99
     * @return mixed
100
     */
101
    public function getPersonalToken($username, $password)
102
    {
103
        $response = $this->client->request('POST', $this->authorization_url(),
104
            [
105
                "auth" => [ $username, $password],
106
                "json" => $this->authorizationsRequestJson()
107
            ]
108
        );
109
        $response = json_decode($response->getBody());
110
        $this->tokenName = $response->app->name;
111
        return $response->token;
112
    }
113
114
    /**
115
     * @return array
116
     */
117
    protected function authorizationsRequestJson(){
118
        return [
119
            'scopes' => [ 'public_repo' ],
120
            'note' =>  uniqid('llum_')
121
        ];
122
    }
123
124
    /**
125
     * Create repo in github.
126
     *
127
     * @param $repo_name
128
     * @param $repo_description
129
     * @return mixed
130
     */
131
    public function createRepo($repo_name, $repo_description)
132
    {
133
        return $this->client->request('POST', $this->create_repo_url(),
134
            [
135
                "auth" => $this->credentials(),
136
                "json" => json_decode($this->compileStub($repo_name, $repo_description),true),
137
            ]
138
        );
139
    }
140
141
    /**
142
     * Set github credentials.
143
     *
144
     * @param array $credentials
145
     */
146
    public function setCredentials(array $credentials)
147
    {
148
        $this->credentials = $credentials;
0 ignored issues
show
The property credentials 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...
149
    }
150
151
    /**
152
     * Get github credentials.
153
     *
154
     * @return mixed
155
     * @throws CredentialsException
156
     */
157
    protected function credentials()
158
    {
159
        if (isset($this->credentials))
160
            return $this->credentials;
161
        throw new CredentialsException;
162
    }
163
164
    /**
165
     * Compile stub.
166
     *
167
     * @param $repo_name
168
     * @param $repo_description
169
     * @return mixed
170
     */
171
    protected function compileStub($repo_name, $repo_description)
172
    {
173
        $data = [
174
            "REPO_NAME" => $repo_name,
175
            "REPO_DESCRIPTION" => $repo_description
176
        ];
177
        return $this->compile(
178
            $this->filesystem->get($this->repo_json_stub()) ,
179
            $data);
180
    }
181
182
    /**
183
     * Compile the template using the given data.
184
     *
185
     * @param $template
186
     * @param $data
187
     * @return mixed
188
     */
189
    protected function compile($template, $data)
190
    {
191
        foreach($data as $key => $value)
192
        {
193
            $template = preg_replace("/\\$$key\\$/i", $value, $template);
194
        }
195
        return $template;
196
    }
197
198
    /**
199
     * @return mixed
200
     */
201
    public function tokenName()
202
    {
203
        return $this->tokenName;
204
    }
205
206
207
}