1
|
|
|
<?php |
2
|
|
|
declare(strict_types=1); |
3
|
|
|
|
4
|
|
|
/** |
5
|
|
|
* @author Christoph Wurst <[email protected]> |
6
|
|
|
* |
7
|
|
|
* @license GNU AGPL version 3 or any later version |
8
|
|
|
* |
9
|
|
|
* This program is free software: you can redistribute it and/or modify |
10
|
|
|
* it under the terms of the GNU Affero General Public License as |
11
|
|
|
* published by the Free Software Foundation, either version 3 of the |
12
|
|
|
* License, or (at your option) any later version. |
13
|
|
|
* |
14
|
|
|
* This program is distributed in the hope that it will be useful, |
15
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
16
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
17
|
|
|
* GNU Affero General Public License for more details. |
18
|
|
|
* |
19
|
|
|
* You should have received a copy of the GNU Affero General Public License |
20
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>. |
21
|
|
|
* |
22
|
|
|
*/ |
23
|
|
|
|
24
|
|
|
namespace OCA\Sentry\AppInfo; |
25
|
|
|
|
26
|
|
|
use OC; |
27
|
|
|
use OCA\Sentry\Reporter\SentryReporterBreadcrumbAdapter; |
|
|
|
|
28
|
|
|
use OCA\Sentry\Reporter\SentryReporterAdapter; |
29
|
|
|
use OCP\AppFramework\App; |
30
|
|
|
use OCP\AppFramework\Http\ContentSecurityPolicy; |
31
|
|
|
use OCP\IConfig; |
32
|
|
|
use OCP\Security\IContentSecurityPolicyManager; |
33
|
|
|
use OCP\Support\CrashReport\IRegistry; |
34
|
|
|
use Raven_Client; |
35
|
|
|
use Raven_ErrorHandler; |
36
|
|
|
|
37
|
|
|
class Application extends App { |
38
|
|
|
|
39
|
|
|
/** |
40
|
|
|
* @param array $urlParams |
41
|
|
|
*/ |
42
|
|
|
public function __construct($urlParams = []) { |
43
|
|
|
parent::__construct('sentry', $urlParams); |
44
|
|
|
|
45
|
|
|
$container = $this->getContainer(); |
46
|
|
|
|
47
|
|
|
/* @var $config IConfig */ |
48
|
|
|
$config = $container->query(IConfig::class); |
49
|
|
|
/** @var IContentSecurityPolicyManager $cspManager */ |
50
|
|
|
$cspManager = $container->query(IContentSecurityPolicyManager::class); |
51
|
|
|
|
52
|
|
|
$dsn = $config->getSystemValue('sentry.dsn', null); |
53
|
|
|
$reportUrl = $config->getSystemValue('sentry.csp-report-url', null); |
54
|
|
|
if (!is_null($dsn)) { |
55
|
|
|
$this->registerClient($config, $dsn); |
56
|
|
|
} |
57
|
|
|
$publicDsn = $config->getSystemValue('sentry.public-dsn', null); |
58
|
|
|
$this->addCsp($cspManager, $publicDsn, $reportUrl); |
59
|
|
|
} |
60
|
|
|
|
61
|
|
|
/** |
62
|
|
|
* @param string $dsn |
63
|
|
|
*/ |
64
|
|
|
private function registerClient(IConfig $config, string $dsn) { |
65
|
|
|
$container = $this->getContainer(); |
66
|
|
|
|
67
|
|
|
$client = new Raven_Client($dsn); |
68
|
|
|
$client->setRelease($config->getSystemValue('version', '0.0.0')); |
69
|
|
|
$container->registerService(Raven_Client::class, function () use ($client) { |
70
|
|
|
return $client; |
71
|
|
|
}); |
72
|
|
|
|
73
|
|
|
/* @var $registry IRegistry */ |
74
|
|
|
$registry = $container->query(IRegistry::class); |
75
|
|
|
$reporter = $container->query(SentryReporterAdapter::class); |
76
|
|
|
$registry->register($reporter); |
77
|
|
|
|
78
|
|
|
$this->registerErrorHandlers($client); |
79
|
|
|
} |
80
|
|
|
|
81
|
|
|
private function registerErrorHandlers(Raven_Client $client) { |
82
|
|
|
$errorHandler = new Raven_ErrorHandler($client); |
83
|
|
|
$errorHandler->registerExceptionHandler(); |
84
|
|
|
$errorHandler->registerErrorHandler(); |
85
|
|
|
$errorHandler->registerShutdownFunction(); |
86
|
|
|
} |
87
|
|
|
|
88
|
|
|
public function addCsp(IContentSecurityPolicyManager $cspManager, |
89
|
|
|
string $publicDsn = null, |
90
|
|
|
string $reportUrl = null) { |
91
|
|
|
if (is_null($publicDsn) && is_null($reportUrl)) { |
92
|
|
|
// Don't add any custom CSP |
93
|
|
|
return; |
94
|
|
|
} |
95
|
|
|
|
96
|
|
|
$csp = new ContentSecurityPolicy(); |
|
|
|
|
97
|
|
|
|
98
|
|
|
if (!is_null($publicDsn)) { |
99
|
|
|
$parsedUrl = parse_url($publicDsn); |
100
|
|
|
if (!isset($parsedUrl['scheme']) || !isset($parsedUrl['host'])) { |
101
|
|
|
// Misconfigured setup -> ignore |
102
|
|
|
return; |
103
|
|
|
} |
104
|
|
|
|
105
|
|
|
$domain = $parsedUrl['scheme'] . '://' . $parsedUrl['host']; |
106
|
|
|
$csp->addAllowedConnectDomain($domain); |
107
|
|
|
} |
108
|
|
|
|
109
|
|
|
if (!is_null($reportUrl)) { |
110
|
|
|
$csp->addReportTo($reportUrl); |
|
|
|
|
111
|
|
|
} |
112
|
|
|
|
113
|
|
|
$cspManager->addDefaultPolicy($csp); |
114
|
|
|
} |
115
|
|
|
|
116
|
|
|
} |
117
|
|
|
|
The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g.
excluded_paths: ["lib/*"]
, you can move it to the dependency path list as follows:For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths