Issues (64)

Security Analysis    not enabled

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/client/fetch.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
 * Fetch API client class.
4
 * @package WordPress_GitHub_Sync
5
 */
6
7
/**
8
 * Class WordPress_GitHub_Sync_Fetch_Client
9
 */
10
class WordPress_GitHub_Sync_Fetch_Client extends WordPress_GitHub_Sync_Base_Client {
11
12
	/**
13
	 * Retrieve the last commit in the repository
14
	 *
15
	 * @return WordPress_GitHub_Sync_Commit|WP_Error
16
	 */
17 11
	public function master() {
18 11
		$data = $this->call( 'GET', $this->reference_endpoint() );
19
20 11
		if ( is_wp_error( $data ) ) {
21 4
			return $data;
22
		}
23
24 7
		return $this->commit( $data->object->sha );
25
	}
26
27
	/**
28
	 * Retrieves a commit by sha from the GitHub API
29
	 *
30
	 * @param string $sha Sha for commit to retrieve.
31
	 *
32
	 * @return WordPress_GitHub_Sync_Commit|WP_Error
33
	 */
34 7
	public function commit( $sha ) {
35 7
		if ( $cache = $this->app->cache()->fetch_commit( $sha ) ) {
36 1
			return $cache;
37
		}
38
39 6
		$data = $this->call( 'GET', $this->commit_endpoint() . '/' . $sha );
40
41 6
		if ( is_wp_error( $data ) ) {
42 1
			return $data;
43
		}
44
45 5
		$commit = new WordPress_GitHub_Sync_Commit( $data );
46 5
		$tree   = $this->tree_recursive( $commit->tree_sha() );
47
48 5
		if ( is_wp_error( $tree ) ) {
49 1
			return $tree;
50
		}
51
52 4
		$commit->set_tree( $tree );
0 ignored issues
show
It seems like $tree defined by $this->tree_recursive($commit->tree_sha()) on line 46 can also be of type object<stdClass>; however, WordPress_GitHub_Sync_Commit::set_tree() does only seem to accept object<WordPress_GitHub_Sync_Tree>, maybe add an additional type check?

If a method or function can return multiple different values and unless you are sure that you only can receive a single value in this context, we recommend to add an additional type check:

/**
 * @return array|string
 */
function returnsDifferentValues($x) {
    if ($x) {
        return 'foo';
    }

    return array();
}

$x = returnsDifferentValues($y);
if (is_array($x)) {
    // $x is an array.
}

If this a common case that PHP Analyzer should handle natively, please let us know by opening an issue.

Loading history...
53
54 4
		return $this->app->cache()->set_commit( $sha, $commit );
55
	}
56
57
	/**
58
	 * Calls the content API to get the post's contents and metadata
59
	 *
60
	 * Returns Object the response from the API
61
	 *
62
	 * @param WordPress_GitHub_Sync_Post $post Post to retrieve remote contents for.
63
	 *
64
	 * @return mixed
65
	 */
66
	public function remote_contents( $post ) {
67
		return $this->call( 'GET', $this->content_endpoint() . $post->github_path() );
68
	}
69
70
	/**
71
	 * Retrieves a tree by sha recursively from the GitHub API
72
	 *
73
	 * @param string $sha Commit sha to retrieve tree from.
74
	 *
75
	 * @return WordPress_GitHub_Sync_Tree|WP_Error
76
	 */
77 5
	protected function tree_recursive( $sha ) {
78 5
		if ( $cache = $this->app->cache()->fetch_tree( $sha ) ) {
79 1
			return $cache;
80
		}
81
82 4
		$data = $this->call( 'GET', $this->tree_endpoint() . '/' . $sha . '?recursive=1' );
83
84 4
		if ( is_wp_error( $data ) ) {
85 1
			return $data;
86
		}
87
88 3
		foreach ( $data->tree as $index => $thing ) {
89
			// We need to remove the trees because
90
			// the recursive tree includes both
91
			// the subtrees as well the subtrees' blobs.
92 3
			if ( 'tree' === $thing->type ) {
93 3
				unset( $data->tree[ $index ] );
94 3
			}
95 3
		}
96
97 3
		$tree = new WordPress_GitHub_Sync_Tree( $data );
98 3
		$tree->set_blobs( $this->blobs( $data->tree ) );
99
100 3
		return $this->app->cache()->set_tree( $sha, $tree );
101
	}
102
103
	/**
104
	 * Generates blobs for recursive tree blob data.
105
	 *
106
	 * @param stdClass[] $blobs Array of tree blob data.
107
	 *
108
	 * @return WordPress_GitHub_Sync_Blob[]
109
	 */
110 3
	protected function blobs( array $blobs ) {
111 3
		$results = array();
112
113 3
		foreach ( $blobs as $blob ) {
114 3
			$obj = $this->blob( $blob );
115
116 3
			if ( ! is_wp_error( $obj ) ) {
117 2
				$results[] = $obj;
118 2
			}
119 3
		}
120
121 3
		return $results;
122
	}
123
124
	/**
125
	 * Retrieves the blob data for a given sha
126
	 *
127
	 * @param stdClass $blob Tree blob data.
128
	 *
129
	 * @return WordPress_GitHub_Sync_Blob|WP_Error
130
	 */
131 3
	protected function blob( $blob ) {
132 3
		if ( $cache = $this->app->cache()->fetch_blob( $blob->sha ) ) {
133 1
			return $cache;
134
		}
135
136 2
		$data = $this->call( 'GET', $this->blob_endpoint() . '/' . $blob->sha );
137
138 2
		if ( is_wp_error( $data ) ) {
139 1
			return $data;
140
		}
141
142 1
		$data->path = $blob->path;
143 1
		$obj = new WordPress_GitHub_Sync_Blob( $data );
144
145 1
		return $this->app->cache()->set_blob( $obj->sha(), $obj );
146
	}
147
}
148