Skip to content

Commit

Permalink
Merge pull request #98 from nextcloud/fix/safari-form-action
Browse files Browse the repository at this point in the history
  • Loading branch information
skjnldsv authored Apr 3, 2024
2 parents 7bcc08f + 510e429 commit 0b21861
Showing 1 changed file with 13 additions and 3 deletions.
16 changes: 13 additions & 3 deletions lib/Controller/PasswordController.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@

use OC\Authentication\Token\IProvider;
use OCP\AppFramework\Controller;
use OCP\AppFramework\Http\ContentSecurityPolicy;
use OCP\AppFramework\Http\RedirectResponse;
use OCP\AppFramework\Http\TemplateResponse;
use OCP\IConfig;
Expand Down Expand Up @@ -195,7 +196,6 @@ public function submitPassword(string $token, string $email, string $password, s
if ($ocsapirequest === '1') {
$clientName = $this->getClientName();
$redirectUri = $this->generateAppPassword($email, $clientName);

return new RedirectResponse($redirectUri);
}

Expand All @@ -220,17 +220,27 @@ public function submitPassword(string $token, string $email, string $password, s
* @return TemplateResponse
*/
protected function generateTemplate(string $token, string $email, string $error = '', bool $ocs = false) {
return new TemplateResponse(
$response = new TemplateResponse(
$this->appName,
'password-public',
array(
'link' => $this->urlGenerator->linkToRouteAbsolute($this->appName . '.password.submit_password', array('token' => $token)),
'link' => $this->urlGenerator->linkToRoute($this->appName . '.password.submit_password', array('token' => $token)),
'email' => $email,
'ocsapirequest' => $this->request->getHeader('OCS-APIREQUEST') || $ocs,
'error' => $error
),
'guest'
);

if ($ocs) {
// We need to set the CSP header to allow the redirect to the Nextcloud client
// some browsers (e.g. Safari) seems to block the redirect if the CSP header is not set.
$csp = new ContentSecurityPolicy();
$csp->addAllowedFormActionDomain('nc://*');
$response->setContentSecurityPolicy($csp);
}

return $response;
}

/**
Expand Down

0 comments on commit 0b21861

Please sign in to comment.