Skip to content

Commit

Permalink
Fixes ebkr#1315 - Prevents unsafe URLs being opened
Browse files Browse the repository at this point in the history
  • Loading branch information
AdamHebby committed Jun 19, 2024
1 parent f91c88b commit eeeaddc
Show file tree
Hide file tree
Showing 6 changed files with 30 additions and 8 deletions.
6 changes: 3 additions & 3 deletions src/AppWrapper.vue
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<template>
<div id="q-app">
<SettingsLoader :logError="logError" :openLink="openLink">
<SettingsLoader :logError="logError" :openWebOnlyLink="openWebOnlyLink">
<App />
</SettingsLoader>
</div>
Expand All @@ -23,8 +23,8 @@ export default class AppWrapper extends Vue {
console.error(error.name, error.message, error.stack);
}
openLink(url: string) {
new LinkImpl().openLink(url);
openWebOnlyLink(url: string) {
new LinkImpl().openWebOnlyLink(url);
}
}
</script>
6 changes: 3 additions & 3 deletions src/components/Link.vue
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<component :is="tag" v-if="target === 'file'" @click="selectFile()" class='target-link' data-semantic="file-selection">
<slot></slot>
</component>
<component :is="tag" v-else-if="target !== null" @click="openLink()" class='target-link' data-semantic="external-link">
<component :is="tag" v-else-if="target !== null" @click="openWebOnlyLink()" class='target-link' data-semantic="external-link">
<slot></slot>
</component>
<component :is="tag" class='target-link' v-else-if="target === null" data-semantic="visual-indicator">
Expand All @@ -27,8 +27,8 @@ import LinkProvider from '../providers/components/LinkProvider';
@Prop({default: 'a'})
tag: string | undefined;
openLink() {
LinkProvider.instance.openLink(this.url!);
openWebOnlyLink() {
LinkProvider.instance.openWebOnlyLink(this.url!);
}
selectFile() {
Expand Down
4 changes: 2 additions & 2 deletions src/components/SettingsLoader.vue
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
Resetting of the settings failed. You can still
try to reset the settings manually by following
these
<a @click="openLink('https://github.com/ebkr/r2modmanPlus/wiki/Error:-White-or-blank-game-select-screen-on-startup#corrupted-settings-on-update')">
<a @click="openWebOnlyLink('https://github.com/ebkr/r2modmanPlus/wiki/Error:-White-or-blank-game-select-screen-on-startup#corrupted-settings-on-update')">
instructions.
</a>
</p>
Expand Down Expand Up @@ -78,7 +78,7 @@ export default class SettingsLoader extends Vue {
private logError!: (error: R2Error) => void;
@Prop({required: true})
openLink!: (url: string) => void;
openWebOnlyLink!: (url: string) => void;
error: R2Error|null = null;
PHASES = PHASES;
Expand Down
12 changes: 12 additions & 0 deletions src/providers/components/LinkProvider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,18 @@ export default abstract class LinkProvider {
return LinkProvider.provider();
}

/**
* Safe URL opening, includes http(s):// only
*
* @param url HTTP / HTTPS Only URL
*/
public abstract openWebOnlyLink(url: string): void;

/**
* Unsafe URL opening, includes file://, steam:// and http(s)://
*
* @param url URL to open
*/
public abstract openLink(url: string): void;

public abstract selectFile(url: string): void;
Expand Down
6 changes: 6 additions & 0 deletions src/r2mm/component_override/LinkImpl.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,12 @@ export default class LinkImpl extends LinkProvider {
shell.openExternal(url);
}

openWebOnlyLink(url: string): void {
if (url.startsWith("http://") || url.startsWith("https://")) {
shell.openExternal(url);
}
}

selectFile(url: string): void {
shell.showItemInFolder(url);
}
Expand Down
4 changes: 4 additions & 0 deletions test/jest/__tests__/stubs/providers/stub.LinkProvider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@ export default class StubLinkProvider extends LinkProvider {
throw new Error("Stub access must be mocked or spied");
}

openWebOnlyLink(url: string): void {
throw new Error("Stub access must be mocked or spied");
}

selectFile(url: string): void {
throw new Error("Stub access must be mocked or spied");
}
Expand Down

0 comments on commit eeeaddc

Please sign in to comment.