Skip to content

Commit f254b1b

Browse files
committed
Address history back button security issue
1 parent 0fc4b1c commit f254b1b

File tree

1 file changed

+15
-2
lines changed

1 file changed

+15
-2
lines changed

packages/core/src/router.ts

+15-2
Original file line numberDiff line numberDiff line change
@@ -155,8 +155,21 @@ export class Router {
155155
}
156156

157157
protected handleBackForwardVisit(page: Page): void {
158-
window.history.state.version = page.version
159-
this.setPage(window.history.state, { preserveScroll: true, preserveState: true }).then(() => {
158+
let currentState
159+
160+
/* This ensures we give precedence to a fresh state.
161+
'page' here holds the props from the latest backend request.
162+
This prevents user A logging out and user B seeing sensitive data
163+
from user A by going back in the history (shared computer)
164+
*/
165+
if (page) {
166+
currentState = page
167+
} else {
168+
window.history.state.version = page.version
169+
currentState = window.history.state
170+
}
171+
172+
this.setPage(currentState, { preserveScroll: true, preserveState: true }).then(() => {
160173
this.restoreScrollPositions()
161174
fireNavigateEvent(page)
162175
})

0 commit comments

Comments
 (0)