Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Don't inject Bruteforce capability info in the webui #31848

Merged
merged 1 commit into from
Apr 11, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions lib/composer/composer/autoload_classmap.php
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,7 @@
'OCP\\Calendar\\Room\\IRoom' => $baseDir . '/lib/public/Calendar/Room/IRoom.php',
'OCP\\Calendar\\Room\\IRoomMetadata' => $baseDir . '/lib/public/Calendar/Room/IRoomMetadata.php',
'OCP\\Capabilities\\ICapability' => $baseDir . '/lib/public/Capabilities/ICapability.php',
'OCP\\Capabilities\\IInitialStateExcludedCapability' => $baseDir . '/lib/public/Capabilities/IInitialStateExcludedCapability.php',
'OCP\\Capabilities\\IPublicCapability' => $baseDir . '/lib/public/Capabilities/IPublicCapability.php',
'OCP\\Collaboration\\AutoComplete\\AutoCompleteEvent' => $baseDir . '/lib/public/Collaboration/AutoComplete/AutoCompleteEvent.php',
'OCP\\Collaboration\\AutoComplete\\IManager' => $baseDir . '/lib/public/Collaboration/AutoComplete/IManager.php',
Expand Down
1 change: 1 addition & 0 deletions lib/composer/composer/autoload_static.php
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,7 @@ class ComposerStaticInit53792487c5a8370acc0b06b1a864ff4c
'OCP\\Calendar\\Room\\IRoom' => __DIR__ . '/../../..' . '/lib/public/Calendar/Room/IRoom.php',
'OCP\\Calendar\\Room\\IRoomMetadata' => __DIR__ . '/../../..' . '/lib/public/Calendar/Room/IRoomMetadata.php',
'OCP\\Capabilities\\ICapability' => __DIR__ . '/../../..' . '/lib/public/Capabilities/ICapability.php',
'OCP\\Capabilities\\IInitialStateExcludedCapability' => __DIR__ . '/../../..' . '/lib/public/Capabilities/IInitialStateExcludedCapability.php',
'OCP\\Capabilities\\IPublicCapability' => __DIR__ . '/../../..' . '/lib/public/Capabilities/IPublicCapability.php',
'OCP\\Collaboration\\AutoComplete\\AutoCompleteEvent' => __DIR__ . '/../../..' . '/lib/public/Collaboration/AutoComplete/AutoCompleteEvent.php',
'OCP\\Collaboration\\AutoComplete\\IManager' => __DIR__ . '/../../..' . '/lib/public/Collaboration/AutoComplete/IManager.php',
Expand Down
8 changes: 7 additions & 1 deletion lib/private/CapabilitiesManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
use OCP\AppFramework\QueryException;
use OCP\Capabilities\ICapability;
use OCP\Capabilities\IPublicCapability;
use OCP\Capabilities\IInitialStateExcludedCapability;
use Psr\Log\LoggerInterface;

class CapabilitiesManager {
Expand All @@ -52,7 +53,7 @@ public function __construct(LoggerInterface $logger) {
* @throws \InvalidArgumentException
* @return array
*/
public function getCapabilities(bool $public = false) : array {
public function getCapabilities(bool $public = false, bool $initialState = false) : array {
$capabilities = [];
foreach ($this->capabilities as $capability) {
try {
Expand All @@ -66,6 +67,11 @@ public function getCapabilities(bool $public = false) : array {

if ($c instanceof ICapability) {
if (!$public || $c instanceof IPublicCapability) {
if ($initialState && ($c instanceof IInitialStateExcludedCapability)) {
// Remove less important capabilities information that are expensive to query
// that we would otherwise inject to every page load
continue;
}
$capabilities = array_replace_recursive($capabilities, $c->getCapabilities());
}
} else {
Expand Down
3 changes: 2 additions & 1 deletion lib/private/Security/Bruteforce/Capabilities.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,10 @@
namespace OC\Security\Bruteforce;

use OCP\Capabilities\IPublicCapability;
use OCP\Capabilities\IInitialStateExcludedCapability;
use OCP\IRequest;

class Capabilities implements IPublicCapability {
class Capabilities implements IPublicCapability, IInitialStateExcludedCapability {
/** @var IRequest */
private $request;

Expand Down
2 changes: 1 addition & 1 deletion lib/private/Template/JSConfigHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,7 @@ public function getConfig() {
$lastConfirmTimestamp = 0;
}

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

$config = [
'session_lifetime' => min($this->config->getSystemValue('session_lifetime', $this->iniWrapper->getNumeric('session.gc_maxlifetime')), $this->iniWrapper->getNumeric('session.gc_maxlifetime')),
Expand Down
34 changes: 34 additions & 0 deletions lib/public/Capabilities/IInitialStateExcludedCapability.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
<?php

declare(strict_types=1);

/**
* @copyright Copyright (c) 2022 Carl Schwan <carl@carlschwan.eu>
*
* @license GNU AGPL version 3 or any later version
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
*/
namespace OCP\Capabilities;

/**
* Indicate that a capability should not be injected in the initial state
* of the page as it might be expensive to query and not useful for the
* webui.
*
* @since 24.0.0
*/
interface IInitialStateExcludedCapability {
CarlSchwan marked this conversation as resolved.
Show resolved Hide resolved
}