Abstract syntax tree-based applet data flow analysis method and related device

By constructing an abstract syntax tree for the mini-program, identifying key path nodes, and analyzing the privacy data flow in the mini-program, the difficulty of static analysis of mini-program JavaScript code in existing technologies is solved, and efficient identification of sensitive data flow and drawing of propagation paths are achieved.

CN116719528BActive Publication Date: 2026-11-24BEIJING UNIV OF POSTS & TELECOMM
View PDF 1 Cites 0 Cited by

Patent Information

Application Number
CN202310476899.3
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2023-04-27
Publication Date
2026-11-24
Estimated Expiration
2043-04-27

AI Technical Summary

Technical Problem

Existing technologies lack static analysis methods for JavaScript code in mini-programs, especially in dealing with the difficulties brought about by the weak typing and flexibility characteristics of mini-programs and the special mechanisms of mini-programs, making it impossible to effectively analyze sensitive data streams and determine data sources.

Method used

By constructing an abstract syntax tree for the mini-program, we can obtain the target privacy data source and element characteristics, identify the parameter nodes of the callback function as critical path nodes, and analyze the propagation path of privacy data.

Benefits of technology

It enables effective analysis of privacy data streams in mini-programs, identifies the propagation process of sensitive data streams, improves the accuracy and efficiency of analysis, and adapts to the special mechanisms of mini-programs.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN116719528B_ABST
    Figure CN116719528B_ABST
Patent Text Reader

Abstract

This application provides a method and related device for analyzing the data flow of a mini-program based on an abstract syntax tree. The method includes: obtaining the syntactic structure of the mini-program code and constructing an abstract syntax tree of the mini-program based on the syntactic structure; obtaining the target privacy data source and the corresponding target element features in the abstract syntax tree based on a preset privacy data source and corresponding element features of the mini-program, and determining the callback function of the target element features; determining the nodes in the abstract syntax tree containing the parameters of the callback function as critical path nodes based on the callback function; and determining the propagation path of the privacy data in the callback function based on the critical path nodes.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This application relates to the field of mobile security technology, and in particular to a method and related equipment for analyzing the data flow of a mini-program based on an abstract syntax tree. Background Technology

[0002] The main language for developing mini-programs is JavaScript, and the security analysis of mini-programs mainly focuses on JavaScript code. As a new application paradigm, mini-programs have experienced prosperous and stable development in recent years, but related research is still in its infancy, and there are relatively few research results.

[0003] In related technologies, research on mini-programs mainly focuses on their application, development, and architecture, without addressing their security. Some research does highlight security issues arising from unique mini-program mechanisms in specific scenarios and provides corresponding solutions, but there is a lack of research on mini-program security analysis techniques. Furthermore, when analyzing the JavaScript code of mini-programs, no corresponding analysis solutions are provided for certain unique mechanisms within the mini-program.

[0004] Therefore, it is urgent to solve the following problems: how to construct a solution for sensitive data flow analysis in mini programs and design sensitive data flow analysis algorithms; how to determine the source of sensitive data in mini programs; how to classify different data sources; how to design data source identification schemes based on different types of data sources; how to solve the difficulties brought about by the weak typing and flexibility of JavaScript code to static analysis work; and how to deal with the problems brought about by the special mechanisms of mini programs. Summary of the Invention

[0005] In view of this, the purpose of this application is to propose a method and related equipment for analyzing the data flow of a mini-program based on an abstract syntax tree to overcome or at least partially solve the above problems.

[0006] To achieve the above objectives, the first aspect of this application provides a method for analyzing the data flow of a WeChat Mini Program based on an abstract syntax tree, comprising:

[0007] Obtain the syntax structure of the mini-program code, and construct the abstract syntax tree of the mini-program based on the syntax structure;

[0008] Based on the preset privacy data source of the mini program and the corresponding element features, obtain the target privacy data source and the corresponding target element features in the abstract syntax tree, and determine the callback function of the target element features;

[0009] Based on the callback function, the nodes in the abstract syntax tree that contain the parameters of the callback function are determined as critical path nodes;

[0010] Based on the critical path nodes, determine the propagation path of the privacy data in the callback function.

[0011] Optionally, obtaining the syntax structure of the mini-program code and constructing the abstract syntax tree of the mini-program based on the syntax structure includes:

[0012] Obtain the logic layer code of the mini-program and determine the Page function of the logic layer code;

[0013] Retrieve the data attributes and function attributes in the Page function;

[0014] Based on the Page function, the data attributes, and the function attributes, an abstract syntax tree for the mini-program is established.

[0015] Optionally, the privacy data source includes:

[0016] The input data of the program interface, the sensitive triggering events of the program interface, and the sensitive APIs of the mini program;

[0017] The element features corresponding to the input data and sensitive triggering events of the program interface include:

[0018] Use properties containing the `bind` or `catch` keywords to bind event callback functions;

[0019] The elements of the sensitive API include at least one of the following: system information, media information, location information, user information, and privacy data.

[0020] Optionally, the step of obtaining the target privacy data source and the corresponding target element features in the abstract syntax tree, and determining the callback function for the target element features, includes:

[0021] Obtain the WXML file in the view layer of the mini-program as the target privacy data source;

[0022] The target element features in the WXML file are located using XML analysis.

[0023] Based on the location of the target element features, obtain the callback function in the logic layer of the mini-program that corresponds to the target element features.

[0024] Optionally, based on the callback function, determining the nodes in the abstract syntax tree that contain the parameters of the callback function as critical path nodes includes:

[0025] Locate the callback function, and parse the parameters of the callback function and the variables assigned by the callback function;

[0026] The parameters of the callback function and the variables assigned by the callback function are compared with the first parameters in the preset first parameter set.

[0027] In response to the first parameter in the first parameter set including the parameters of the callback function and the variable assigned by the callback function, the node in the abstract syntax tree containing the parameters of the callback function and the variable assigned by the callback function is determined to be a critical path node.

[0028] The first parameter in the preset first parameter set includes the parameters of all callback functions involved in the privacy data source and the variables assigned by the callback functions.

[0029] Optionally, if the parameters responding to the callback function and the variables assigned by the callback function belong to the first parameter set, then after determining that the parameters of the callback function are critical path nodes, the method further includes:

[0030] The callback function is recursively called on all child nodes of the critical path node in the abstract syntax tree to obtain the first return value after the recursive call.

[0031] Compare the variable in the first return value with the first parameter in the preset first parameter set;

[0032] If the first parameter of the first parameter set includes a variable of the first return value, then the current child node is determined to be the critical path node.

[0033] Optionally, the parameters of the callback function and the variables assigned by the callback function are compared with the first parameters in a preset first parameter set, and then the following steps are also included:

[0034] The page member functions of the mini-program are compared with the preset page member functions.

[0035] In response to mutual calls between page member functions of the mini-program and the use of the user privacy data as parameters of the page member functions, the node mapping of the called page member function in the abstract syntax tree is determined, and the page member function is recursively called on all child nodes of the root node in the abstract syntax tree with the node mapping as the root node, and the second return value after the recursive call is obtained.

[0036] Compare the variable in the second return value with the first parameter in the preset first parameter set;

[0037] If the first parameter of the first parameter set includes a variable of the second return value, then the current child node is determined to be the critical path node;

[0038] If the page member variable of the mini-program is used as a parameter for the this.setData function call, then the node in the abstract syntax tree where the this.setData function call is located is determined to be a critical path node;

[0039] The preset page member functions include all page member function names of the mini program and the node mapping of the abstract syntax tree corresponding to the page member function names;

[0040] The preset set of page member variables includes all page member variables of the mini-program that use the this.setData function to set the user privacy data.

[0041] A second aspect of this application provides a small program data flow analysis device based on an abstract syntax tree, comprising:

[0042] The building module is used to construct the abstract syntax tree of the mini-program based on its code syntax structure.

[0043] The acquisition module is used to acquire the code syntax structure of the mini-program; and to acquire the target privacy data source and the corresponding target element features in the abstract syntax tree.

[0044] The determination module is used to determine the callback function of the target element feature based on the target privacy data source and the corresponding target element feature in the abstract syntax tree; and

[0045] The parameters used to determine the critical path of the callback function;

[0046] The preset module is used to preset the privacy data source and corresponding element characteristics of the mini program.

[0047] A third aspect of this application provides an electronic device including a memory, a processor, and a computer program stored in the memory and executable on the processor, characterized in that the processor executes the program to implement the method described in the first aspect.

[0048] A fourth aspect of this application provides a non-transitory computer-readable storage medium storing computer instructions, characterized in that the computer instructions are used to cause a computer to perform the method described in the first aspect.

[0049] As can be seen from the above, the WeChat Mini Program data flow analysis method and related device based on abstract syntax tree provided in this application first constructs an abstract syntax tree of the Mini Program as an intermediate structure, and at the same time classifies and summarizes the user privacy data involved in the Mini Program, determines the corresponding privacy data source and corresponding element features, and determines the target privacy data source and corresponding target element features of the Mini Program for which data flow analysis is to be performed through the privacy data source and corresponding element features, thereby facilitating data flow analysis. Attached Figure Description

[0050] To more clearly illustrate the technical solutions in this application or related technologies, the drawings used in the description of the embodiments or related technologies will be briefly introduced below. Obviously, the drawings described below are only embodiments of this application. For those skilled in the art, other drawings can be obtained based on these drawings without creative effort.

[0051] Figure 1 This is a flowchart illustrating the WeChat Mini Program data flow analysis method based on an abstract syntax tree, as described in this application.

[0052] Figure 2 This is a schematic diagram of the critical path nodes in an embodiment of this application;

[0053] Figure 3 This is a schematic diagram illustrating the use of page member functions in embodiments of this application;

[0054] Figure 4 This is a schematic diagram illustrating the use of page member variables in embodiments of this application.

[0055] Figure 5 This is a schematic diagram of a data flow analysis example from an embodiment of this application;

[0056] Figure 6 This is a schematic diagram of the data flow analysis algorithm according to an embodiment of this application;

[0057] Figure 7 This is a schematic diagram of a WeChat mini-program data flow analysis device based on an abstract syntax tree according to an embodiment of this application;

[0058] Figure 8 This is a schematic diagram of the hardware structure of an electronic device according to an embodiment of this application. Detailed Implementation

[0059] To make the objectives, technical solutions, and advantages of this application clearer, the following detailed description is provided in conjunction with specific embodiments and the accompanying drawings.

[0060] It should be noted that, unless otherwise defined, the technical or scientific terms used in the embodiments of this application should have the ordinary meaning understood by one of ordinary skill in the art to which this application pertains. The terms "first," "second," and similar terms used in the embodiments of this application do not indicate any order, quantity, or importance, but are merely used to distinguish different components. Terms such as "comprising" or "including" mean that the element or object preceding the word encompasses the elements or objects listed after the word and their equivalents, without excluding other elements or objects. Terms such as "connected" or "linked" are not limited to physical or mechanical connections, but can include electrical connections, whether direct or indirect. Terms such as "upper," "lower," "left," and "right" are only used to indicate relative positional relationships; when the absolute position of the described object changes, the relative positional relationship may also change accordingly.

[0061] refer to Figure 1 The first aspect of this application provides a data flow analysis method based on an abstract syntax tree, comprising:

[0062] S101. Obtain the syntax structure of the mini-program code and construct the abstract syntax tree of the mini-program based on the syntax structure.

[0063] Specifically, after studying the syntax structure of the WeChat Mini Program code, this application finds that the logic layer code of the Mini Program is JavaScript code, and the JavaScript code has a fixed structure. The JavaScript code file mainly contains a Page function, which wraps an Object type parameter. This parameter has two types of properties: data and function. The data is the initial data used for the first rendering of the Mini Program page, and the function includes the Mini Program's lifecycle functions, page event handling functions, and custom functions. Because the syntax structure of the Mini Program code is fixed, the abstract syntax tree structure generated from the code is also relatively fixed.

[0064] Obtain the logic layer code of the mini-program and determine the Page function of the logic layer code;

[0065] Retrieve data properties and function properties from the Page function;

[0066] Based on Page functions, data attributes, and function attributes, construct the abstract syntax tree of the mini-program.

[0067] Understandably, after the logic layer code of a mini-program page is converted into an abstract syntax tree, it is generally wrapped by a CallExpression node, which represents the Page function in the logic layer code. The CallExpression node contains ObjectExpression nodes representing data properties and multiple FunctionExpression nodes representing function properties. Therefore, the mini-program's abstract syntax tree is built with CallExpression as the root node and ObjectExpression and FunctionExpression as branch nodes. In other words, the mini-program's abstract syntax tree is built with the Page function as the root node and data and function properties as branch nodes.

[0068] It should be noted that when obtaining the logic layer code of a mini-program, you may directly obtain the source code of the mini-program, or you may obtain the code package of the mini-program. If you obtain the source code of the mini-program, you can directly build the abstract syntax tree of the mini-program based on the Page function, data attribute, and function attribute in the logic layer code of the mini-program, following the method described above. If you obtain the code package of the mini-program, you also need to use mini-program reverse engineering technology to decompile the code package of the mini-program and restore it to the source code, and then build the abstract syntax tree of the mini-program based on the Page function, data attribute, and function attribute in the logic layer code of the mini-program, following the method described above.

[0069] In some embodiments, if you want to analyze the data stream of private data, you need to identify the private data sources that exist in the mini-program.

[0070] S102. Based on the preset privacy data source of the mini program and the corresponding element features, obtain the target privacy data source and the corresponding target element features in the abstract syntax tree, and determine the callback function of the target element features.

[0071] Specifically, analysis of the developer documentation for mini-programs reveals that, similar to traditional apps, mini-programs primarily acquire user privacy data through the following methods: obtaining user input data via the program interface (UI); requesting user authorization during mini-program use and then calling interfaces that inject sensitive data such as contacts, camera, and location information to obtain user privacy data; and collecting user privacy information through third-party plugins. In other words, the privacy data sources for mini-programs include: program interface input data, sensitive trigger events, and sensitive APIs. Table 1 below shows the components in the program interface that can obtain input data and trigger events.

[0072] Table 1 shows the components in the program interface that can obtain input data and trigger events.

[0073]

[0074] As shown in Table 1, different component categories for acquiring user input data and triggering sensitive events have different element characteristics, which can be summarized into the four categories mentioned above. The first category consists of officially provided components with the `open-type` attribute, such as the `button` component. The `open-type` attribute, as an open capability of the mini-program, specifies the button's behavior, such as opening a page or making a phone call, providing the function to acquire user information by specifying a callback function. The second category consists of components that collect user input data, such as forms and input boxes. These components use attributes containing the `bind` or `catch` keywords to bind event callback functions to receive or process user input data. The third category consists of custom components created by mini-program developers. During development, developers often combine and encapsulate certain components for component reuse. These encapsulated components may contain basic components for receiving user input data. The paths to these custom components can also be found in the mini-program's page configuration file. The fourth category consists of components such as maps and media that use `canvas`, `media`, and `map` to collect user input data. These components need to be used in conjunction with the APIs provided by the app for collecting user information, which can also be found directly in the logic layer code. As shown in Table 1, the element characteristics corresponding to the input data and sensitive triggering events of the program interface of the mini program include at least: using attributes containing the bind or catch keywords to bind event callback functions.

[0075] Table 2 Sensitive APIs for Mini Programs

[0076]

[0077]

[0078] Regarding sensitive APIs in WeChat Mini Programs, due to the current lack of mature research on sensitive information in Mini Programs, there is no readily available list of sensitive APIs for reference. This application reviewed all API documentation for Mini Programs in the open documentation and manually screened them based on their functions, identifying a total of 27 APIs related to the collection of user privacy data. These sensitive APIs mainly involve system information, media information, location information, user information, and privacy data. In addition, they also include information related to camera, audio, photos, videos, payment information, license plate numbers, and clipboard, as shown in Table 2. Based on the calling methods of these APIs, this application categorizes them into synchronous APIs and asynchronous APIs.

[0079] In some implementations, obtaining the target privacy data source and the corresponding target element features in the abstract syntax tree, and determining the callback function for the target element features, includes:

[0080] The WXML file in the view layer of the mini-program is obtained as the target privacy data source. Based on the summary of privacy data sources above, it can be understood that the target privacy data source is mainly in the WXML file of the view layer of the mini-program.

[0081] The target element features in the WXML file are located using XML analysis. Since WXML is identified as the target privacy data source, the target element features corresponding to the target privacy data source can be determined. Therefore, the target element features in the WXML file are located using XML analysis.

[0082] Then, based on the location of the target element's features, the callback function corresponding to the target element's features in the logic layer of the mini-program is determined. That is, through the correspondence between the view layer and the logic layer of the mini-program, the callback function of the target element's features is found in the logic layer of the mini-program. It can be understood that by using the abstract syntax tree as an intermediate structure, the corresponding node of the callback function of the target element's features in the abstract syntax tree can be found directly, which makes the subsequent analysis of the data flow simpler.

[0083] S103. Based on the callback function, determine the nodes in the abstract syntax tree that contain the parameters of the callback function as critical path nodes.

[0084] Specifically, refer to Figure 6 The process involves locating the callback function and parsing its parameters and the variables assigned by it. It can be understood that the node in the abstract syntax tree containing the callback function can be directly located, meaning the relevant code of the mini-program's callback function can be found. Then, the parameters and variables assigned by the callback function are parsed using this relevant code.

[0085] The parameters of the callback function and the variables assigned to the callback function are compared with the first parameter in the preset first parameter set.

[0086] If the first parameter in the first parameter set includes the parameters of the callback function and the variable assigned by the callback function, then the nodes in the abstract syntax tree containing the parameters of the callback function and the variable assigned by the callback function are determined to be critical path nodes.

[0087] The first parameter in the preset first parameter set includes the parameters of callback functions involved in all privacy data sources, as well as the variables assigned by the callback functions. In other words, the first parameter in the preset first parameter set is determined after considering all possible privacy data sources. It consists of the parameters of callback functions involved in all privacy data sources and the variables assigned by the callback functions. This first parameter serves as a reference point, allowing comparison between the parameters of the callback functions and the variables assigned by the callback functions of the mini-program for which data flow analysis is to be performed. If the first parameter contains elements related to or identical to the parameters and variables assigned by the callback functions, then it can be determined that the nodes representing the parameters and variables of the callback functions are also critical path nodes. In other words, the nodes representing the parameters and variables of the current callback functions include user privacy data.

[0088] The aforementioned sensitive APIs include both synchronous and asynchronous APIs. Synchronous and asynchronous APIs differ significantly in their usage, thus requiring separate handling. Synchronous APIs return user privacy data directly as a return value. Asynchronous APIs, on the other hand, return user privacy data as a callback function parameter. Asynchronous APIs accept an object-type parameter, within which a callback function can be defined. Upon successful asynchronous API call, the privacy data is included in the parameters of the success callback function for subsequent use. Therefore, in addition to callback functions in asynchronous APIs, synchronous APIs directly return return values, which also require data flow analysis.

[0089] Specifically, the callback function is recursively called on all child nodes of the critical path node in the abstract syntax tree to obtain the first return value after the recursive call. The variable of the first return value is compared with the first parameter in the preset first parameter set;

[0090] If the first parameter of the first parameter set includes a variable of the first return value, then the current child node is determined to be the critical path node.

[0091] In other words, the user privacy data obtained from the synchronous API is directly returned by the return value, which is the first return value. During the data flow analysis of the return value of the synchronous API, the variable corresponding to the first return value is directly compared with the first parameter of the preset first parameter set. If the first parameter of the first parameter set includes the variable corresponding to the return value or the first parameter is related to the variable corresponding to the return value, then the return value corresponds to the propagation path of the user privacy data, making the analysis method simpler.

[0092] It is understandable that the variables in the first return value are also determined by comparing them with the first parameters in the first parameter set. Therefore, the first parameters in the first parameter set also include the variables of the first return values ​​of all privacy data sources in the above embodiments.

[0093] It should be noted that the critical path nodes mentioned above are determined by the mini-program's code. In other words, the data flow analysis method is also based on the mini-program's code. For details, please refer to... Figure 8 For example, in the code, the abstract syntax tree node type generated by the code statements for variable declaration and definition is VariableDeclarator. When determining whether a node of this type is a critical path node, it analyzes all elements on the right side of the expression's equal sign that participate in the expression's operation to determine whether they are the target element features corresponding to the target privacy data source. Figure 2 The right side of the "variable declaration" statement marked in comment 1 represents a call to a sensitive API. Therefore, the variable on the left side is directly added to the first parameter set, and this node is marked as a critical path node. Additionally, some variable declaration expressions may have multiple elements participating in the calculation on the right side. For these elements, the node analysis algorithm is recursively called to determine whether these elements use the first parameter from the first parameter set. Figure 2 The analysis methods for the code statements marked in comments 3 and 4, such as "variable assignment" and "variable update", are similar.

[0094] The abstract syntax tree nodes generated by function call code statements and API call code statements are of type CallExpression, such as... Figure 2 The code statements marked in comments 2 and 6. To determine whether a node of this type is a critical path node, it is necessary to check whether the passed parameters are in the first parameter set, thereby determining whether the node is a critical path node.

[0095] The abstract syntax tree generated by the ternary expression code statement is of type ConditionalExpression, such as Figure 2 The code statement marked in comment 5. This type of code expression consists of three parts on the right side. During analysis, it is not necessary to analyze the Boolean expression part. It is only necessary to determine whether the result part of the Boolean expression uses the parameters in the first parameter set. The method of judgment is similar to the analysis of variable declaration and definition statements mentioned above.

[0096] The code statements for return value types are somewhat special, such as Figure 2 The code statements marked in comment 7. Because the return value types are diverse, the expression corresponding to the return value statement is used as input during analysis, and the node analysis algorithm is recursively called to determine the specific type of the return value statement.

[0097] However, in the process of data flow analysis, in addition to using the parameters of the callback function and the variables assigned by the callback function for analysis, there are also cases where the parameters of the callback function and the variables assigned by the callback function do not contain user privacy data. In such cases, it is also necessary to analyze the page member functions and page member variables of the mini program.

[0098] Specifically, the parameters of the callback function and the variables assigned to the callback function are compared with the first parameters in a preset first parameter set. Then, the process further includes:

[0099] The page member functions of the mini-program are compared with the preset page member functions;

[0100] In response to mutual calls between page member functions of the mini-program and the use of the user privacy data as parameters of the page member functions, the node mapping of the called page member function in the abstract syntax tree is determined, and the page member function is recursively called on all child nodes of the root node in the abstract syntax tree with the node mapping as the root node, and the second return value after the recursive call is obtained.

[0101] Compare the variable in the second return value with the first parameter in the preset first parameter set;

[0102] If a variable whose first parameter in the first parameter set includes the second return value is determined, then the current child node is determined to be the critical path node.

[0103] The preset page member functions include all page member function names of the mini program and the node mapping of the abstract syntax tree corresponding to the page member function names.

[0104] It is understandable that comparing page member functions with preset page member functions is used when encountering mutual calls between page member functions, i.e., when cross-function analysis occurs.

[0105] like Figure 3The diagram illustrates the mutual calls between page member functions. The boxed example shows a call to a page member function using `this.checkPhone()` within the `bindPhoneInput()` function, passing user privacy data as a parameter. The preset page member functions store a mapping between the page member function name and its abstract syntax tree structure. When calling a page member function using user privacy data as a parameter, the preset page member functions retrieve the corresponding abstract syntax tree structure. The data flow is then analyzed recursively, using the called member function as the root node, and recursively calling all child nodes of the root node within the abstract syntax tree to obtain a second return value. The variables in the second return value are compared with the first parameter in the preset first parameter set. If the first parameter in the first parameter set includes the variables from the second return value, the current child node is determined to be the critical path node. It should be noted that the first parameter in the first parameter set also includes variables from all called page member functions.

[0106] Furthermore, in response to the page member variables of the mini-program being used as parameters for the this.setData function call, the node in the abstract syntax tree where the this.setData function call occurs is determined to be a critical path node.

[0107] The preset set of page member variables includes all page member variables that use the this.setData function to set the user's privacy data as the mini-program's page member variables.

[0108] Specifically, refer to Figure 4 The example shows the use of page member variables. In the mini-program, the `this.setData()` function is used to set the variable as a page member variable, and then `this.data` is used to read the page member variable. Similarly, user privacy data is also set as a page member variable in this way, such as... Figure 4 The box indicates that when user privacy data is set using this.setData(), this user privacy data will be added to a preset page member variable. When this.data is read, the corresponding page member variable will be retrieved from the preset page member variable.

[0109] It should be noted that the above data flow analysis mainly focuses on critical path nodes. However, non-critical paths, i.e., non-critical path nodes formed with callback functions as root nodes, also need to be analyzed. For example, nodes formed by branching and looping statements in the code of the mini-program will also form corresponding branch nodes in the abstract syntax tree. These branch nodes also need to be checked and the same data flow analysis as the critical path nodes is performed.

[0110] S104. Based on the critical path nodes, determine the propagation path of the privacy data in the callback function.

[0111] Specifically, refer to Figure 5 , Figure 6 As shown, after the critical path nodes are determined, corresponding critical node paths are created directly based on the critical path nodes, and graphviz is used to draw the critical node paths to complete the data flow graph. Figure 5 This application illustrates a specific example of a data stream analysis method according to an embodiment of the present application, wherein... Figure 5 The left side shows the logic layer code of the mini-program, and the right side shows the key node paths drawn based on the abstract syntax tree. The `collectImage()` function uses the sensitive API `wx.getSystemInfo()`, which is used to obtain system information. After the sensitive API call is successful, the user's system information is extracted from the `res` parameter, concatenated into a string, and assigned to the variable `phone`. Finally, `phone` is sent to the mini-program's backend as a parameter in the HTTP request initiated by `wx.request()`. The parts marked with squares in the diagram are the key node paths, and the arrows represent the propagation paths of private data. Figure 5 As shown on the right, the data flow graph generated by the data flow analysis records all the key node paths and fully describes the propagation process of user privacy data.

[0112] Based on the aforementioned data flow analysis method for mini-programs using abstract syntax trees, this application randomly selected five mini-programs for experiments. Data flow analysis algorithms were used to identify and track the privacy data sources of these five mini-programs, and the tracking results were analyzed. During the analysis, the aforementioned privacy data sources were used as the starting point (Source), while no endpoint (Sink) was defined. This is because the number of APIs that can be considered key in a mini-program is relatively small, and during development, these APIs that could serve as endpoints are usually encapsulated by the developers. Defining a specific endpoint might lead to gaps in the data flow during analysis, making it impossible to plot the propagation process of the sensitive data flow to be analyzed, resulting in interruptions.

[0113] Table 3 Data Flow Analysis Results

[0114]

[0115] As shown in Table 3, "correct" indicates that the complete data stream of the corresponding mini-program was identified, i.e., the sensitive data to be identified was detected; "incorrect" indicates that the identified data stream was faulty or interrupted; and "missing" indicates that the data stream in the code of the corresponding mini-program was not identified. This application identified a total of 157 data streams from 5 mini-programs, of which 148 were correctly identified, 2 were incorrectly identified, and 6 were missing. Calculations show that the accuracy rate of the mini-program data stream analysis method based on abstract syntax trees achieved a rate of 94.26%, demonstrating good analysis results. Furthermore, the efficiency of the data stream analysis was also tested. Referring to Table 3, the longest data stream analysis time was 63.66 seconds, the shortest time was 25.16 seconds, and the average time was 45.03 seconds. Analysis revealed that the time spent was not directly proportional to the number of pages in the mini-program. In other words, more pages in a mini-program do not necessarily mean more time. Instead, the efficiency of data flow analysis is affected by the traversal and parsing of the nodes in the corresponding mini-program's abstract syntax tree. The more complex the JavaScript code structure of the page logic layer of the mini-program, such as the greater the nesting of code blocks and callback functions, the longer the data flow analysis will take.

[0116] As can be seen from the above-described method for analyzing the data flow of mini-programs based on abstract syntax trees, this application classifies and summarizes user privacy data in mini-programs, identifies corresponding privacy data sources, and formulates corresponding analysis strategies. At the same time, this application does not rely on other analysis tools, adapts to some special mechanisms in mini-programs, and implements cross-function analysis during the static analysis process of mini-programs.

[0117] It should be noted that the method in this embodiment can be executed by a single device, such as a computer or server. The method can also be applied in a distributed scenario, where multiple devices cooperate to complete the task. In such a distributed scenario, one of these devices may execute only one or more steps of the method in this embodiment, and the multiple devices will interact with each other to complete the method described.

[0118] It should be noted that the above description describes some embodiments of this application. Other embodiments are within the scope of the appended claims. In some cases, the actions or steps recorded in the claims can be performed in a different order than that shown in the above embodiments and still achieve the desired result. Furthermore, the processes depicted in the drawings do not necessarily require a specific or sequential order to achieve the desired result. In some embodiments, multitasking and parallel processing are also possible or may be advantageous.

[0119] Based on the same technical concept, and corresponding to any of the above embodiments, this application also provides a mini-program data flow analysis device based on an abstract syntax tree.

[0120] refer to Figure 7 The mini-program data flow analysis device based on abstract syntax tree includes:

[0121] Module 701 is used to construct the abstract syntax tree of the mini-program based on its code syntax structure.

[0122] The acquisition module 702 is used to acquire the code syntax structure of the mini-program; and to acquire the target privacy data source and the corresponding target element features in the abstract syntax tree.

[0123] Module 703 is configured to determine a callback function for the target element features based on the target privacy data source and the corresponding target element features in the abstract syntax tree; and

[0124] The parameters used to determine the critical path of the callback function;

[0125] The preset module 704 is used to preset the privacy data source and corresponding element characteristics of the mini program.

[0126] Furthermore, the acquisition module is used to acquire the logic layer code of the mini-program, the Page function of the logic layer code, and the data attribute function and function attribute function in the Page function.

[0127] The building module is used to construct the abstract syntax tree (AST) of the mini-program based on the Page function, data attribute function, and function attribute function.

[0128] For ease of description, the above devices are described in terms of function, divided into various modules. Of course, in implementing this application, the functions of each module can be implemented in one or more software and / or hardware.

[0129] The apparatus described above is used to implement the corresponding mini-program data flow analysis method based on abstract syntax tree in any of the foregoing embodiments, and has the beneficial effects of the corresponding method embodiments, which will not be repeated here.

[0130] Based on the same technical concept, corresponding to the methods of any of the above embodiments, this application also provides an electronic device, including a memory, a processor, and a computer program stored in the memory and executable on the processor. When the processor executes the program, it implements the applet data flow analysis method based on abstract syntax tree described in any of the above embodiments.

[0131] Figure 8 This embodiment illustrates a more specific hardware structure of an electronic device, which may include a processor 1010, a memory 1020, an input / output interface 1030, a communication interface 1040, and a bus 1050. The processor 1010, memory 1020, input / output interface 1030, and communication interface 1040 are interconnected internally via the bus 1050.

[0132] The processor 1010 can be implemented using a general-purpose CPU (Central Processing Unit), microprocessor, application-specific integrated circuit (ASIC), or one or more integrated circuits, and is used to execute relevant programs to implement the technical solutions provided in the embodiments of this specification.

[0133] The memory 1020 can be implemented in the form of ROM (Read Only Memory), RAM (Random Access Memory), static storage device, dynamic storage device, etc. The memory 1020 can store the operating system and other applications. When the technical solutions provided in the embodiments of this specification are implemented by software or firmware, the relevant program code is stored in the memory 1020 and is called and executed by the processor 1010.

[0134] The input / output interface 1030 is used to connect input / output modules to realize information input and output. Input / output modules can be configured as components within the device (not shown in the figure) or externally connected to the device to provide corresponding functions. Input devices may include keyboards, mice, touchscreens, microphones, various sensors, etc., while output devices may include displays, speakers, vibrators, indicator lights, etc.

[0135] The communication interface 1040 is used to connect a communication module (not shown in the figure) to enable communication between this device and other devices. The communication module can communicate via wired means (such as USB, Ethernet cable, etc.) or wireless means (such as mobile network, WIFI, Bluetooth, etc.).

[0136] Bus 1050 includes a pathway for transmitting information between various components of the device, such as processor 1010, memory 1020, input / output interface 1030, and communication interface 1040.

[0137] It should be noted that although the above-described device only shows the processor 1010, memory 1020, input / output interface 1030, communication interface 1040, and bus 1050, in specific implementations, the device may also include other components necessary for normal operation. Furthermore, those skilled in the art will understand that the above-described device may only include the components necessary for implementing the embodiments of this specification, and not necessarily all the components shown in the figures.

[0138] The electronic devices described above are used to implement the corresponding mini-program data flow analysis methods based on abstract syntax trees in any of the foregoing embodiments, and have the beneficial effects of the corresponding method embodiments, which will not be elaborated here.

[0139] Based on the same technical concept, corresponding to the methods of any of the above embodiments, this application also provides a non-transitory computer-readable storage medium that stores computer instructions for causing the computer to execute the applet data flow analysis method based on the abstract syntax tree as described in any of the above embodiments.

[0140] The computer-readable medium of this embodiment includes permanent and non-permanent, removable and non-removable media, and information storage can be implemented by any method or technology. Information can be computer-readable instructions, data structures, program modules, or other data. Examples of computer storage media include, but are not limited to, phase-change memory (PRAM), static random access memory (SRAM), dynamic random access memory (DRAM), other types of random access memory (RAM), read-only memory (ROM), electrically erasable programmable read-only memory (EEPROM), flash memory or other memory technologies, CD-ROM, digital versatile optical disc (DVD) or other optical storage, magnetic tape, magnetic magnetic disk storage or other magnetic storage devices, or any other non-transfer medium that can be used to store information accessible by a computing device.

[0141] The computer instructions stored in the storage medium of the above embodiments are used to cause the computer to execute the applet data flow analysis method based on the abstract syntax tree as described in any of the above embodiments, and have the beneficial effects of the corresponding method embodiments, which will not be repeated here.

[0142] Those skilled in the art should understand that the discussion of any of the above embodiments is merely exemplary and is not intended to imply that the scope of this application (including the claims) is limited to these examples; within the framework of this application, the technical features of the above embodiments or different embodiments can also be combined, the steps can be implemented in any order, and there are many other variations of different aspects of the embodiments of this application as described above, which are not provided in the details for the sake of brevity.

[0143] Additionally, to simplify the description and discussion, and to avoid obscuring the embodiments of this application, the well-known power / ground connections to integrated circuit (IC) chips and other components may or may not be shown in the provided drawings. Furthermore, the apparatus may be shown in block diagram form to avoid obscuring the embodiments of this application, and this also takes into account the fact that the details of the implementation of these block diagram apparatuses are highly dependent on the platform on which the embodiments of this application will be implemented (i.e., these details should be fully understood by those skilled in the art). While specific details (e.g., circuits) have been set forth to describe exemplary embodiments of this application, it will be apparent to those skilled in the art that the embodiments of this application can be implemented without these specific details or with variations thereof. Therefore, these descriptions should be considered illustrative rather than restrictive.

[0144] Although this application has been described in conjunction with specific embodiments thereof, many substitutions, modifications, and variations of these embodiments will be apparent to those skilled in the art from the foregoing description. For example, other memory architectures (e.g., dynamic RAM (DRAM)) may be used with the embodiments discussed.

[0145] The embodiments of this application are intended to cover all such substitutions, modifications, and variations that fall within the broad scope of the appended claims. Therefore, any omissions, modifications, equivalent substitutions, improvements, etc., made within the spirit and principles of the embodiments of this application should be included within the protection scope of this application.

Claims

1. A method for analyzing the data flow of a WeChat mini-program based on an abstract syntax tree, characterized in that, include: Obtain the syntax structure of the mini-program code, and construct the abstract syntax tree of the mini-program based on the syntax structure; wherein, the abstract syntax tree of the mini-program is constructed with the Page function of the mini-program as the root node and data attributes and function attributes as branch nodes; Based on the preset privacy data source of the mini program and the corresponding element features, obtain the target privacy data source and the corresponding target element features in the abstract syntax tree, and determine the callback function of the target element features; Based on the callback function, the nodes in the abstract syntax tree that contain the parameters of the callback function are determined as critical path nodes; Based on the critical path nodes, determine the propagation path of the privacy data in the callback function; Specifically, determining the nodes in the abstract syntax tree that contain the parameters of the callback function as critical path nodes, based on the callback function, includes: Locate the callback function, and parse the parameters of the callback function and the variables assigned by the callback function; The parameters of the callback function and the variables assigned by the callback function are compared with the first parameters in the preset first parameter set. In response to the first parameter in the first parameter set including the parameters of the callback function and the variable assigned by the callback function, the node in the abstract syntax tree containing the parameters of the callback function and the variable assigned by the callback function is determined to be a critical path node. The first parameter in the preset first parameter set includes the parameters of all callback functions involved in the privacy data source and the variables assigned by the callback functions.

2. The method according to claim 1, characterized in that, The step of obtaining the syntax structure of the mini-program code and constructing the abstract syntax tree of the mini-program based on the syntax structure includes: Obtain the logic layer code of the mini-program and determine the Page function of the logic layer code; Retrieve the data attributes and function attributes in the Page function; Based on the Page function, the data attributes, and the function attributes, an abstract syntax tree for the mini-program is established.

3. The method according to claim 1, characterized in that, The privacy data source includes: The input data of the program interface, the sensitive triggering events of the program interface, and the sensitive APIs of the mini program; The element features corresponding to the input data and sensitive triggering events of the program interface include: Use properties containing the `bind` or `catch` keywords to bind event callback functions; The elements of the sensitive API include at least one of the following: system information, media information, location information, user information, and privacy data.

4. The method according to claim 1, characterized in that, The step of obtaining the target privacy data source and the corresponding target element features in the abstract syntax tree, and determining the callback function for the target element features, includes: Obtain the WXML file in the view layer of the mini-program as the target privacy data source; The target element features in the WXML file are located using XML analysis. Based on the location of the target element features, obtain the callback function in the logic layer of the mini-program that corresponds to the target element features.

5. The method according to claim 1, characterized in that, If the parameters responding to the callback function and the variables assigned by the callback function belong to the first parameter set, then after determining that the parameters of the callback function are critical path nodes, the method further includes: The callback function is recursively called on all child nodes of the critical path node in the abstract syntax tree to obtain the first return value after the recursive call. Compare the variable in the first return value with the first parameter in the preset first parameter set; If the first parameter of the first parameter set includes a variable of the first return value, then the current child node is determined to be the critical path node.

6. The method according to claim 1, characterized in that, The parameters of the callback function and the variables assigned by the callback function are compared with the first parameters in the preset first parameter set, and then the process further includes: The page member functions of the mini-program are compared with the preset page member functions. In response to mutual calls between page member functions of the mini-program and the use of user privacy data as parameters of the page member functions, the node mapping of the called page member function in the abstract syntax tree is determined, and the page member function is recursively called on all child nodes of the root node in the abstract syntax tree with the node mapping as the root node, and the second return value after the recursive call is obtained. Compare the variable in the second return value with the first parameter in the preset first parameter set; If the first parameter of the first parameter set includes a variable of the second return value, then the current child node is determined to be the critical path node; If the page member variable of the mini-program is used as a parameter for the this.setData function call, then the node in the abstract syntax tree where the this.setData function call is located is determined to be a critical path node; The preset page member functions include all page member function names of the mini program and the node mapping of the abstract syntax tree corresponding to the page member function names; The preset set of page member variables includes all page member variables that use the this.setData function to set user privacy data as the mini program.

7. A data flow analysis device for small programs based on abstract syntax trees, characterized in that, include: The building module is used to construct the abstract syntax tree of the mini-program based on its code syntax structure. The acquisition module is used to obtain the code syntax structure of the mini-program; Obtain the target privacy data source and the corresponding target element features from the abstract syntax tree; The determination module is used to determine the callback function of the target element feature based on the target privacy data source in the abstract syntax tree and the corresponding target element feature; as well as The parameters used to determine the critical path of the callback function; A tagging module is used to tag the critical path; The preset module is used to preset the privacy data source and corresponding element characteristics of the mini program; Specifically, determining the nodes in the abstract syntax tree that contain the parameters of the callback function as critical path nodes, based on the callback function, includes: Locate the callback function, and parse the parameters of the callback function and the variables assigned by the callback function; The parameters of the callback function and the variables assigned by the callback function are compared with the first parameters in the preset first parameter set. In response to the first parameter in the first parameter set including the parameters of the callback function and the variable assigned by the callback function, the node in the abstract syntax tree containing the parameters of the callback function and the variable assigned by the callback function is determined to be a critical path node. The first parameter in the preset first parameter set includes the parameters of all callback functions involved in the privacy data source and the variables assigned by the callback functions.

8. An electronic device comprising a memory, a processor, and a computer program stored in the memory and executable on the processor, characterized in that, When the processor executes the program, it implements the method as described in any one of claims 1 to 6.

9. A non-transitory computer-readable storage medium storing computer instructions, characterized in that, The computer instructions are used to cause the computer to perform the method as described in any one of claims 1 to 6.

Citation Information

Patent Citations

  • Method and system for detecting privacy data leakage for applet source code

    CN114880673A