Skip to content

Commit 682468e

Browse files
authored
Merge pull request #31848 from nextcloud/performance/trottling-capability-frontent
Don't inject Bruteforce capability info in the webui
2 parents 0b8582f + 69b36fc commit 682468e

File tree

6 files changed

+46
-3
lines changed

6 files changed

+46
-3
lines changed

lib/composer/composer/autoload_classmap.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,7 @@
133133
'OCP\\Calendar\\Room\\IRoom' => $baseDir . '/lib/public/Calendar/Room/IRoom.php',
134134
'OCP\\Calendar\\Room\\IRoomMetadata' => $baseDir . '/lib/public/Calendar/Room/IRoomMetadata.php',
135135
'OCP\\Capabilities\\ICapability' => $baseDir . '/lib/public/Capabilities/ICapability.php',
136+
'OCP\\Capabilities\\IInitialStateExcludedCapability' => $baseDir . '/lib/public/Capabilities/IInitialStateExcludedCapability.php',
136137
'OCP\\Capabilities\\IPublicCapability' => $baseDir . '/lib/public/Capabilities/IPublicCapability.php',
137138
'OCP\\Collaboration\\AutoComplete\\AutoCompleteEvent' => $baseDir . '/lib/public/Collaboration/AutoComplete/AutoCompleteEvent.php',
138139
'OCP\\Collaboration\\AutoComplete\\IManager' => $baseDir . '/lib/public/Collaboration/AutoComplete/IManager.php',

lib/composer/composer/autoload_static.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -162,6 +162,7 @@ class ComposerStaticInit53792487c5a8370acc0b06b1a864ff4c
162162
'OCP\\Calendar\\Room\\IRoom' => __DIR__ . '/../../..' . '/lib/public/Calendar/Room/IRoom.php',
163163
'OCP\\Calendar\\Room\\IRoomMetadata' => __DIR__ . '/../../..' . '/lib/public/Calendar/Room/IRoomMetadata.php',
164164
'OCP\\Capabilities\\ICapability' => __DIR__ . '/../../..' . '/lib/public/Capabilities/ICapability.php',
165+
'OCP\\Capabilities\\IInitialStateExcludedCapability' => __DIR__ . '/../../..' . '/lib/public/Capabilities/IInitialStateExcludedCapability.php',
165166
'OCP\\Capabilities\\IPublicCapability' => __DIR__ . '/../../..' . '/lib/public/Capabilities/IPublicCapability.php',
166167
'OCP\\Collaboration\\AutoComplete\\AutoCompleteEvent' => __DIR__ . '/../../..' . '/lib/public/Collaboration/AutoComplete/AutoCompleteEvent.php',
167168
'OCP\\Collaboration\\AutoComplete\\IManager' => __DIR__ . '/../../..' . '/lib/public/Collaboration/AutoComplete/IManager.php',

lib/private/CapabilitiesManager.php

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131
use OCP\AppFramework\QueryException;
3232
use OCP\Capabilities\ICapability;
3333
use OCP\Capabilities\IPublicCapability;
34+
use OCP\Capabilities\IInitialStateExcludedCapability;
3435
use Psr\Log\LoggerInterface;
3536

3637
class CapabilitiesManager {
@@ -52,7 +53,7 @@ public function __construct(LoggerInterface $logger) {
5253
* @throws \InvalidArgumentException
5354
* @return array
5455
*/
55-
public function getCapabilities(bool $public = false) : array {
56+
public function getCapabilities(bool $public = false, bool $initialState = false) : array {
5657
$capabilities = [];
5758
foreach ($this->capabilities as $capability) {
5859
try {
@@ -66,6 +67,11 @@ public function getCapabilities(bool $public = false) : array {
6667

6768
if ($c instanceof ICapability) {
6869
if (!$public || $c instanceof IPublicCapability) {
70+
if ($initialState && ($c instanceof IInitialStateExcludedCapability)) {
71+
// Remove less important capabilities information that are expensive to query
72+
// that we would otherwise inject to every page load
73+
continue;
74+
}
6975
$capabilities = array_replace_recursive($capabilities, $c->getCapabilities());
7076
}
7177
} else {

lib/private/Security/Bruteforce/Capabilities.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,9 +28,10 @@
2828
namespace OC\Security\Bruteforce;
2929

3030
use OCP\Capabilities\IPublicCapability;
31+
use OCP\Capabilities\IInitialStateExcludedCapability;
3132
use OCP\IRequest;
3233

33-
class Capabilities implements IPublicCapability {
34+
class Capabilities implements IPublicCapability, IInitialStateExcludedCapability {
3435
/** @var IRequest */
3536
private $request;
3637

lib/private/Template/JSConfigHelper.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -187,7 +187,7 @@ public function getConfig() {
187187
$lastConfirmTimestamp = 0;
188188
}
189189

190-
$capabilities = $this->capabilitiesManager->getCapabilities();
190+
$capabilities = $this->capabilitiesManager->getCapabilities(false, true);
191191

192192
$config = [
193193
'session_lifetime' => min($this->config->getSystemValue('session_lifetime', $this->iniWrapper->getNumeric('session.gc_maxlifetime')), $this->iniWrapper->getNumeric('session.gc_maxlifetime')),
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
/**
6+
* @copyright Copyright (c) 2022 Carl Schwan <carl@carlschwan.eu>
7+
*
8+
* @license GNU AGPL version 3 or any later version
9+
*
10+
* This program is free software: you can redistribute it and/or modify
11+
* it under the terms of the GNU Affero General Public License as
12+
* published by the Free Software Foundation, either version 3 of the
13+
* License, or (at your option) any later version.
14+
*
15+
* This program is distributed in the hope that it will be useful,
16+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
17+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18+
* GNU Affero General Public License for more details.
19+
*
20+
* You should have received a copy of the GNU Affero General Public License
21+
* along with this program. If not, see <http://www.gnu.org/licenses/>.
22+
*
23+
*/
24+
namespace OCP\Capabilities;
25+
26+
/**
27+
* Indicate that a capability should not be injected in the initial state
28+
* of the page as it might be expensive to query and not useful for the
29+
* webui.
30+
*
31+
* @since 24.0.0
32+
*/
33+
interface IInitialStateExcludedCapability {
34+
}

0 commit comments

Comments
 (0)