Issues (4967)

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.

tools/i18n/add-textdomain.php (1 issue)

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
 * Console application, which adds textdomain argument
4
 * to all i18n function calls
5
 *
6
 * @package wordpress-i18n
7
 */
8
error_reporting(E_ALL);
9
10
require_once dirname( __FILE__ ) . '/makepot.php';
11
12
class AddTextdomain {
13
14
	var $modified_contents = '';
15
	var $funcs;
16
17
	/**
18
	 * Constructor.
19
	 */
20
	public function __construct() {
21
		$makepot = new MakePOT;
22
		$this->funcs = array_keys( $makepot->rules );
23
		$this->funcs[] = 'translate_nooped_plural';
24
	}
25
26
	/**
27
	 * Prints CLI usage.
28
	 */
29
	public function usage() {
30
		$usage = "Usage: php add-textdomain.php [-i] <domain> <file>\n\nAdds the string <domain> as a last argument to all i18n function calls in <file>\nand prints the modified php file on standard output.\n\nOptions:\n    -i    Modifies the PHP file in place, instead of printing it to standard output.\n";
31
		fwrite(STDERR, $usage);
32
		exit(1);
0 ignored issues
show
Coding Style Compatibility introduced by
The method usage() contains an exit expression.

An exit expression should only be used in rare cases. For example, if you write a short command line script.

In most cases however, using an exit expression makes the code untestable and often causes incompatibilities with other libraries. Thus, unless you are absolutely sure it is required here, we recommend to refactor your code to avoid its usage.

Loading history...
33
	}
34
35
	/**
36
	 * Adds textdomain to a single file.
37
	 *
38
	 * @see AddTextdomain::process_string()
39
	 *
40
	 * @param string $domain          Text domain.
41
	 * @param string $source_filename Filename with optional path.
42
	 * @param bool   $inplace         True to modifies the PHP file in place. False to print to standard output.
43
	 */
44
	public function process_file( $domain, $source_filename, $inplace ) {
45
		$new_source = $this->process_string( $domain, file_get_contents( $source_filename ) );
46
47
		if ( $inplace ) {
48
			$f = fopen( $source_filename, 'w' );
49
			fwrite( $f, $new_source );
50
			fclose( $f );
51
		} else {
52
			echo $new_source;
53
		}
54
	}
55
56
	/**
57
	 * Adds textdomain to a string of PHP.
58
	 *
59
	 * Functions calls should be wrapped in opening and closing PHP delimiters as usual.
60
	 *
61
	 * @see AddTextdomain::process_tokens()
62
	 *
63
	 * @param string $domain Text domain.
64
	 * @param string $string PHP code to parse.
65
	 * @return string Modified source.
66
	 */
67
	public function process_string( $domain, $string ) {
68
		$tokens = token_get_all( $string );
69
		return $this->process_tokens( $domain, $tokens );
70
	}
71
72
	/**
73
	 * Adds textdomain to a set of PHP tokens.
74
	 *
75
	 * @param string $domain Text domain.
76
	 * @param array  $tokens PHP tokens. An array of token identifiers. Each individual token identifier is either a
77
	 *                       single character (i.e.: ;, ., >, !, etc.), or a three element array containing the token
78
	 *                       index in element 0, the string content of the original token in element 1 and the line
79
	 *                       number in element 2.
80
	 * @return string Modified source.
81
	 */
82
	public function process_tokens( $domain, $tokens ) {
83
		$this->modified_contents = '';
84
		$domain = addslashes( $domain );
85
86
		$in_func = false;
87
		$args_started = false;
88
		$parens_balance = 0;
89
		$found_domain = false;
90
91
		foreach($tokens as $index => $token) {
92
			$string_success = false;
93
			if (is_array($token)) {
94
				list($id, $text) = $token;
95
				if (T_STRING == $id && in_array($text, $this->funcs)) {
96
					$in_func = true;
97
					$parens_balance = 0;
98
					$args_started = false;
99
					$found_domain = false;
100
				} elseif (T_CONSTANT_ENCAPSED_STRING == $id && ("'$domain'" == $text || "\"$domain\"" == $text)) {
101
					if ($in_func && $args_started) {
102
						$found_domain = true;
103
					}
104
				}
105
				$token = $text;
106
			} elseif ('(' == $token){
107
				$args_started = true;
108
				++$parens_balance;
109
			} elseif (')' == $token) {
110
				--$parens_balance;
111
				if ($in_func && 0 == $parens_balance) {
112
					if ( ! $found_domain ) {
113
						$token = ", '$domain'";
114
						if ( T_WHITESPACE == $tokens[ $index - 1 ][0] ) {
115
							$token .= ' '; // Maintain code standards if previously present
116
							// Remove previous whitespace token to account for it.
117
							$this->modified_contents = trim( $this->modified_contents );
118
						}
119
						$token .= ')';
120
					}
121
					$in_func = false;
122
					$args_started = false;
123
					$found_domain = false;
124
				}
125
			}
126
			$this->modified_contents .= $token;
127
		}
128
129
		return $this->modified_contents;
130
	}
131
}
132
133
// Run the CLI only if the file wasn't included.
134
$included_files = get_included_files();
135
if ($included_files[0] == __FILE__) {
136
	$adddomain = new AddTextdomain();
137
138
	if (!isset($argv[1]) || !isset($argv[2])) {
139
		$adddomain->usage();
140
	}
141
142
	$inplace = false;
143
	if ('-i' == $argv[1]) {
144
		$inplace = true;
145
		if (!isset($argv[3])) $adddomain->usage();
146
		array_shift($argv);
147
	}
148
149
	if ( is_dir( $argv[2] ) ) {
150
		$directory = new RecursiveDirectoryIterator( $argv[2], RecursiveDirectoryIterator::SKIP_DOTS );
151
		$files = new RecursiveIteratorIterator( $directory );
152
		foreach ( $files as $file ) {
153
			if ( 'php' === $file->getExtension() ) {
154
				$adddomain->process_file( $argv[1], $file->getPathname(), $inplace );
155
			}
156
		}
157
	} else {
158
		$adddomain->process_file( $argv[1], $argv[2], $inplace );
159
	}
160
}
161