Skip to content

Commit 92303b5

Browse files
Merge pull request #12770 from nextcloud/fix/drop-dead-redirect
fix: Remove unused proxy redirect route
2 parents 35e2c09 + 32a6d46 commit 92303b5

8 files changed

Lines changed: 0 additions & 198 deletions

File tree

appinfo/routes.php

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -295,11 +295,6 @@
295295
'url' => '/api/avatars/image/{email}',
296296
'verb' => 'GET'
297297
],
298-
[
299-
'name' => 'proxy#redirect',
300-
'url' => '/redirect',
301-
'verb' => 'GET'
302-
],
303298
[
304299
'name' => 'proxy#proxy',
305300
'url' => '/proxy',

css/redirect.css

Lines changed: 0 additions & 8 deletions
This file was deleted.

lib/Controller/ProxyController.php

Lines changed: 0 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@
1010

1111
namespace OCA\Mail\Controller;
1212

13-
use Exception;
1413
use OCA\Mail\Html\ProxyHmacGenerator;
1514
use OCA\Mail\Http\ProxyDownloadResponse;
1615
use OCA\Mail\Service\MailManager;
@@ -20,7 +19,6 @@
2019
use OCP\AppFramework\Http\Attribute\OpenAPI;
2120
use OCP\AppFramework\Http\Attribute\UserRateLimit;
2221
use OCP\AppFramework\Http\Response;
23-
use OCP\AppFramework\Http\TemplateResponse;
2422
use OCP\Http\Client\IClientService;
2523
use OCP\Http\Client\LocalServerException;
2624
use OCP\IRequest;
@@ -61,38 +59,6 @@ public function __construct(string $appName,
6159
$this->userId = $userId;
6260
}
6361

64-
/**
65-
* @NoAdminRequired
66-
* @NoCSRFRequired
67-
*
68-
* @param string $src
69-
*
70-
* @throws \Exception If the URL is not valid.
71-
* @return TemplateResponse
72-
*/
73-
public function redirect(string $src): TemplateResponse {
74-
$authorizedRedirect = false;
75-
76-
if (!str_starts_with($src, 'http://')
77-
&& !str_starts_with($src, 'https://')
78-
&& !str_starts_with($src, 'ftp://')) {
79-
throw new Exception('URL is not valid.', 1);
80-
}
81-
82-
// If strict cookies are set it means we come from the same domain so no open redirect
83-
if ($this->request->passesStrictCookieCheck()) {
84-
$authorizedRedirect = true;
85-
}
86-
87-
$params = [
88-
'authorizedRedirect' => $authorizedRedirect,
89-
'url' => $src,
90-
'urlHost' => parse_url($src, PHP_URL_HOST),
91-
'mailURL' => $this->urlGenerator->linkToRoute('mail.page.index'),
92-
];
93-
return new TemplateResponse($this->appName, 'redirect', $params, 'guest');
94-
}
95-
9662
/**
9763
* @NoAdminRequired
9864
* @NoCSRFRequired

src/autoredirect.js

Lines changed: 0 additions & 12 deletions
This file was deleted.

src/tests/unit/util/text.spec.js

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -149,15 +149,6 @@ describe('text', () => {
149149
expect(actual).toEqual(expected)
150150
})
151151

152-
it('does not leak internal redirection URLs', () => {
153-
const source = html('<a href="https://localhost/apps/mail/redirect?src=domain.tld">domain.tld</a>')
154-
const expected = plain('domain.tld')
155-
156-
const actual = toPlain(source)
157-
158-
expect(actual).toEqual(expected)
159-
})
160-
161152
it('preserves quotes', () => {
162153
const source = html('<blockquote><div><b>yes.</b></div><div><br /></div><div>Am Montag, den 21.10.2019, 16:51 +0200 schrieb Christoph Wurst:</div><blockquote style="margin:0 0 0 .8ex;border-left:2px #729fcf solid;padding-left:1ex;"><div>ok cool</div><div><br /></div><div>Am Montag, den 21.10.2019, 16:51 +0200 schrieb Christoph Wurst:</div><blockquote style="margin:0 0 0 .8ex;border-left:2px #729fcf solid;padding-left:1ex;"><div>Hello</div><div><br /></div><div>this is some t<i>e</i>xt</div><div><br /></div><div>yes</div><div><br /></div><div>cheers</div><br></blockquote><br></blockquote></blockquote>')
163154
const expected = plain(`> yes.

templates/redirect.php

Lines changed: 0 additions & 35 deletions
This file was deleted.

tests/Unit/Controller/ProxyControllerTest.php

Lines changed: 0 additions & 94 deletions
Original file line numberDiff line numberDiff line change
@@ -11,15 +11,13 @@
1111
namespace OCA\Mail\Tests\Unit\Controller;
1212

1313
use ChristophWurst\Nextcloud\Testing\TestCase;
14-
use Exception;
1514
use OCA\Mail\Controller\ProxyController;
1615
use OCA\Mail\Html\ProxyHmacGenerator;
1716
use OCA\Mail\Http\ProxyDownloadResponse;
1817
use OCA\Mail\Service\MailManager;
1918
use OCP\AppFramework\Db\DoesNotExistException;
2019
use OCP\AppFramework\Http;
2120
use OCP\AppFramework\Http\Response;
22-
use OCP\AppFramework\Http\TemplateResponse;
2321
use OCP\Http\Client\IClient;
2422
use OCP\Http\Client\IClientService;
2523
use OCP\Http\Client\IResponse;
@@ -73,98 +71,6 @@ protected function setUp(): void {
7371
$this->logger = new NullLogger();
7472
}
7573

76-
public function redirectDataProvider() {
77-
return [
78-
[
79-
'http://nextcloud.com',
80-
false,
81-
false
82-
],
83-
[
84-
'https://nextcloud.com',
85-
false,
86-
false
87-
],
88-
[
89-
'http://nextcloud.com',
90-
true,
91-
true
92-
],
93-
[
94-
'http://example.com',
95-
false,
96-
false
97-
],
98-
[
99-
'https://example.com',
100-
true,
101-
true
102-
],
103-
[
104-
'ftp://example.com',
105-
true,
106-
true
107-
],
108-
];
109-
}
110-
111-
/**
112-
* @dataProvider redirectDataProvider
113-
*/
114-
public function testRedirect(string $url,
115-
bool $passesTest,
116-
bool $authorized) {
117-
$this->urlGenerator->expects($this->once())
118-
->method('linkToRoute')
119-
->with('mail.page.index')
120-
->will($this->returnValue('mail-route'));
121-
$this->request->expects($this->once())
122-
->method('passesStrictCookieCheck')
123-
->willReturn($passesTest);
124-
$this->controller = new ProxyController(
125-
$this->appName,
126-
$this->request,
127-
$this->urlGenerator,
128-
$this->session,
129-
$this->clientService,
130-
$this->hmacGenerator,
131-
$this->logger,
132-
$this->mailManager,
133-
$this->userId,
134-
);
135-
$expected = new TemplateResponse(
136-
$this->appName,
137-
'redirect',
138-
[
139-
'authorizedRedirect' => $authorized,
140-
'url' => $url,
141-
'urlHost' => parse_url($url, PHP_URL_HOST),
142-
'mailURL' => 'mail-route'
143-
],
144-
'guest'
145-
);
146-
147-
$response = $this->controller->redirect($url);
148-
149-
$this->assertEquals($expected, $response);
150-
}
151-
152-
public function testRedirectInvalidUrl() {
153-
$this->controller = new ProxyController(
154-
$this->appName,
155-
$this->request,
156-
$this->urlGenerator,
157-
$this->session,
158-
$this->clientService,
159-
$this->hmacGenerator,
160-
$this->logger,
161-
$this->mailManager,
162-
$this->userId,
163-
);
164-
$this->expectException(Exception::class);
165-
166-
$this->controller->redirect('ftps://example.com');
167-
}
16874

16975
public function testProxyWithoutCookies(): void {
17076
$src = 'http://example.com';

webpack.common.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,6 @@ const plugins = [
4040

4141
module.exports = async () => ({
4242
entry: {
43-
autoredirect: path.join(__dirname, 'src/autoredirect.js'),
4443
mail: path.join(__dirname, 'src/main.js'),
4544
oauthpopup: path.join(__dirname, 'src/main-oauth-popup.js'),
4645
settings: path.join(__dirname, 'src/main-settings'),

0 commit comments

Comments
 (0)