-
Notifications
You must be signed in to change notification settings - Fork 6
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
Integrate files_sharing_webapppassword #61
Changes from 8 commits
8c2c80b
ffba8f2
5256b5f
5151acb
ca23896
4811fda
d159d83
1e6ce9f
591197b
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,5 +7,49 @@ | |
['name' => 'page#index', 'url' => '/', 'verb' => 'GET'], | ||
['name' => 'page#create_token', 'url' => '/create', 'verb' => 'POST'], | ||
['name' => 'admin#update', 'url' => '/admin', 'verb' => 'PUT'], | ||
/* | ||
* OCS Share API | ||
*/ | ||
[ | ||
'name' => 'ShareAPI#getShares', | ||
'url' => '/api/v1/shares', | ||
'verb' => 'GET', | ||
], | ||
[ | ||
'name' => 'ShareAPI#getInheritedShares', | ||
'url' => '/api/v1/shares/inherited', | ||
'verb' => 'GET', | ||
], | ||
[ | ||
'name' => 'ShareAPI#createShare', | ||
'url' => '/api/v1/shares', | ||
'verb' => 'POST', | ||
], | ||
[ | ||
'name' => 'ShareAPI#preflighted_cors', | ||
'url' => '/api/v1/shares', | ||
'verb' => 'OPTIONS', | ||
], | ||
[ | ||
'name' => 'ShareAPI#pendingShares', | ||
'url' => '/api/v1/shares/pending', | ||
'verb' => 'GET', | ||
], | ||
[ | ||
'name' => 'ShareAPI#getShare', | ||
'url' => '/api/v1/shares/{id}', | ||
'verb' => 'GET', | ||
], | ||
[ | ||
'name' => 'ShareAPI#updateShare', | ||
'url' => '/api/v1/shares/{id}', | ||
'verb' => 'PUT', | ||
], | ||
[ | ||
'name' => 'ShareAPI#deleteShare', | ||
'url' => '/api/v1/shares/{id}', | ||
'verb' => 'DELETE', | ||
] | ||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Aren't those Nextcloud routes? Why do they need to be included in webapppassword? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. In fact it is reimplementing the files_sharing api in webapppassword namespace to be able to apply the filtering of origins. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ok, I see. This really should belong into Nextcloud core. 😅 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Added, and restructured the settings to sections. It may include the copy url button and the real base url but this may add noise to this MR. maybe in next merge requests... |
||
], | ||
]; |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -9,3 +9,7 @@ | |
#webapppassword-origins { | ||
width: 100%; | ||
} | ||
|
||
#files-sharing-webapppassword-origins { | ||
width: 100%; | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
<?php | ||
declare(strict_types=1); | ||
// SPDX-FileCopyrightText: Aleix Quintana Alsius <kinta@communia.org> | ||
// SPDX-License-Identifier: AGPL-3.0-or-later | ||
|
||
namespace OCA\WebAppPassword\Controller; | ||
|
||
use OCP\AppFramework\Http\DataResponse; | ||
use OCP\AppFramework\OCS\OCSNotFoundException; | ||
|
||
trait AccessControl { | ||
/** | ||
* Checks the origin of a request and modifies response. | ||
* | ||
* @param DataResponse $response | ||
* @return DataResponse | ||
* @throws NotFoundException | ||
* @throws OCSBadRequestException | ||
* @throws OCSException | ||
* @throws OCSForbiddenException | ||
* @throws OCSNotFoundException | ||
* @throws InvalidPathException | ||
* @suppress PhanUndeclaredClassMethod | ||
*/ | ||
protected function checkOrigin( DataResponse $response | ||
): DataResponse { | ||
$origins_allowed = $this->getOriginList(); | ||
if (in_array('access-control-allow-origin', $response->getHeaders())) { | ||
throw new OCSNotFoundException($this->l->t('Could not create share')); | ||
} | ||
|
||
$origin = $this->request->getHeader('origin'); | ||
if (empty($origin) || !in_array($origin, $origins_allowed, true)) { | ||
throw new OCSNotFoundException($this->l->t('Could not create share')); | ||
} | ||
|
||
$response->addHeader('access-control-allow-origin', $origin); | ||
$response->addHeader('access-control-allow-methods', $this->request->getHeader('access-control-request-method')); | ||
$response->addHeader('access-control-allow-headers', $this->request->getHeader('access-control-request-headers')); | ||
$response->addHeader('access-control-expose-headers', 'etag, dav'); | ||
$response->addHeader('access-control-allow-credentials', 'true'); | ||
return $response; | ||
} | ||
|
||
/** | ||
* Serializes the allowed origins in a string. | ||
* | ||
* @return string | ||
* List allowed origins separated by commas. | ||
* | ||
*/ | ||
protected function getOrigins(): string | ||
{ | ||
// TODO DI $this->config->getAppValue('files_sharing_origins', 'origins'); | ||
// __construct must be reimplemented as config prop in parent is private... | ||
$config = \OC::$server->getConfig(); | ||
$origins = $config->getAppValue('webapppassword', 'files_sharing_origins'); | ||
|
||
if ($origins === '') { | ||
$origins = implode(',', $config->getSystemValue('webapppassword.files_sharing_origins', [])); | ||
} | ||
|
||
if ($origins === null) { | ||
$origins = ''; | ||
} | ||
|
||
return implode(',', array_map('trim', explode(',', $origins))); | ||
} | ||
|
||
/** | ||
* Gets an array of the defined allowed origins | ||
* | ||
* @return array | ||
* List of allowed origins. | ||
*/ | ||
protected function getOriginList() | ||
{ | ||
return explode(',', $this->getOrigins()); | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Typo: "Alos" => "Also"