Skip to content

Commit 9bd98d9

Browse files
authored
Merge pull request #791 from nextcloud/backport/788/stable-5.1
[stable-5.1] refactor(Controller): read parameter only once
2 parents 37098ed + 3c34ebe commit 9bd98d9

File tree

5 files changed

+26
-78
lines changed

5 files changed

+26
-78
lines changed

.drone.yml

Lines changed: 1 addition & 71 deletions
Original file line numberDiff line numberDiff line change
@@ -67,77 +67,7 @@ trigger:
6767
- pull_request
6868
- push
6969

70-
type: docker
71-
72-
---
73-
kind: pipeline
74-
name: integration-tests-stable22
75-
76-
clone:
77-
depth: 1
78-
79-
steps:
80-
- name: integration-tests-stable22
81-
image: ghcr.io/nextcloud/continuous-integration-user_saml_shibboleth-php7.3:latest
82-
environment:
83-
CORE_BRANCH: stable22
84-
commands:
85-
- /start.sh &
86-
- /wait-for-services.sh
87-
- rm -rf /var/www/html
88-
- cd /var/www/
89-
- git clone --depth 1 -b $CORE_BRANCH https://github.com/nextcloud/server html
90-
- cd /var/www/html && git submodule update --init
91-
# use local clone
92-
- cp -r /drone/src /var/www/html/apps/user_saml
93-
- scl enable rh-php73 "bash -c 'php /var/www/html/occ maintenance:install --database sqlite --admin-pass password; php /var/www/html/occ app:enable user_saml'"
94-
- chown -R apache:apache /var/www/html/
95-
- scl enable rh-php73 "bash -c 'cd /var/www/html/apps/user_saml/tests/integration && vendor/bin/behat'"
96-
97-
trigger:
98-
branch:
99-
- master
100-
- stable*
101-
event:
102-
- pull_request
103-
- push
104-
105-
type: docker
106-
107-
---
108-
kind: pipeline
109-
name: integration-tests-stable21
110-
111-
clone:
112-
depth: 1
113-
114-
steps:
115-
- name: integration-tests-stable21
116-
image: ghcr.io/nextcloud/continuous-integration-user_saml_shibboleth-php7.3:latest
117-
environment:
118-
CORE_BRANCH: stable21
119-
commands:
120-
- /start.sh &
121-
- /wait-for-services.sh
122-
- rm -rf /var/www/html
123-
- cd /var/www/
124-
- git clone --depth 1 -b $CORE_BRANCH https://github.com/nextcloud/server html
125-
- cd /var/www/html && git submodule update --init
126-
# use local clone
127-
- cp -r /drone/src /var/www/html/apps/user_saml
128-
- scl enable rh-php73 "bash -c 'php /var/www/html/occ maintenance:install --database sqlite --admin-pass password; php /var/www/html/occ app:enable user_saml'"
129-
- chown -R apache:apache /var/www/html/
130-
- scl enable rh-php73 "bash -c 'cd /var/www/html/apps/user_saml/tests/integration && vendor/bin/behat'"
131-
132-
trigger:
133-
branch:
134-
- master
135-
- stable*
136-
event:
137-
- pull_request
138-
- push
139-
14070
type: docker
14171
---
14272
kind: signature
143-
hmac: a52d842da41e201e20d05b1f9b79289f29d38347a02a0455e03223dc244856d5
73+
hmac: 68850e2cb40f63c6c75cd56498acc4706222cbd10c69ddf0d02f604fced2eb0e

.github/workflows/phpunit-sqlite.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ jobs:
4444
strategy:
4545
matrix:
4646
php-versions: ['7.4', '8.0']
47-
server-versions: ['stable21', 'stable22', 'stable23', 'stable24']
47+
server-versions: ['stable23', 'stable24']
4848
include:
4949
- php-versions: '8.1'
5050
server-versions: 'stable24'

appinfo/info.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ While theoretically any other authentication provider implementing either one of
3333
<screenshot>https://raw.githubusercontent.com/nextcloud/user_saml/master/screenshots/1.png</screenshot>
3434
<screenshot>https://raw.githubusercontent.com/nextcloud/user_saml/master/screenshots/2.png</screenshot>
3535
<dependencies>
36-
<nextcloud min-version="21" max-version="26" />
36+
<nextcloud min-version="23" max-version="24" />
3737
</dependencies>
3838
<commands>
3939
<command>OCA\User_SAML\Command\ConfigCreate</command>

lib/Controller/SAMLController.php

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@
4242
use OCP\IURLGenerator;
4343
use OCP\IUserSession;
4444
use OCP\Security\ICrypto;
45+
use OCP\Security\ITrustedDomainHelper;
4546
use OneLogin\Saml2\Auth;
4647
use OneLogin\Saml2\Error;
4748
use OneLogin\Saml2\Settings;
@@ -74,6 +75,10 @@ class SAMLController extends Controller {
7475
* @var ICrypto
7576
*/
7677
private $crypto;
78+
/**
79+
* @var ITrustedDomainHelper
80+
*/
81+
private $trustedDomainHelper;
7782

7883
/**
7984
* @param string $appName
@@ -100,7 +105,8 @@ public function __construct(
100105
IL10N $l,
101106
UserResolver $userResolver,
102107
UserData $userData,
103-
ICrypto $crypto
108+
ICrypto $crypto,
109+
ITrustedDomainHelper $trustedDomainHelper
104110
) {
105111
parent::__construct($appName, $request);
106112
$this->session = $session;
@@ -114,6 +120,7 @@ public function __construct(
114120
$this->userResolver = $userResolver;
115121
$this->userData = $userData;
116122
$this->crypto = $crypto;
123+
$this->trustedDomainHelper = $trustedDomainHelper;
117124
}
118125

119126
/**
@@ -203,11 +210,17 @@ protected function assertGroupMemberships(): void {
203210
* @throws \Exception
204211
*/
205212
public function login(int $idp = 1) {
213+
$originalUrl = (string)$this->request->getParam('originalUrl', '');
214+
if (!$this->trustedDomainHelper->isTrustedUrl($originalUrl)) {
215+
$originalUrl = '';
216+
}
217+
206218
$type = $this->config->getAppValue($this->appName, 'type');
207219
switch ($type) {
208220
case 'saml':
209221
$auth = new Auth($this->samlSettings->getOneLoginSettingsArray($idp));
210-
$returnUrl = $this->request->getParam('originalUrl', $this->urlGenerator->linkToRouteAbsolute('user_saml.SAML.login'));
222+
223+
$returnUrl = $originalUrl ?: $this->urlGenerator->linkToRouteAbsolute('user_saml.SAML.login');
211224
$ssoUrl = $auth->login($returnUrl, [], false, false, true);
212225
$response = new Http\RedirectResponse($ssoUrl);
213226

@@ -226,7 +239,7 @@ public function login(int $idp = 1) {
226239
// Pack data as JSON so we can properly extract it later
227240
$data = json_encode([
228241
'AuthNRequestID' => $auth->getLastRequestID(),
229-
'OriginalUrl' => $this->request->getParam('originalUrl', ''),
242+
'OriginalUrl' => $originalUrl,
230243
'Idp' => $idp,
231244
'flow' => $flowData,
232245
]);
@@ -240,7 +253,7 @@ public function login(int $idp = 1) {
240253
$response->addCookie('saml_data', $data, null, 'None');
241254
break;
242255
case 'environment-variable':
243-
$ssoUrl = $this->request->getParam('originalUrl', '');
256+
$ssoUrl = $originalUrl;
244257
if (empty($ssoUrl)) {
245258
$ssoUrl = $this->urlGenerator->getAbsoluteURL('/');
246259
}

tests/unit/Controller/SAMLControllerTest.php

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@
3939
use OCP\IURLGenerator;
4040
use OCP\IUser;
4141
use OCP\IUserSession;
42+
use OCP\Security\ITrustedDomainHelper;
4243
use PHPUnit\Framework\MockObject\MockObject;
4344
use OCP\Security\ICrypto;
4445
use Test\TestCase;
@@ -70,6 +71,8 @@ class SAMLControllerTest extends TestCase {
7071
private $crypto;
7172
/** @var SAMLController */
7273
private $samlController;
74+
/** @var ITrustedDomainHelper|MockObject */
75+
private $trustedDomainController;
7376

7477
protected function setUp(): void {
7578
parent::setUp();
@@ -86,6 +89,7 @@ protected function setUp(): void {
8689
$this->userResolver = $this->createMock(UserResolver::class);
8790
$this->userData = $this->createMock(UserData::class);
8891
$this->crypto = $this->createMock(ICrypto::class);
92+
$this->trustedDomainController = $this->createMock(ITrustedDomainHelper::class);
8993

9094
$this->l->expects($this->any())->method('t')->willReturnCallback(
9195
function ($param) {
@@ -111,7 +115,8 @@ function ($param) {
111115
$this->l,
112116
$this->userResolver,
113117
$this->userData,
114-
$this->crypto
118+
$this->crypto,
119+
$this->trustedDomainController
115120
);
116121
}
117122

0 commit comments

Comments
 (0)