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: ssconf:// deeplinking on ios #1524

Merged
merged 16 commits into from
Jan 12, 2023
26 changes: 18 additions & 8 deletions src/www/app/app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,9 @@ import {VpnInstaller} from './vpn_installer';

// If s is a URL whose fragment contains a Shadowsocks URL then return that Shadowsocks URL,
// otherwise return s.
export function unwrapInvite(s: string): string {
export function unwrapInvite(possiblyInviteUrl: string): string {
try {
const url = new URL(s);
const url = new URL(possiblyInviteUrl);
if (url.hash) {
const decodedFragment = decodeURIComponent(url.hash);

Expand All @@ -41,17 +41,18 @@ export function unwrapInvite(s: string): string {
// - When a user opens invite.html#ENCODEDSSURL in their browser, the website (currently)
// redirects to invite.html#/en/invite/ENCODEDSSURL. Since copying that redirected URL
// seems like a reasonable thing to do, let's support those URLs too.
// - ssconf:// is not supported by the invite flow, so we don't need to check it
const possibleShadowsocksUrl = decodedFragment.substring(decodedFragment.indexOf('ss://'));

if (new URL(possibleShadowsocksUrl).protocol === 'ss:') {
return possibleShadowsocksUrl;
}
}
} catch (e) {
// Something wasn't a URL, or it couldn't be decoded - no problem, people put all kinds of
// unexpected things in the clipboard.
// It wasn't invite URL!
}
return s;

return possiblyInviteUrl;
}

const DEFAULT_SERVER_CONNECTION_STATUS_CHANGE_TIMEOUT = 600;
Expand Down Expand Up @@ -589,14 +590,23 @@ export class App {
}
}

private isOutlineAccessKey(url: string): boolean {
if (!url) return false;

url = unwrapInvite(url);
daniellacosse marked this conversation as resolved.
Show resolved Hide resolved

return url.startsWith('ss://') || url.startsWith('ssconf://');
daniellacosse marked this conversation as resolved.
Show resolved Hide resolved
}

private registerUrlInterceptionListener(urlInterceptor: UrlInterceptor) {
urlInterceptor.registerListener(url => {
if (!url || !unwrapInvite(url).startsWith('ss://')) {
if (!this.isOutlineAccessKey(url)) {
// This check is necessary to ignore empty and malformed install-referrer URLs in Android
// while allowing ss:// and invite URLs.
// while allowing ss://, ssconf:// and invite URLs.
// TODO: Stop receiving install referrer intents so we can remove this.
return console.debug(`Ignoring intercepted non-shadowsocks url`);
return console.debug(`Ignoring intercepted non-outline url`);
daniellacosse marked this conversation as resolved.
Show resolved Hide resolved
daniellacosse marked this conversation as resolved.
Show resolved Hide resolved
}

try {
this.confirmAddServer(url);
} catch (err) {
Expand Down