MiniCAT- Understanding and Detecting Cross-Page Request Forgery Vulnerabilities in Mini-Programs
MiniCAT- Understanding and Detecting Cross-Page Request Forgery Vulnerabilities in Mini-Programs
525
CCS ’24, October 14–18, 2024, Salt Lake City, UT, USA Zidong Zhang, et al.
resulting in issues like broken authentication, request forging, and issue but a widespread security concern across the mini-program
sensitive data leaks. ecosystem.
Existing research has predominantly assessed the security of Responsible Disclosure. Every attack experiment described in
mini-programs from the perspective of mobile apps, such as ex- this paper that involves real-world mini-programs was performed
ploring permissions, common development bugs, and cross-mini- in a controlled environment. Moreover, we have reported all our
program communications [68, 70, 72]. Nevertheless, a noticeable discovered vulnerabilities to the corresponding vendors and de-
gap persists in studying mini-program security from a web app velopers. Currently, three of them have been confirmed and as-
standpoint. signed vulnerability IDs: CNVD-2024-05527 (high-severity), CNVD-
Our Work. We have discovered a new vulnerability that results 2023-75836 (moderate-severity), and CNVD-2023-75837 (moderate-
from the flawed design of page routing and user state management severity).
in mini-programs, including dependence on URL schema for nav- Contributions. The main contributions of this paper are:
igation and transmission of parameters, unencrypted parameter
communication, and inconsistent preservation of user state. • New Vulnerability. We identified a new type of mini-program
In particular, utilizing the sharing & forwarding features of mini- vulnerability named MiniCPRF. This vulnerability enables at-
programs and the insecure local storage, an attacker can manipu- tackers to forge mini-program routing and parameters, leading
late the URLs designated for page routing within mini-programs. to various security consequences, such as controlling sensitive
This manipulation allows controlling the targeted routing page operations and information leakage.
and the transmitted parameters. This specific vulnerability, termed • New Tool. We developed an automated analysis framework called
MiniCPRF (Cross-Page Request Forgery in Mini-Programs), can MiniCAT, specifically designed for MiniCPRF. This framework
result in the following consequences: can automatically crawl WeChat mini-programs and perform
MiniCPRF detection based on static analysis.
• Consequence I: Inducing victims to access modified mini-program • Large-scale Evaluations. We measured 41,726 out of the 44,273
page routes, thus executing sensitive operations (e.g., free shop- crawled WeChat mini-programs and found that 13,349 (32.0%)
ping and unauthorized device control). could be identified as potentially vulnerable to MiniCPRF.
• Consequence II: Stealing sensitive information from the mini-
program routes (e.g., the credit card number).
Open Source. Our analysis framework, MiniCAT [49], has been
After further investigation into the root causes of MiniCPRF, released on GitHub.
we found they were linked to several design flaws in both mini- Demo Site. The anonymized PoC attack demos of the above vul-
programs and their super apps, including plain-text routing param- nerabilities can be found at https://sites.google.com/view/minicprf.
eter transmission, a lack of integrity check for chat messages, and Roadmap. The rest of this paper is organized as follows. Section 2
modifiable local storage of the super app. Thus, due to the simplic- provides the necessary background of the WeChat mini-program
ity of implementing MiniCPRF and the potential for attackers to framework and introduces the threat model used in this paper.
expand the attack surface by exploiting the sharing mechanism of Section 3 discusses the motivation case and summarizes MiniCPRF.
mini-programs, it is imperative to measure the impact of MiniCPRF The detailed design of MiniCAT is illustrated in Section 4, and
on the current mini-program ecosystem and their corresponding Section 5 gives its prototype implementation. Section 6 analyzes
platforms comprehensively. the evaluation results. Section 7 discusses the limitations of our
To conduct such a large-scale measurement, we designed an work and the lessons learned. Section 8 reviews the existing related
automated detection framework called MiniCAT (MiniCPRF Anal- work, and Section 9 concludes this paper.
ysis Tool). It consists of a mini-program crawler and a MiniCPRF
automatic detector based on reverse taint analysis. With Mini-
CAT, we crawled mini-programs on a large scale and detected the 2 BACKGROUND AND THREAT MODEL
corresponding potential MiniCPRF issues. In the experiments, we 2.1 Mini-Program
collected 44,273 WeChat mini-programs, and 41,726 (94.2%) can be
successfully unpacked for further analysis. The final results show WeChat Mini-Program Framework. WeChat is a killer app devel-
that 32.0% (13,349/41,726) of them are risky to MiniCPRF, includ- oped by Tencent for messaging, social media, and mobile payment.
ing some famous ones with millions of users, such as Sohu [21], a Besides, WeChat is also a super app that provides a runtime en-
leading Chinese Internet and media mini-program, and Wenjuanx- vironment for WeChat mini-programs [35]. These mini-programs
ing, a leading online survey service mini-program. Moreover, we are lightweight without installation and provide users with various
also propose measures to mitigate MiniCPRF, such as deploying services, such as e-commerce, games, and tools. The architecture
encryption methods and performing message integrity checks. of a WeChat mini-program has two parts, as illustrated in Figure 1:
Our research primarily concentrates on WeChat mini-programs 1) a front-end running on the super app to interact with the user
due to their prevalence, as WeChat has over 900M daily active users and access system services; 2) a back-end providing the running
worldwide [40]. Nevertheless, our findings on MiniCPRF in WeChat environment (super apps) and performing server-side operations.
mini-programs led us to extend our analysis to other mini-program According to the official documentation [9], the mini-program
platforms, such as Baidu and Alipay, where we discovered similar front-end can be further divided into a render layer and a logic
vulnerabilities. This indicates that MiniCPRF is not an isolated layer [30]. WXML (Wechat Markup Language) templates and WXSS
526
MiniCAT: Understanding and Detecting Cross-Page Request Forgery Vulnerabilities in Mini-Programs CCS ’24, October 14–18, 2024, Salt Lake City, UT, USA
Components Event
Handler
①
Event Tigger Event
API
...
...
Login
page/index/index ③ page/user/index/index
Back-end
(Wechat Style Sheets) are used in the render layer, while JavaScript
is used in the logic layer. with the system. In HTTP-based web apps, cookies and session
Figure 1 shows how WeChat mini-programs enable communi- mechanisms typically manage the user state. However, WeChat
cation between the render and logic layers using Events [13]. User mini-programs do not support such HTTP-like mechanisms. To
actions are transferred from the render layer to the logic layer via implement user states in WeChat mini-programs, developers need
events for further processing by the super app, similar to JavaScript to utilize WeChat’s specific authentication mechanism based on the
DOM Events [15]. When an event is triggered by the render layer ac- OAuth 2.0 model [31]. Figure 3 shows an example of mini-program
tivity (e.g., user tap), the logic layer will execute the corresponding authentication and user state process in the logic layer and the
function named Event-Handling Function. Events drive the function- back-end. Specifically:
ality and interactivity of the WeChat mini-program framework.
• Step ➊: The mini-program initiates wx.login, prompting the
Routing Implementation. Routing [20] is a common concept WeChat client to produce a temporary credential, generally 5-
in web apps, referring to determining the network scope for the minute valid, named code.
end-to-end path when packets are transmitted from a source to a • Step ➋: Developers need to setup a handler page handler.php
destination. Similarly, WeChat mini-programs require interactions in their own servers. The front-end of mini-programs sends
and communications between different pages. In this paper, we the code to the handler page, and the page will communicate
define these processes as mini-program page routing. In detail, with the WeChat server by the back-end API code2Session,
mini-program page routing is the rule for navigating from one retrieving the user’s unique OpenID and session_key. At this
page to another based on routing rules (i.e., the path) [37]. The point, the session_key-OpenID forms a pair of credentials for
URL schema controls it and can pass parameters in the page URL. the user state.
For example, a completed mini-program routing path may look
like /page/index?param=1 (similar to the GET method in HTTP). There are two options to check the user state on specific pages:
WeChat officially provides three APIs for navigation between mini- • Step ➌.A: Design a custom user state using the OpenID, stored
program pages: wx.navigateTo [45], wx.redirectTo [46], and locally [38] via wx.setStorage. When validation is needed, de-
wx.reLaunch [47]. velopers can use wx.getStorage to fetch the OpenID, as demon-
Figure 2 shows an example of event communication and page strated in Page I of Figure 3.
routing implementation. The loginBtn button component in in • Step ➌.B: Use wx.checkSession for the validation of user state
dex.wxml is bound to the event-handling function formSubmit. generated by wx.login, as seen in Page II of Figure 3.
When the user enters the username and password and presses the
login button (①), this action will trigger bindtap and then trigger It is crucial to mention that the custom user state method man-
formBubmit (②) of index.js, resulting in sending the user’s user- dates verification on every authentication page. Otherwise, the
name and password to the developer’s server for verification. If the page will lack user state by default.
verification is successful, the username will be a routing parameter Sharing and Forwarding. As WeChat is a social-focused app with
of /page/user/index/index, and the mini-program will jump to social features, users can share mini-programs with their friends
index page via wx.navigateTo (③). through Moments or chats [34]. The shared mini-programs will
User State. The user state refers to the user’s authenticated status appear as WeChat mini-program cards as normal chat messages.
in a system or app, meaning that a user has successfully authenti- Moreover, developers can customize the shared mini-program card
cated and can durable access the protected resources or function- and use the onShareAppMessage function of one specific page in
alities. It serves as the foundation for maintaining user sessions the logic layer to determine whether this page can be shared or
and enforcing security measures throughout the user’s interaction forwarded to other users.
527
CCS ’24, October 14–18, 2024, Salt Lake City, UT, USA Zidong Zhang, et al.
for smart locks management) through MiniCPRF and take over the
➊ smart locks of the victim users.
Normal Workflow. The unlocking process of OKLOK is illustrated
❷ in Figure 4. OKLOK offers two binding options for users Bluetooth
smart locks: QR code scanning (①.A) and a mini-program’s device
search page (①.B). In both methods, the mini-program communi-
Mini-Program
cates with the back-end server, submitting the QR code or receiving
Storage Bluetooth broadcast packets and retrieving a unique, user-invisible
_id identifier (used to identify each lock). This _id guides the user
The Authentication Page to the Bind Page (pages/index/deviceAdd?_id=...), verifying
code2Session:code + Appsecret + appid whether the lock has been bound (②). If the lock is already bound,
other users will receive a message indicating the need for permis-
session_key + OpenID
sion to access it. If unbound, the current user’s account will be
WeChat Back-end API handler.php
linked to the lock, and the process advances to the Unlock Page
❸.A (/pages/index/deviceDetail?_id=...), carrying the _id (③).
Page I The login status (user state) is checked on this page, and then the
mini-program will start the unlocking process to unlock the target
Page II
❸.B lock (④).
Vulnerability and Attack. However, the above process can present
opportunities for attackers. Through manual analysis, we discov-
Figure 3: Case of authentication and user state management. ered that the Bind Page allows users to share, presenting as a
WeChat mini-program card. As illustrated in Figure 4, a WeChat
mini-program card is an XML text stored in the local storage of the
2.2 Threat Model WeChat client. It contains the page routing URL (i.e., <pagepath>)
that the mini-program navigates to after a user clicks on this card.
Here, we discuss the threat model used in our work, including the Also, OKLOK allows users to forward the Bind Page to any chat. Be-
attack scenario and the attacker’s capabilities. sides, we found that the Unlock Page does not implement complete
Scenario. Both the attacker and the victim are WeChat users. user state verification, which means that this page only checks if
They can access WeChat mini-programs using the official WeChat the user is logged in, not if the user is the owner of the _id lock. In
client on any platform (Windows/macOS/iOS/Android). Addition- other words, any user who provides the correct _id can unlock the
ally, their devices run normally without malicious mini-programs. target lock.
In this scenario, the attacker does not intercept communications The attack process is described as follows: First, the attacker
directly between WeChat clients, nor is there a need for physical can share the Bind Page to any chat (❶). Then, the attacker can
or remote manipulation of the victim’s device. Moreover, the at- extract this card from the local storage to obtain the lock’s _id (❷).
tack can also occur indirectly (e.g., through sharing mini-program Next, they can modify the URL in the <pagepath> XML section
cards). of the card to the URL of the Unlock Page with the device’s _id
Attacker’s Capabilities. An attacker can exploit MiniCPRF vul- (pages/index/deviceDetail?_id=...), and update the modified
nerabilities to generate malicious mini-program cards and either card to the local storage (❸). Since the Unlock Page implements
personally click on them or induce the victim to do so, enabling incomplete user state checks, the attacker can click on the modified
both individual and mass targeting. Furthermore, the attacker can mini-program card (❹) and then navigate to that page and perform
create or modify malicious mini-program cards, with or without an unauthorized unlocking (❺). It should be noted that attackers can
existing card as a base. To construct or modify these cards, attack- acquire the victim’s _id directly (e.g., by accessing the victim’s
ers only need to acquire the page routing URL and corresponding device) or indirectly. For example, in an Airbnb rental scenario, if
parameters, which can be obtained directly or indirectly from the the landlord (victim) remotely shares a temporary mini-program
victim. These capabilities are relatively easy for the attacker to card with the tenant (attacker) for unlocking, it may accidentally
achieve because WeChat mini-program cards are stored in the local expose the device’s _id, enabling the attacker’s permanent control
storage, and a public method [12] is still functional in the latest of the device by exploiting MiniCPRF.
version of WeChat (Jan 2024). Consequently, the attacker can ac- Even worse, the mini-program sharing feature enables attack-
cess the detailed content of mini-program cards for the purpose of ers to widely distribute malicious mini-program cards, potentially
modification or forgery. affecting all OKLOK products. To carry out the attack mentioned
above, the attacker only needs the device’s _id. Besides, WeChat’s
functionality of navigating through mini-program QR codes (i.e.,
3 MOTIVATION CASE AND MINICPRF WeChat mini-program code [29]) allows attackers to enable unau-
3.1 Motivation Case thorized unlocking for any user who scans such a QR code. In
Here, we give a real-world case to illustrate MiniCPRF. In this case, other words, attackers can widely distribute forged mini-program
an attacker can bypass the authorization of OKLOK (a mini-program
528
MiniCAT: Understanding and Detecting Cross-Page Request Forgery Vulnerabilities in Mini-Programs CCS ’24, October 14–18, 2024, Salt Lake City, UT, USA
cards, affecting many users simultaneously in a "spray and pray" Table 1: Comparison of CMRF, CSRF, and MiniCPRF.
approach.
MP: Mini-program; WA: Web app.
529
CCS ’24, October 14–18, 2024, Salt Lake City, UT, USA Zidong Zhang, et al.
1 /* deviceAdd . wxml */
ta Metadata Render 2 /* < button bindtap =" __e " class =" ubgc - blue umar - t100 "
da Event S2# WXML
ta fo API Layer data - event - opts ="{{[ [ 'tap ' ,[ ['toBindDevice'] ] ]
Me In Trigger Elements
(WXML) ]}}" >{{ ' '+( lan . btn_bind || ' bind ') + ' '}} </ button >
Auto */
Event S3# 3
User Actions WeChat User State
Simulator Client Logic Function Result 4 /* deviceAdd . js */
Layer 5 ④ Page({
(Js) Routing
Shareablity 6 ...
API Calls S4# 7 onLoad : function ( e ) {
wxunpacker
S1# 8 var data = this ;...
9 wx . setStorageSync (" user " , data . user )
Crawler MiniCPRF Detector 10 ...
11 }
Figure 5: The Workflow of MiniCAT. 12 onShareAppMessage () {
13 return {..}
14 } ,...
15 ③ toBindDevice: function () {
16 ....
risky page routing URLs, associated parameters, and attack paths 17 var a = {
18 _id : t . form . code ,
for MiniCPRF. This collected information can be used to create 19 user : t . user . _id ,
malicious mini-program cards to launch MiniCPRF attacks. 20 remark : t . form . remark };
21 /* binding the device from the server - side */
22 n . default . httpPost ({
4 DESIGN OF MINICAT 23 name : " device / bind " ,
24 data : a ,
We designed an automated analysis framework, MiniCAT, to detect 25 /* If the binding process is successful , the
potential MiniCPRF vulnerabilities in WeChat mini-programs. As device 's _id will be connected to the URL as a
parameter */
shown in Figure 5, MiniCAT contains two modules: Mini-Program 26 ② success: function ( a ) {
Crawler to collect massive mini-programs and MiniCPRF Detector to 27 var n = {
detect MiniCPRF vulnerabilities in mini-programs. 28 _id : t . form . code
29 };
30 ① wx.redirectTo({ url : "/ pages / index / deviceDetail /
deviceDetail ? param =" + JSON . stringify ( n ) }) ;
4.1 Mini-Program Crawler 31 },
Crawling WeChat mini-programs is challenging since there are no 32 fail : function (e , t ) {
33 n . default . showToast ( t ) ;
official or third-party markets similar to Google Play [14] or Ap- 34 }
kpure [4] for Android apps. Typically, users access mini-programs 35 }) ;}...})
by scanning mini-program QR codes or searching within the WeChat 36
37 /* deviceDetail . js */
client. Zhang et al. [73] developed MiniCrawler to download mini- 38 Page ({
programs using specific WeChat APIs and designated AppIDs, 39 ...
40 onLoad : function ( t ) {
which are unique identifiers for mini-programs. However, batch 41 var o = this ;
querying of AppIDs has become impossible due to Tencent’s re- 42 o . app = wx . getStorageSync ( ' user ') ,
striction on related API access. 43 if ( o . app ) { o . getDetail () ;}
44 } ,...
During our investigation, we discovered that when a user ac- 45 getDetail : function () {
cesses a mini-program on the WeChat Windows client, the client 46 var t = this ,
creates a directory under the user profile folder to store the mini- 47 o = { _id : t . param . _id };
48 ...
program, located at user_file/Applet/AppID. Furthermore, a 49 success : function ( o ) { ...
WeChat metadata API [23] can provide metadata information for 50 t . blue . device = o ,
51 /* Unlock the corresponding lock */
mini-programs, such as description, type, and developer informa- 52 t . toStart () ;
tion, based on the AppID. This discovery inspired us to develop 53 ...}) ;
an automated crawler that simulates user actions on the WeChat 54 } ,...})
Windows client. Listing 1: Code snippet of OKLOK.
Our crawler, called Mini-Program Crawler, utilizes Natural Lan-
guage Processing (NLP) techniques to construct a keyword dictio-
nary to search for mini-programs within the WeChat Windows 4.2 MiniCPRF Detector
client, similar to the approach mentioned in MiniCrawler [73]. Addi-
tionally, Mini-Program Crawler leverages the mini-program metadata Following the attack for MiniCPRF flow described in Section 3, we
to generate the keyword dictionary. The metadata can be obtained designed MiniCPRF Detector in the following steps.
through the metadata API using the mini-program AppID from the Step I: Identifying the Nodes Calling Page Routing APIs. Ac-
user profile directory. cording to the WeChat developer documentation [37], page rout-
Furthermore, the crawler retrieves mini-program packages from ing APIs of WeChat mini-programs are called in the logic layer
the user profile directory and unpacks them into source code us- of the mini-program (i.e., in JavaScript files). We focus on three
ing wxappUnpacker [42] for further analysis, serving as input for routing APIs: wx.navigateTo, wx.reLaunch, and wx.redirectTo.
MiniCPRF Detector. In detail, MiniCPRF Detector constructs an Abstract Syntax Tree
530
MiniCAT: Understanding and Detecting Cross-Page Request Forgery Vulnerabilities in Mini-Programs CCS ’24, October 14–18, 2024, Salt Lake City, UT, USA
(AST) of the source code in the mini-program logic layer (i.e., Algorithm 1 Finding the event-driven function in the logic layer.
JavaScript code). Then, it filters the callee nodes that match the 1: function findEventHandling(rawAST, routingAPI_calleeNode)
names of those APIs. Next, MiniCPRF Detector filters the callee node 2: sourceNodeList ← ∅
and extracts the url property to obtain the URL passed through 3: sink = routingAPI_calleeNode
the page routing API. The URL is then split by regular match- 4: sourceNodeList += reverseTaint(rawAST,sink)
ing into the potentially vulnerable mini-program page, (for Steps 5: for source in sourceNodeList do
III and IV) and parameters (for Step II). As in the case of OK- 6: sourceScope = source.getContainer().getScope()
LOK (see Listing 1), MiniCPRF Detector can locate the API call to 7: sinkScope = sink.getContainer().getScope()
if sourceScope == sinkScope then
wx.redirectTo (Line 30∼31). It extracts the url property from
8:
9: PR_node = sourceScope.getpredNode()
this API as the page routing URL, including the vulnerable page 10: if PR_node.getContainer() instanceof Function then
/pages/index/deviceDetail/deviceDetail and its parameters 11: continue
JSON.stringify(n). 12: else if PR_node.getContainer() instanceof TopLevel then
Step II: Building the Attack Path. After obtaining the routing 13: EV_FunctionNode = source
and parameters of a potentially vulnerable mini-program page, the 14: break
15: end if
next step to launch the MiniCPRF attack is to build an attack path. In
16: end if
other words, our goal is not to obtain exact parameter values, which 17: end for
may be server-generated and hard to extract statically. Rather, we 18: return EV_FunctionNode
focus on outlining and formulating the attack path, which are the 19: end function
steps an attacker must take at the render layer to activate the page
routing API, reach the vulnerable page, and eventually extract its
routing URL. As described in Listing 1, after retrieving the URL,
our MiniCPRF Detector aims to identify how to initiate the page
routing API for url attribute manipulation within the attack con- that trigger events. Therefore, we must solve the following two
text. Through manual analysis, we have charted the reverse attack challenges to automate the above manual process:
path to engage the routing API at the mini-programs logic layer Challenge I: Locating the correct event-handling function in
as follows: ①wx.redirectTo() → ②success: function(a) → the logic layer. In Listing 1, we found that the attack path passed
③toBindDevice: function() → ④Page({..}). two functions: success and toBindDevice. If MiniCPRF Detector
However, the existing static analysis tools for mini-programs [57, mistakenly identifies success as an event-handling function, it
60, 65] are insufficient for automated analysis of mini-programs like cannot find the corresponding WXML element on the render layer
OKLOK, as they fail to detect MiniCPRF issues. In detail, these tools
page, resulting in an interruption in the attack path. Therefore, it is
use forward static analysis, focusing on client-side data flow, such crucial for our approach to identify the correct function accurately.
as TaintMini [65], which constructs data flows from user inputs to To address Challenge I, we analyzed the AST of the source code
sensitive APIs. However, our approach differs from this, as we aim and identified that the part executing the page routing API (Lines
to reconstruct the entire attack path instead of building a data flow 15∼35 in Listing 1) acts as a function container. This container
through page routing APIs. Thus, we need to find a new method could either be an event-handling function (EV function) or another
for detecting MiniCPRF. function type (OT function, e.g., the success callback function). Dis-
Since the attack path always ends with a page-routing API callee tinguishing between these functions is possible by examining the
node, reverse taint analysis can potentially automate the analysis of scope of their preceding node (PR node). Based on the standardized
this path. To verify our assumption, we manually analyzed the at- architecture of mini-program logic layers [24], the PR node of an
tack path in the mini-program. In the related view page in the render EV function aligns with its module node at the AST’s top level (the
layer (deviceAdd.wxml), we discovered that the event toBindDe- Page() object in Listing 1), while the PR node of an OT function is
vice interacts with the logic layer through a WXML attribute in a located within a function container.
button component. As shown in Listing 1, when the user clicks the In particular, MiniCPRF Detector identifies each function’s PR node
(bindtap) button, it triggers the logic layer (deviceAdd.js) to ex- using reverse taint analysis, as shown in Algorithm 1. It defines
ecute the toBindDevice event-handling function. The _id is then the PR node scope per node, accurately locating the EV function
passed to toBindDevice through the event channel and ultimately while avoiding OT function confusion. If an EV function ties to mini-
linked with ?param= to construct the complete page routing URL. program page functions [36] like onLoad or onHide, it suggests user
To address this issue, we propose an analysis method based on interaction response, such as page loads or refreshes. In summary,
reverse taint analysis. Specifically, we set the page routing API we can solve Challenge I by analyzing the scope of PR nodes in
node as the sink node and aim to locate its event-handling function the AST, achieving accurate locating of event-handling functions
toBindDevice through reverse taint query (as the target source without interference from other functions.
node). Following that, the MiniCPRF Detector attempts to identify Challenge II: Identifying WXML components in the render
the WXML elements and attributes that trigger the event on the layer. After solving Challenge I, we can locate the event-handling
corresponding logic layer page. Note that reverse taint analysis aids function on the logic layer. Then, we must implement a data flow
our analysis by accurately identifying components on the attack analysis to find the event-triggered element in the render layer.
path, such as event-handling functions and WXML components Although tools like [57, 60, 65] do analyze WXML data flows, they
fall short of our needs as their analysis initiates at the render layer.
531
CCS ’24, October 14–18, 2024, Salt Lake City, UT, USA Zidong Zhang, et al.
Algorithm 2 Finding event trigger attribute in the render layer. complete verification of the user state. That is, the page logic can
1: function findEventWXML(wxmlFile, jsFile, EV_FunctionNode) be executed regardless of whether the user is logged in. This incon-
2: newSourceCode ← ∅ sistency in user state is key to the success of MiniCPRF attacks.
3: newSourceCode += (convertoHTML(wxmlFile), jsFile) Step IV: Shareability Check. As mentioned in Section 2, the on-
newAST ← ∅
ShareAppMessage() function can control the shareability of the
4:
5: newAST += buildAST(newSourceCode)
6: wxmlSinkNode = EV_FunctionNode
mini-program page. MiniCPRF Detector analyzes the page with page
7: wxmlSourceNode = reverseTaint(newAST, wxmlSinkNode) routing API calls in Step I, checking whether it uses this function to
8: EV_attribute = wxmlSourceNode determine its shareability. As shown in Listing 1, MiniCPRF Detector
9: return EV_attribute identifies that the page deviceAdd.js calls the onShareAppMes-
10: end function sage() function in the OKLOK case. The attacker can share the
page within any chat and extract the full page routing URL from
the WeChat local storage, which simplifies the attack.
This necessitates a technique for the MiniCPRF detector to analyze
WXML files effectively and make the attack path uninterrupted. 5 IMPLEMENTATION OF MINICAT
As the syntax of WXML is similar to HTML [43], we can use a
Here, we introduce the implementation of MiniCAT, including the
public tool [44] to convert WXML files to HTML files while main-
Mini-Program Crawler and MiniCPRF Detector modules. In summary,
taining the raw WXML tags and attributes. Then, utilizing well-
MiniCAT contains 2,374 lines of Python code and 900 lines of QL
established HTML-supported analysis tools (such as CodeQL [11]),
code.
we can reconstruct the AST with the transformed mini-program
source code for further cross-layer analysis. As shown in Algo- Mini-Program Crawler Implementation. First, we used pywin-
rithm 2, MiniCPRF Detector uses the previously queried EV function auto [19] (a set of Python modules to automate the Windows GUI)
as the new sink node of the new reverse taint analysis in the new to simulate the user search and access process on the WeChat Win-
AST. Finally, MiniCPRF Detector can locate the attribute correspond- dows client. Moreover, using the NLP word segmentation library,
ing to the EV function (called EV attribute). Since the converted jieba [16], we processed mini-program descriptions from the meta-
WXML files preserve all original attributes, we can identify the data API mentioned in Section 4 to create the search keyword list.
EV attribute and its corresponding element as the target event- Finally, we used wxappUnpacker (a public WeChat mini-program
triggered WXML components. unpacking tool) to unpack the crawled mini-program packages.
In the OKLOK case (Listing 1), we can construct a complete attack MiniCPRF Detector Implementation. After obtaining source
path of the MiniCPRF vulnerability page after Step II. That is, to get codes of mini-programs, we implemented MiniCPRF Detector follow-
the value of t, an attacker only needs to click the target <button> ing the steps designed in Section 4 based on CodeQL, a static anal-
on the deviceAdd page (deviceAdd.wxml). After clicking, t will ysis tool that can build ASTs and conduct static data flow analysis.
be passed into toBindDevice and used as part of the parameter Furthermore, we used the wxml-transformer to convert WXML
url of wx.redirectTo in deviceAdd.js. Then, the OKLOK mini- to HTML files.
program will jump to the vulnerable page deviceDetail. If page
deviceDetail can be shared or forwarded, the attacker can easily
6 EVALUATIONS
obtain the value of t by extracting its routing URL.
In this section, we discuss the detection results of MiniCAT. We also
Step III: Checking User State. In the OKLOK case, a crucial fac- design a passive DNS-based approach to evaluate the popularity
tor for the success of the attack was the lack of correct user state of mini-programs. Moreover, two real-world cases are analyzed
implementation on the deviceDetail page, allowing attackers’ deeply, and measurements on multi-platforms are discussed.
unauthorized access and sensitive operations. As mentioned in Sec-
tion 2, the implementation of user state in WeChat mini-programs is Experiment Setup. Our Mini-Program Crawler was deployed on a
more unified than that of web apps, enabling us to perform general Windows 10 laptop (i7-6600u/16 GB RAM) with Python 3.8.0. For
static analysis on them. MiniCPRF Detector, we performed the analysis on a server running
Our static analysis focuses on detecting two types of API calls Ubuntu 20.04 with 32 CPU cores and 256 GB memory, utilizing 10
in the onLoad page load functions of potentially vulnerable pages. threads to analyze all mini-programs.
The absence of these calls suggests that the page does not check Dataset. We collected and successfully unpacked 44,273 WeChat
the user state upon loading, leading to higher risks, especially if mini-programs using Mini-Program Crawler, which occupied a stor-
MiniCPRF vulnerabilities exist. age space of 126.38 GB. These mini-programs consisted of 2,264,377
(1) The APIs can check if the user state obtained by wx.login is pages, with an average of approximately 51 pages per mini-program.
expired, such as wx.checkSession. For those non-unpackable mini-programs, we found that they were
(2) The APIs can get the local mini-program storage cache, such as incompatible with the wxappUnpacker tool due to their use of a
wx.getStorage and wx.getStorageSync. newer version of the WeChat mini-program base library. Addition-
In the OKLOK case, after the user logs into the mini-program, ally, failures in unpacking were also attributed to missing main
wx.setStorageSync("user") on the logic layer is used to store packages [17].
the user field in local storage. However, when users navigate to Result Overview. Among the mini-programs collected, MiniCAT
the deviceDetail page and trigger the onLoad function, it lacks successfully analyzed 41,726/44,273 (94.2%), identifying 13,349/41,726
532
MiniCAT: Understanding and Detecting Cross-Page Request Forgery Vulnerabilities in Mini-Programs CCS ’24, October 14–18, 2024, Salt Lake City, UT, USA
ɩ ɬ Ŝ ɭ ɰ
(32.0%) as potentially vulnerable with a cumulative 119,471 risky ɩ ɬ
pages. On average, each such mini-program contained nine poten-
tial MiniCPRF vulnerabilities. The remaining 2,547/44,273 (5.8%) ɩ ɥ ɨ ɯ Ŝ ɪ ɬ
mini-programs were not analyzed due to absent codes from WeChat
ɨ ɬ
Cloud Development [28] or highly obfuscated source codes.
ɨ ɥ Ŝ ɨ ɫ ɨ ɥ Ŝ ɥ ɰ
Efficiency. Mini-Program Crawler took about 15 seconds to crawl ɨ ɥ
ɭ Ŝ ɯ ɯ ɮ Ŝ ɩ ɫ ɮ Ŝ ɩ ɫ ɮ Ŝ ɩ ɫ ɮ Ŝ ɩ ɫ
a single mini-program, enabling an average collection of 2,687 ɬ Ŝ ɥ ɬ
For MiniCPRF Detector, the total analysis time was eight days, av-
eraging 106.75 seconds for each mini-program. Building each mini-