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

[stable30] fix: wipe local storages on log out #50997

Draft
wants to merge 1 commit into
base: stable30
Choose a base branch
from
Draft
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
20 changes: 20 additions & 0 deletions core/src/utils/xhr-request.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

import { getCurrentUser } from '@nextcloud/auth'
import { generateUrl, getRootUrl } from '@nextcloud/router'
import logger from '../logger.js'

/**
*
Expand Down Expand Up @@ -51,6 +52,7 @@ async function checkLoginStatus() {
const { status } = await window.fetch(generateUrl('/apps/files'))
if (status === 401) {
console.warn('User session was terminated, forwarding to login page.')
await wipeBrowserStorages()
window.location = generateUrl('/login?redirect_url={url}', {
url: window.location.pathname + window.location.search + window.location.hash,
})
Expand All @@ -62,6 +64,24 @@ async function checkLoginStatus() {
}
}

/**
* Clear all Browser storages connected to current origin.
* @returns {Promise<void>}
*/
export async function wipeBrowserStorages() {
try {
window.localStorage.clear()
window.sessionStorage.clear()
const indexedDBList = await window.indexedDB.databases()
for (const indexedDB of indexedDBList) {
await window.indexedDB.deleteDatabase(indexedDB.name)
}
logger.debug('Browser storages cleared')
} catch (error) {
logger.error('Could not clear browser storages', { error })
}
}

/**
* Intercept XMLHttpRequest and fetch API calls to add X-Requested-With header
*
Expand Down
8 changes: 1 addition & 7 deletions core/src/views/Login.vue
Original file line number Diff line number Diff line change
Expand Up @@ -116,13 +116,7 @@ import NcNoteCard from '@nextcloud/vue/dist/Components/NcNoteCard.js'

const query = queryString.parse(location.search)
if (query.clear === '1') {
try {
window.localStorage.clear()
window.sessionStorage.clear()
console.debug('Browser storage cleared')
} catch (e) {
console.error('Could not clear browser storage', e)
}
wipeBrowserStorages()
}

export default {
Expand Down