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

Fixes #1315 - Prevents unsafe URLs being opened #1378

Open
wants to merge 2 commits into
base: develop
Choose a base branch
from
Open
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
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
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ describe("Link component", () => {
});

it("Invokes the correct action when clicked", () => {
sandbox.mock(LinkProvider.instance).expects("openLink").exactly(1).calledWith(mountOptions.propsData.url);
sandbox.mock(LinkProvider.instance).expects("openWebOnlyLink").exactly(1).calledWith(mountOptions.propsData.url);
const link = mount.find("a");
link.trigger("click");
sandbox.verify();
Expand Down