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

[stable29] fix(core): unsupported browser redirect url #45621

Merged
merged 2 commits into from
Jun 7, 2024
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
4 changes: 3 additions & 1 deletion core/Controller/UnsupportedBrowserController.php
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,8 @@ public function __construct(IRequest $request) {
public function index(): Response {
Util::addScript('core', 'unsupported-browser');
Util::addStyle('core', 'icons');
return new TemplateResponse('core', 'unsupportedbrowser', [], TemplateResponse::RENDER_AS_ERROR);

// not using RENDER_AS_ERROR as we need the JSConfigHelper for url generation
return new TemplateResponse('core', 'unsupportedbrowser', [], TemplateResponse::RENDER_AS_GUEST);
}
}
19 changes: 15 additions & 4 deletions core/src/views/UnsupportedBrowser.vue
Original file line number Diff line number Diff line change
Expand Up @@ -49,13 +49,14 @@
</template>

<script>
import { generateUrl } from '@nextcloud/router'
// eslint-disable-next-line n/no-extraneous-import
import { agents } from 'caniuse-lite/dist/unpacker/agents.js'
import { generateUrl, getRootUrl } from '@nextcloud/router'
import { translate as t, translatePlural as n } from '@nextcloud/l10n'

import NcButton from '@nextcloud/vue/dist/Components/NcButton.js'
import NcEmptyContent from '@nextcloud/vue/dist/Components/NcEmptyContent.js'
import Web from 'vue-material-design-icons/Web.vue'
// eslint-disable-next-line n/no-extraneous-import
import { agents } from 'caniuse-lite/dist/unpacker/agents.js'

import { browserStorageKey } from '../utils/RedirectUnsupportedBrowsers.js'
import { supportedBrowsers } from '../services/BrowsersListService.js'
Expand Down Expand Up @@ -130,12 +131,22 @@ export default {
// Redirect if there is the data
const urlParams = new URLSearchParams(window.location.search)
if (urlParams.has('redirect_url')) {
const redirectPath = Buffer.from(urlParams.get('redirect_url'), 'base64').toString() || '/'
let redirectPath = Buffer.from(urlParams.get('redirect_url'), 'base64').toString() || '/'

// remove index.php and double slashes
redirectPath = redirectPath
.replace('index.php', '')
.replace(getRootUrl(), '')
.replace(/\/\//g, '/')

// if we have a valid redirect url, use it
if (redirectPath.startsWith('/')) {
window.location = generateUrl(redirectPath)
return
}
}

// else redirect to root
window.location = generateUrl('/')
},

Expand Down
4 changes: 2 additions & 2 deletions dist/core-unsupported-browser.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/core-unsupported-browser.js.map

Large diffs are not rendered by default.

Loading