Skip to content

Commit 56e0149

Browse files
committed
feat: no iframe, remove view route, csp for iframe
Signed-off-by: Sebastien Marinier <seb@smarinier.net>
1 parent 5fa1212 commit 56e0149

File tree

2 files changed

+1
-48
lines changed

2 files changed

+1
-48
lines changed

appinfo/routes.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
return [
77
'routes' => [
88
['name' => 'page#index', 'url' => '/', 'verb' => 'GET'],
9-
['name' => 'page#view', 'url' => '/view/{app}', 'verb' => 'GET'],
109
['name' => 'apps#index', 'url' => '/apps', 'verb' => 'GET'],
1110
['name' => 'apps#load', 'url' => '/apps/{app}', 'verb' => 'GET'],
1211
]

lib/Controller/PageController.php

Lines changed: 1 addition & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -5,30 +5,17 @@
55

66
namespace OCA\OCSAPIViewer\Controller;
77

8-
use OC\Security\CSP\ContentSecurityPolicyNonceManager;
98
use OCA\OCSAPIViewer\AppInfo\Application;
10-
use OCA\Theming\Service\ThemesService;
11-
use OCP\App\IAppManager;
129
use OCP\AppFramework\Controller;
13-
use OCP\AppFramework\Http\ContentSecurityPolicy;
1410
use OCP\AppFramework\Http\TemplateResponse;
1511
use OCP\IRequest;
1612
use OCP\Util;
1713

1814
class PageController extends Controller {
19-
private ThemesService $themesService;
20-
private IAppManager $appManager;
21-
private ContentSecurityPolicyNonceManager $nonceManager;
2215

2316
public function __construct(
2417
IRequest $request,
25-
ThemesService $themesService,
26-
IAppManager $appManager,
27-
ContentSecurityPolicyNonceManager $nonceManager
2818
) {
29-
$this->appManager = $appManager;
30-
$this->themesService = $themesService;
31-
$this->nonceManager = $nonceManager;
3219
parent::__construct(Application::APP_ID, $request);
3320
}
3421

@@ -39,40 +26,7 @@ public function __construct(
3926
public function index(): TemplateResponse {
4027
Util::addScript(Application::APP_ID, Application::APP_ID . '-main');
4128

42-
$response = new TemplateResponse(Application::APP_ID, 'main');
43-
$csp = new ContentSecurityPolicy();
44-
$csp->addAllowedFrameDomain("'self'");
45-
$response->setContentSecurityPolicy($csp);
46-
return $response;
29+
return new TemplateResponse(Application::APP_ID, 'main');
4730
}
4831

49-
/**
50-
* @NoAdminRequired
51-
* @NoCSRFRequired
52-
*/
53-
public function view(string $app): TemplateResponse {
54-
// We can't load the script and initial state here, because otherwise all the other scripts would load too
55-
56-
$theme = 'system';
57-
$enabledThemes = array_map(fn(string $id) => explode('-', $id)[0], $this->themesService->getEnabledThemes());
58-
if (count(array_filter($enabledThemes, fn(string $id) => $id == 'dark')) > 0) {
59-
$theme = 'dark';
60-
} else if (count(array_filter($enabledThemes, fn(string $id) => $id == 'light')) > 0) {
61-
$theme = 'light';
62-
}
63-
64-
$response = new TemplateResponse(Application::APP_ID, 'iframe', [
65-
'app' => $app,
66-
'viewer-root' => $this->appManager->getAppWebPath(Application::APP_ID),
67-
'theme' => $theme,
68-
'nonce' => $this->nonceManager->getNonce(),
69-
], TemplateResponse::RENDER_AS_BLANK);
70-
$csp = new ContentSecurityPolicy();
71-
$csp->addAllowedFrameAncestorDomain("'self'");
72-
$csp->addAllowedScriptDomain("'unsafe-eval'");
73-
$csp->addAllowedScriptDomain("'unsafe-inline'");
74-
$csp->addAllowedScriptDomain('*');
75-
$response->setContentSecurityPolicy($csp);
76-
return $response;
77-
}
7832
}

0 commit comments

Comments
 (0)