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_wkhtmltoimage.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
	class wkhtmltoimage {
3
		protected $config;
4
		protected $headers;
5
		protected $cookies;
6
		protected $options;
7
8
		public function __construct( $config = array() ) {
9
			if (!$config['cmd']) {
10
				$config['cmd'] = '/usr/local/bin/wkhtmltoimage --disable-local-file-access ';
11
			}
12
13 View Code Duplication
			if (!$config['temp']) {
14
				$context = pobject::getContext();
15
				$me = $context["arCurrentObject"];
16
				$config['temp'] = $me->store->get_config( "files" ) . "temp/";
17
			}
18
19
			$this->config = $config;
20
			$this->options = array(
21
				'format' => 'png'
22
			);
23
			$this->cookies = array();
24
			$this->headers = array();
25
		}
26
27
28
		public function generateFromURL( $url ) {
29
			if ( !preg_match( '|^https?://|', $url ) ) {
30
				return ar_error::raiseError( "wkhtmltoimage: '$url' is not a valid URL", 201 );
31
			}
32
33
			$url = escapeshellarg( $url );
34
			$tempFile = tempnam( $this->config['temp'], 'pdf' );
35
			if ( !$tempFile ) {
36
				return ar_error::raiseError( "wkhtmltoimage: could not create a temporary file", 202 );
37
			}
38
39
			$execString = $this->config['cmd'];
40 View Code Duplication
			foreach ($this->options as $name => $value) {
41
				if ( is_bool( $name ) ) {
42
					$execString .= " --$name";
43
				} else {
44
					$execString .= " --$name " . escapeshellarg( $value );
45
				}
46
			}
47
48 View Code Duplication
			foreach ($this->cookies as $name => $value) {
49
				$execString .= " --cookie " . escapeshellarg( $name ) . " " . escapeshellarg( $value );
50
			}
51
52 View Code Duplication
			foreach ($this->headers as $name => $value) {
53
				$execString .= " --custom-header " . escapeshellarg( $name ) . " " . escapeshellarg( $value );
54
			}
55
56
			$execString .= " $url $tempFile";
57
			$execOutput = array();
58
			$execResult = 0;
59
60
			exec( $execString, $execOutput, $execResult );
61 View Code Duplication
			if ( $execResult != 0 && $execResult != 2 ) { // code 2 is for 404's encountered
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...
62
				@unlink( $tempFile );
63
				return ar_error::raiseError( "wkhtmltoimage: error ($execResult) while trying to generate image: " . implode( "\n", (array) $execOutput ), 203 );
64
			}
65
66
			readfile( $tempFile );
67
			unlink( $tempFile );
68
		}
69
70
		public function setCookieList( $cookieList = array() ) {
71
			if ( is_array($cookieList) ) {
72
				foreach( $cookieList as $name => $value) {
73
					$this->setOption( $name, $value );
74
				}
75
			}
76
		}
77
78
		public function setCookie($name, $value = null) {
79
			$this->cookies[ $name ] = $value;
80
		}
81
82
		public function setHeaderList( $headerList = array() ) {
83
			if ( is_array($headerList) ) {
84
				foreach( $headerList as $name => $value) {
85
					$this->setHeader( $name, $value );
86
				}
87
			}
88
		}
89
90
91
		public function setHeader($name, $value = null) {
92
			$this->headers[ $name ] = $value;
93
		}
94
95
96
		public function setOptionList( $optionList = array() ) {
97
			if ( is_array($optionList) ) {
98
				foreach( $optionList as $name => $value) {
99
					$this->setOption( $name, $value );
100
				}
101
			}
102
		}
103
104
		public function setOption($name, $value = null) {
105
			if ($value === null) {
106
				unset( $this->options[ $name ] );
107
				return true;
108
			}
109
			switch ($name) {
110
				case 'ignore-load-errors':
111
					$this->options[ $name ] = true;
112
				break;
113
				case 'format':
114
				case 'encoding':
115
				case 'username':
116
				case 'password':
117
				case 'title':
118
					$this->options[ $name ] = (string) $value;
119
				break;
120
				case 'zoom':
121
					$this->options[ $name ] = (float) $value;
122
				break;
123
				default:
124
					return false;
125
			}
126
			return true;
127
		}
128
129
	}
130
131
132
	class pinp_wkhtmltoimage {
133
		private $instance;
134
135
		public function __construct( $options = array() ) {
136
			$this->instance = new wkhtmltoimage();
137
			$this->instance->setOptionList( $options );
138
		}
139
140
		public function _generateFromURL( $url ) {
141
			return $this->instance->generateFromURL( $url );
142
		}
143
144
		static function _get( $options = array() ) {
145
			return new pinp_wkhtmltoimage( $options );
146
		}
147
148
149
150
	}
151