Skip to content

Commit b95abc8

Browse files
authored
[Fix] Prevent storing external urls for stores (#3208)
* Prevent storing external urls for stores * Use sessionStorage instead of localStorage so last-url is not persisted
1 parent b6bfb5b commit b95abc8

File tree

2 files changed

+21
-5
lines changed
  • src/frontend

2 files changed

+21
-5
lines changed

src/frontend/components/UI/Sidebar/components/SidebarLinks/index.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ export default function SidebarLinks() {
9393
}
9494

9595
// if we have a stored last-url, default to the `/last-url` route
96-
const lastStore = localStorage.getItem('last-store')
96+
const lastStore = sessionStorage.getItem('last-store')
9797
if (lastStore) {
9898
defaultStore = lastStore
9999
}

src/frontend/screens/WebView/index.tsx

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,19 @@ interface Props {
2020
store?: 'epic' | 'gog' | 'amazon'
2121
}
2222

23+
const validStoredUrl = (url: string, store: 'epic' | 'gog' | 'amazon') => {
24+
switch (store) {
25+
case 'epic':
26+
return url.includes('epicgames.com')
27+
case 'gog':
28+
return url.includes('gog.com')
29+
case 'amazon':
30+
return url.includes('gaming.amazon.com')
31+
default:
32+
return false
33+
}
34+
}
35+
2336
export default function WebView({ store }: Props) {
2437
const { i18n } = useTranslation()
2538
const { pathname, search } = useLocation()
@@ -71,9 +84,9 @@ export default function WebView({ store }: Props) {
7184
let startUrl = urls[pathname]
7285

7386
if (store) {
74-
localStorage.setItem('last-store', `/${store}store`)
75-
const lastUrl = localStorage.getItem(`last-url-${store}`)
76-
if (lastUrl) {
87+
sessionStorage.setItem('last-store', `/${store}store`)
88+
const lastUrl = sessionStorage.getItem(`last-url-${store}`)
89+
if (lastUrl && validStoredUrl(lastUrl, store)) {
7790
startUrl = lastUrl
7891
}
7992
}
@@ -228,7 +241,10 @@ export default function WebView({ store }: Props) {
228241
const webview = webviewRef.current
229242
if (webview && store) {
230243
const onNavigate = () => {
231-
localStorage.setItem(`last-url-${store}`, webview.getURL())
244+
const url = webview.getURL()
245+
if (validStoredUrl(url, store)) {
246+
sessionStorage.setItem(`last-url-${store}`, webview.getURL())
247+
}
232248
}
233249

234250
// this one is needed for gog/amazon

0 commit comments

Comments
 (0)