Issues (78)

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.

lib/service/html.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
/**
4
 * @author Christoph Wurst <[email protected]>
5
 * @author Jakob Sack <[email protected]>
6
 * @author Jakob Sack <[email protected]>
7
 * @author Lukas Reschke <[email protected]>
8
 * @author Thomas Müller <[email protected]>
9
 *
10
 * Mail
11
 *
12
 * This code is free software: you can redistribute it and/or modify
13
 * it under the terms of the GNU Affero General Public License, version 3,
14
 * as published by the Free Software Foundation.
15
 *
16
 * This program is distributed in the hope that it will be useful,
17
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19
 * GNU Affero General Public License for more details.
20
 *
21
 * You should have received a copy of the GNU Affero General Public License, version 3,
22
 * along with this program.  If not, see <http://www.gnu.org/licenses/>
23
 *
24
 */
25
26
namespace OCA\Mail\Service;
27
28
use Closure;
29
use HTMLPurifier;
30
use HTMLPurifier_Config;
31
use HTMLPurifier_HTMLDefinition;
32
use HTMLPurifier_URISchemeRegistry;
33
use Kwi\UrlLinker;
34
use OCA\Mail\Service\HtmlPurify\CidURIScheme;
35
use OCA\Mail\Service\HtmlPurify\TransformCSSBackground;
36
use OCA\Mail\Service\HtmlPurify\TransformHTMLLinks;
37
use OCA\Mail\Service\HtmlPurify\TransformImageSrc;
38
use OCA\Mail\Service\HtmlPurify\TransformNoReferrer;
39
use OCA\Mail\Service\HtmlPurify\TransformURLScheme;
40
use OCP\IRequest;
41
use OCP\IURLGenerator;
42
use OCP\Util;
43
44
class Html {
45
46
	/** @var IURLGenerator */
47
	private $urlGenerator;
48
49
	/** @var IRequest */
50
	private $request;
51
52 27
	public function __construct(IURLGenerator $urlGenerator, IRequest $request) {
53 27
		$this->urlGenerator = $urlGenerator;
54 27
		$this->request = $request;
55 27
	}
56
57
	/**
58
	 * @param string $data
59
	 * @return string
60
	 */
61 15
	public function convertLinks($data) {
62 15
		$linker = new UrlLinker(true, false);
63 15
		$data = $linker->linkUrlsInTrustedHtml($data);
64
65 15
		$config = HTMLPurifier_Config::createDefault();
66
67
		// Append target="_blank" to all link (a) elements
68 15
		$config->set('HTML.TargetBlank', true);
69
70
		// allow cid, http and ftp
71 15
		$config->set('URI.AllowedSchemes', ['http' => true, 'https' => true, 'ftp' => true, 'mailto' => true]);
72 15
		$config->set('URI.Host', Util::getServerHostName());
73
74
		// Disable the cache since ownCloud has no really appcache
75
		// TODO: Fix this - requires https://github.com/owncloud/core/issues/10767 to be fixed
76 15
		$config->set('Cache.DefinitionImpl', null);
77
78
		/** @var HTMLPurifier_HTMLDefinition $uri */
79 15
		$uri = $config->getDefinition('HTML');
80 15
		$uri->info_attr_transform_post['noreferrer'] = new TransformNoReferrer();
81
82 15
		$purifier = new HTMLPurifier($config);
83
84 15
		return $purifier->purify($data);
85
	}
86
87
	/**
88
	 * split off the signature
89
	 *
90
	 * @param string $body
91
	 * @return array
92
	 */
93 3
	public function parseMailBody($body) {
94 3
		$signature = null;
95 3
		$parts = explode("-- \r\n", $body);
96 3
		if (count($parts) > 1) {
97 2
			$signature = nl2br(array_pop($parts));
98 2
			$body = implode("-- \r\n", $parts);
99 2
		}
100
101
		return [
102 3
			$body,
103
			$signature
104 3
		];
105
	}
106
107 1
	public function sanitizeHtmlMailBody($mailBody, array $messageParameters, Closure $mapCidToAttachmentId) {
108 1
		$config = HTMLPurifier_Config::createDefault();
109
110
		// Append target="_blank" to all link (a) elements
111 1
		$config->set('HTML.TargetBlank', true);
112
113
		// allow cid, http and ftp
114 1
		$config->set('URI.AllowedSchemes', ['cid' => true, 'http' => true, 'https' => true, 'ftp' => true, 'mailto' => true]);
115 1
		$config->set('URI.Host', Util::getServerHostName());
116
117
		// Disable the cache since ownCloud has no really appcache
118
		// TODO: Fix this - requires https://github.com/owncloud/core/issues/10767 to be fixed
119 1
		$config->set('Cache.DefinitionImpl', null);
120
121
		// Rewrite URL for redirection and proxying of content
122 1
		$html = $config->getDefinition('HTML');
123 1
		$html->info_attr_transform_post['imagesrc'] = new TransformImageSrc($this->urlGenerator);
0 ignored issues
show
The property info_attr_transform_post does not seem to exist in HTMLPurifier_Definition.

An attempt at access to an undefined property has been detected. This may either be a typographical error or the property has been renamed but there are still references to its old name.

If you really want to allow access to undefined properties, you can define magic methods to allow access. See the php core documentation on Overloading.

Loading history...
124 1
		$html->info_attr_transform_post['cssbackground'] = new TransformCSSBackground($this->urlGenerator);
125 1
		$html->info_attr_transform_post['htmllinks'] = new TransformHTMLLinks();
126
127 1
		$uri = $config->getDefinition('URI');
128 1
		$uri->addFilter(new TransformURLScheme($messageParameters, $mapCidToAttachmentId, $this->urlGenerator, $this->request), $config);
129
130 1
		HTMLPurifier_URISchemeRegistry::instance()->register('cid', new CidURIScheme());
131
132 1
		$purifier = new HTMLPurifier($config);
133
134 1
		$result = $purifier->purify($mailBody);
135
		// eat xml parse errors within HTMLPurifier
136 1
		libxml_clear_errors();
137 1
		return $result;
138
	}
139
140
}
141