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

[Fix] Prevent storing external urls for stores #3208

Merged
merged 2 commits into from
Nov 21, 2023
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
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ export default function SidebarLinks() {
}

// if we have a stored last-url, default to the `/last-url` route
const lastStore = localStorage.getItem('last-store')
const lastStore = sessionStorage.getItem('last-store')
if (lastStore) {
defaultStore = lastStore
}
Expand Down
24 changes: 20 additions & 4 deletions src/frontend/screens/WebView/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,19 @@ interface Props {
store?: 'epic' | 'gog' | 'amazon'
}

const validStoredUrl = (url: string, store: 'epic' | 'gog' | 'amazon') => {
switch (store) {
case 'epic':
return url.includes('epicgames.com')
case 'gog':
return url.includes('gog.com')
case 'amazon':
return url.includes('gaming.amazon.com')
default:
return false
}
}

export default function WebView({ store }: Props) {
const { i18n } = useTranslation()
const { pathname, search } = useLocation()
Expand Down Expand Up @@ -71,9 +84,9 @@ export default function WebView({ store }: Props) {
let startUrl = urls[pathname]

if (store) {
localStorage.setItem('last-store', `/${store}store`)
const lastUrl = localStorage.getItem(`last-url-${store}`)
if (lastUrl) {
sessionStorage.setItem('last-store', `/${store}store`)
const lastUrl = sessionStorage.getItem(`last-url-${store}`)
if (lastUrl && validStoredUrl(lastUrl, store)) {
startUrl = lastUrl
}
}
Expand Down Expand Up @@ -228,7 +241,10 @@ export default function WebView({ store }: Props) {
const webview = webviewRef.current
if (webview && store) {
const onNavigate = () => {
localStorage.setItem(`last-url-${store}`, webview.getURL())
const url = webview.getURL()
if (validStoredUrl(url, store)) {
sessionStorage.setItem(`last-url-${store}`, webview.getURL())
}
}

// this one is needed for gog/amazon
Expand Down