Issues (1751)

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/modules/mod_pdftk.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
	class pdftk {
3
		protected $config;
4
5
		public function __construct( $config = array() ) {
6
			if (!$config['cmd']) {
7
				$config['cmd'] = '/usr/bin/pdftk ';
8
			}
9
10
			if (!$config['temp']) {
11
				$context = pobject::getContext();
12
				$me = $context["arCurrentObject"];
13
				$config['temp'] = $me->store->get_config( "files" ) . "temp/";
14
			}
15
16
			$this->config = $config;
17
		}
18
19
		public function concat( $files = array() ) {
20
			if (!sizeof($files)) {
21
				return false;
22
			}
23
24
			$inputs = array();
25
			$i = 1;
0 ignored issues
show
$i is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
26 View Code Duplication
			foreach ($files as $file) {
27
				$tempFile = tempnam( $this->config['temp'], 'pdftk-input-' );
28
				if ( !$tempFile ) {
29
					return ar_error::raiseError( "pdftk: could not create a temporary input file", 202 );
30
				}
31
				$inputs[] = $tempFile;
32
				file_put_contents($tempFile, $file);
33
			}
34
			unset($files);
35
36
			$outputFile = tempnam( $this->config['temp'], 'pdftk-output-' );
37
			if ( !$outputFile ) {
38
				return ar_error::raiseError( "pdftk: could not create a temporary output file", 204 );
39
			}
40
			
41
			// pdftk in1.pdf in2.pdf cat output out1.pdf
42
			$execString = $this->config['cmd'];
43
			$execString .= " " . implode(" ", $inputs);
44
			$execString .= " cat output $outputFile";
45
46
			$execOutput = array();
47
			$execResult = 0;
48
49
			exec( $execString, $execOutput, $execResult );
50
51 View Code Duplication
			if ( $execResult != 0 ) {
0 ignored issues
show
It seems like you are loosely comparing $execResult of type integer|null to 0; this is ambiguous as not only 0 == 0 is true, but null == 0 is true, too. Consider using a strict comparison ===.
Loading history...
52
				foreach ($inputs as $file) { 
53
					@unlink($file);
54
				}
55
				@unlink($outputFile);
56
				return ar_error::raiseError( "pdftk: error ($execResult) [$execString] while trying to generate PDF: " . implode( "\n", (array) $execOutput ), 203 );
57
			}
58
59
			$result = file_get_contents( $outputFile );
60
61
			foreach ($inputs as $file) { 
62
				@unlink($file);
63
			}
64
			@unlink($outputFile);
65
			return $result;
66
		}
67
68
		public function background( $files = array() ) {
69
			/*
70
				Call this with arguments:
71
					$files = array(
72
						"pdf" => $pdfData,
73
						"background" => $backgroundPdf
74
					);
75
			*/						
76
			if (!sizeof($files)) {
77
				return false;
78
			}
79
80
			$inputs = array();
81
			$i = 1;
0 ignored issues
show
$i is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
82 View Code Duplication
			foreach ($files as $key => $file) {
83
				$tempFile = tempnam( $this->config['temp'], 'pdftk-input-' );
84
				if ( !$tempFile ) {
85
					return ar_error::raiseError( "pdftk: could not create a temporary input file", 202 );
86
				}
87
				$inputs[$key] = $tempFile;
88
				file_put_contents($tempFile, $file);
89
			}
90
			unset($files);
91
92
			$outputFile = tempnam( $this->config['temp'], 'pdftk-output-' );
93
			if ( !$outputFile ) {
94
				return ar_error::raiseError( "pdftk: could not create a temporary output file", 204 );
95
			}
96
			
97
			// pdftk in1.pdf in2.pdf cat output out1.pdf
98
			// system("pdftk.exe \"$frontpage\" background $frontpage_file output \"$wm_frontpage\"");
99
			$execString = $this->config['cmd'];
100
			$execString .= " " . $inputs["pdf"];
101
			$execString .= " background " . $inputs["background"] . " output $outputFile";
102
103
			$execOutput = array();
104
			$execResult = 0;
105
106
			exec( $execString, $execOutput, $execResult );
107
108 View Code Duplication
			if ( $execResult != 0 ) {
0 ignored issues
show
It seems like you are loosely comparing $execResult of type integer|null to 0; this is ambiguous as not only 0 == 0 is true, but null == 0 is true, too. Consider using a strict comparison ===.
Loading history...
109
				foreach ($inputs as $file) { 
110
					@unlink($file);
111
				}
112
				@unlink($outputFile);
113
				return ar_error::raiseError( "pdftk: error ($execResult) while trying to generate PDF: " . implode( "\n", (array) $execOutput ), 203 );
114
			}
115
116
			$result = file_get_contents( $outputFile );
117
118
			foreach ($inputs as $file) { 
119
				@unlink($file);
120
			}
121
			@unlink($outputFile);
122
			return $result;
123
		}
124
125
		public function pages( $args = array() ) {
126
			/*
127
				Call this with arguments:
128
					$args = array(
129
						"pdf" => $pdfData,
130
						"pages" => "1-r2" // removes the last page;
131
					);
132
			*/						
133
			if (!sizeof($args)) {
134
				return false;
135
			}
136
137
			$inputs = array();
138
139
			$tempFile = tempnam( $this->config['temp'], 'pdftk-input-' );
140
			if ( !$tempFile ) {
141
				return ar_error::raiseError( "pdftk: could not create a temporary input file", 202 );
142
			}
143
			$inputs['pdf'] = $tempFile;
144
			file_put_contents($tempFile, $args['pdf']);
145
146
			$outputFile = tempnam( $this->config['temp'], 'pdftk-output-' );
147
			if ( !$outputFile ) {
148
				return ar_error::raiseError( "pdftk: could not create a temporary output file", 204 );
149
			}
150
			
151
			// pdftk in1.pdf cat 1-r2 output out1.pdf
152
			// system("pdftk.exe \"$frontpage\" background $frontpage_file output \"$wm_frontpage\"");
153
			$execString = $this->config['cmd'];
154
			$execString .= " " . $inputs["pdf"];
155
			$execString .= " cat " . escapeshellcmd($args["pages"]) . " output $outputFile";
156
157
			$execOutput = array();
158
			$execResult = 0;
159
160
			exec( $execString, $execOutput, $execResult );
161
162 View Code Duplication
			if ( $execResult != 0 ) {
0 ignored issues
show
It seems like you are loosely comparing $execResult of type integer|null to 0; this is ambiguous as not only 0 == 0 is true, but null == 0 is true, too. Consider using a strict comparison ===.
Loading history...
163
				foreach ($inputs as $file) { 
164
					@unlink($file);
165
				}
166
				@unlink($outputFile);
167
				return ar_error::raiseError( "pdftk: error ($execResult) while trying to generate PDF: " . implode( "\n", (array) $execOutput ), 203 );
168
			}
169
170
			$result = file_get_contents( $outputFile );
171
172
			foreach ($inputs as $file) { 
173
				@unlink($file);
174
			}
175
			@unlink($outputFile);
176
			return $result;
177
		}
178
	}
179
180
	class pinp_pdftk {
181
		private $instance;
182
183
		public function __construct() {
184
			$this->instance = new pdftk();
185
		}
186
187
		public function _concat( $files = array() ) {
188
			return $this->instance->concat( $files );
189
		}
190
		
191
		public function _background( $args = array() ) {
192
			return $this->instance->background( $args );
193
		}
194
195
		public function _pages( $args = array() ) {
196
			return $this->instance->pages( $args );
197
		}
198
199
		public static function _get() {
200
			return new pinp_pdftk();
201
		}
202
	}
203