Skip to content

Commit 9453d8a

Browse files
committed
[SECURITY] Avoid disclosing loaded extensions
Inline JavaScript settings for RequireJS and ajaxUrls disclose the existence of specific extensions in a TYPO3 installation. In case no backend user is logged in RequireJS settings are fetched using an according endpoint, ajaxUrls (for backend AJAX routes) are limited to those that are accessible without having a user session. Resolves: #83855 Releases: master, 9.5, 8.7 Security-Commit: a6275dcec387039a8a40972f3f8a8607d20fe6dd Security-Bulletin: TYPO3-CORE-SA-2019-001 Change-Id: I7be7e93b2bd67ddcb2e10863577090b34182c555 Reviewed-on: https://review.typo3.org/59527 Reviewed-by: Oliver Hader <[email protected]> Tested-by: Oliver Hader <[email protected]>
1 parent 3ccf7ed commit 9453d8a

File tree

5 files changed

+441
-23
lines changed

5 files changed

+441
-23
lines changed
Lines changed: 109 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,109 @@
1+
<?php
2+
declare(strict_types = 1);
3+
namespace TYPO3\CMS\Core\Controller;
4+
5+
/*
6+
* This file is part of the TYPO3 CMS project.
7+
*
8+
* It is free software; you can redistribute it and/or modify it under
9+
* the terms of the GNU General Public License, either version 2
10+
* of the License, or any later version.
11+
*
12+
* For the full copyright and license information, please read the
13+
* LICENSE.txt file that was distributed with this source code.
14+
*
15+
* The TYPO3 project - inspiring people to share!
16+
*/
17+
18+
use Psr\Http\Message\ResponseInterface;
19+
use Psr\Http\Message\ServerRequestInterface;
20+
use TYPO3\CMS\Core\Http\JsonResponse;
21+
use TYPO3\CMS\Core\Page\PageRenderer;
22+
use TYPO3\CMS\Core\Utility\GeneralUtility;
23+
24+
/**
25+
* Handling requirejs client requests.
26+
*/
27+
class RequireJsController
28+
{
29+
/**
30+
* @var PageRenderer
31+
*/
32+
protected $pageRenderer;
33+
34+
public function __construct()
35+
{
36+
$this->pageRenderer = GeneralUtility::makeInstance(PageRenderer::class);
37+
}
38+
39+
/**
40+
* Retrieves additional requirejs configuration for a given module name or module path.
41+
*
42+
* The JSON result e.g. could look like:
43+
* {
44+
* "shim": {
45+
* "vendor/module": ["exports" => "TheModule"]
46+
* },
47+
* "paths": {
48+
* "vendor/module": "/public/web/path/"
49+
* },
50+
* "packages": {
51+
* [
52+
* "name": "module",
53+
* ...
54+
* ]
55+
* }
56+
* }
57+
*
58+
* Parameter name either could be the module name ("vendor/module") or a
59+
* module path ("vendor/module/component") belonging to a module.
60+
*
61+
* @param ServerRequestInterface $request
62+
* @return ResponseInterface
63+
*/
64+
public function retrieveConfiguration(ServerRequestInterface $request): ResponseInterface
65+
{
66+
$name = $request->getQueryParams()['name'] ?? null;
67+
if (empty($name) || !is_string($name)) {
68+
return new JsonResponse(null, 404);
69+
}
70+
$configuration = $this->findConfiguration($name);
71+
return new JsonResponse($configuration, !empty($configuration) ? 200 : 404);
72+
}
73+
74+
/**
75+
* @param string $name
76+
* @return array
77+
*/
78+
protected function findConfiguration(string $name): array
79+
{
80+
$relevantConfiguration = [];
81+
$this->pageRenderer->loadRequireJs();
82+
$configuration = $this->pageRenderer->getRequireJsConfig(PageRenderer::REQUIREJS_SCOPE_RESOLVE);
83+
84+
$shim = $configuration['shim'] ?? [];
85+
foreach ($shim as $baseModuleName => $baseModuleConfiguration) {
86+
if (strpos($name . '/', $baseModuleName . '/') === 0) {
87+
$relevantConfiguration['shim'][$baseModuleName] = $baseModuleConfiguration;
88+
}
89+
}
90+
91+
$paths = $configuration['paths'] ?? [];
92+
foreach ($paths as $baseModuleName => $baseModulePath) {
93+
if (strpos($name . '/', $baseModuleName . '/') === 0) {
94+
$relevantConfiguration['paths'][$baseModuleName] = $baseModulePath;
95+
}
96+
}
97+
98+
$packages = $configuration['packages'] ?? [];
99+
foreach ($packages as $package) {
100+
if (!empty($package['name'])
101+
&& strpos($name . '/', $package['name'] . '/') === 0
102+
) {
103+
$relevantConfiguration['packages'][] = $package;
104+
}
105+
}
106+
107+
return $relevantConfiguration;
108+
}
109+
}

0 commit comments

Comments
 (0)