Proxy proxy detection method, system, device and product suitable for JavaScript object

By binding virtual properties on JavaScript objects and obtaining stack frame information, the problem of inability to accurately judge Proxy agents in existing technologies is solved, stable cross-platform detection and dynamic monitoring are achieved, and security and debugging efficiency are improved.

CN120508493BActive Publication Date: 2025-10-10CHENGDU YUBUO TECH CO LTD
View PDF 2 Cites 0 Cited by

Patent Information

Application Number
CN202511006187.0
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2025-07-22
Publication Date
2025-10-10
Estimated Expiration
2045-07-22

AI Technical Summary

Technical Problem

Existing technologies cannot accurately and stably determine whether a JavaScript object is proxied without modifying the original object or relying on specific implementations.

Method used

By binding virtual properties on the target JavaScript object and using the getter function to obtain stack frame information, combined with a customized error stack processing method, the caller type name is extracted to determine whether it is a Proxy proxy.

Benefits of technology

It can accurately and stably determine whether a JavaScript object is proxied without modifying the original object or relying on specific implementations. It supports cross-platform compatibility and dynamic analysis, and improves debugging efficiency and security.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN120508493B_ABST
    Figure CN120508493B_ABST
Patent Text Reader

Abstract

The application discloses a Proxy proxy detection method, system, device and product suitable for JavaScript objects, and relates to the technical field of object state identification and security control. The method is that first, a virtual property for triggering detection logic through a getter function is bound on a target JavaScript object through an object operation tool Object.defineProperty, then the virtual property is actively accessed to trigger the getter function, and a custom error stack processing mode is implemented in the getter function to obtain stack frame information of the target object, finally, a caller type name related to the current access behavior of the target object is extracted from the stack frame information, and when it is found that the name matches the string "Proxy", it is determined that the target object has been proxied by Proxy, so that whether the target object is proxied by Proxy can be accurately and stably judged without modifying the original object or depending on the specific implementation, an empty place in the object state identification in the JavaScript ecology is filled, and the method has good application value and business prospect.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present invention belongs to the technical field of object state identification and security control, and in particular relates to a Proxy agent detection method, system, device and product applicable to JavaScript objects. Background Art

[0002] JavaScript is a lightweight, interpreted, or just-in-time compiled, programming language widely used in web development, primarily to enhance the interactivity and dynamism of web pages. A proxy is a transparent proxy used to efficiently access remote services or other proxies. JavaScript's Proxy object allows developers to intercept and customize operations on target objects and is widely used in scenarios such as responsive frameworks (such as Vue), data binding, and access control. However, due to the transparency of proxies, the JavaScript standard does not provide a direct method to determine whether an object is a Proxy instance.

[0003] Currently, common methods for detecting whether a JavaScript object is proxied include the following: (1) checking the constructor; (2) using the Object.prototype.toString.call() function; (3) adding a custom marker attribute (which must be set proactively) that requires pre-injection; and (4) exploiting specific trap behaviors (which are easily circumvented) that require pre-injection. However, none of these methods can accurately and stably determine whether a JavaScript object is proxied without modifying the original object or relying on specific implementations. Summary of the Invention

[0004] The purpose of the present invention is to provide a proxy agent detection method, system, computer device, computer-readable storage product and computer program product applicable to JavaScript objects, so as to solve the problem that existing proxy agent detection schemes cannot accurately and stably determine whether a JavaScript object is a proxy without modifying the original object or relying on specific implementation.

[0005] In order to achieve the above object, the present invention adopts the following technical solutions:

[0006] In a first aspect, a proxy detection method applicable to JavaScript objects is provided, comprising:

[0007] Determine the target JavaScript object to be detected;

[0008] Bind a virtual property for triggering detection logic through a getter function on the target JavaScript object through the object operation tool Object.defineProperty;

[0009] Actively access the virtual attribute to trigger the getter function;

[0010] Implementing a custom error stack processing method in the getter function to obtain stack frame information of the target JavaScript object;

[0011] The target JavaScript object and the caller type name related to the current access behavior are extracted from the stack frame information, and when it is found that the caller type name matches the character string "Proxy", it is determined that the target JavaScript object has been proxied by Proxy.

[0012] Based on the above invention content, a practical, stable and cross-platform Proxy proxy detection mechanism is provided. That is, first, a virtual property for triggering the detection logic through a getter function is bound to the target JavaScript object through the object operation tool Object.defineProperty, then the virtual property is actively accessed to trigger the getter function, and a custom error stack processing method is implemented in the getter function to obtain the stack frame information of the target object. Finally, the target object and the caller type name related to the current access behavior are extracted from the stack frame information. When the name is found to match the string "Proxy", it is determined that the target object has been proxied by a Proxy. In this way, without modifying the original object or relying on the specific implementation, it is possible to accurately and stably determine whether the target object is proxied by a Proxy. This fills a gap in object state recognition in the JavaScript ecosystem, has good application value and commercial prospects, and is easy to apply and promote in practice.

[0013] In a possible design, the virtual attribute is a non-enumerable attribute, and / or the name of the virtual attribute is a randomly generated unique identifier or a preset fixed name.

[0014] In a possible design, actively accessing the virtual attribute includes:

[0015] The virtual property is explicitly accessed by inserting a line of access statement during the debugging phase, or the virtual property is implicitly accessed by triggering it in any lifecycle hook.

[0016] In one possible design, a custom error stack processing method is implemented in the getter function to obtain stack frame information of the target JavaScript object, including:

[0017] Introduce the Error.prepareStackTrace custom mechanism into the getter function and temporarily rewrite the Error.prepareStackTrace function as follows: replace the Error.prepareStackTrace function with a custom function that receives the error object itself and a structured stack frame array, where each stack frame array represents a function call and contains metadata about the corresponding call, including the file path, line number, column number, function name, and / or constructor flags;

[0018] Create and throw a temporary error object in the getter function to trigger the call of the overridden Error.prepareStackTrace function to capture the current call stack of the target JavaScript object and eliminate unnecessary stack frames;

[0019] The stack frame array corresponding to the current call stack is traversed, and the field contents of the function name field, the type name field, and the constructor identification field of each frame are extracted as the stack frame information of the target JavaScript object.

[0020] In a possible design, extracting the target JavaScript object and the caller type name related to the current access behavior from the stack frame information includes:

[0021] The function getTypeName() is called to directly obtain the caller type name of the target JavaScript object and related to the current access behavior from the stack frame information.

[0022] In one possible design, after calling the function getTypeName(), the method further includes:

[0023] If direct acquisition fails, the target JavaScript object and the caller type name related to the current access behavior are inferred through the function getFunctionName() according to the stack frame information.

[0024] In a second aspect, a Proxy agent detection system for JavaScript objects is provided, comprising a target object determination unit, an object property binding unit, a property function triggering unit, a stack information acquisition unit, and a type name matching unit, which are sequentially connected in communication;

[0025] The target object determination unit is used to determine the target JavaScript object to be detected;

[0026] The object property binding unit is used to bind a virtual property for triggering the detection logic through a getter function on the target JavaScript object through the object operation tool Object.defineProperty;

[0027] The property function triggering unit is used to actively access the virtual property and trigger the getter function;

[0028] The stack information acquisition unit is configured to implement a custom error stack processing method in the getter function to acquire stack frame information of the target JavaScript object;

[0029] The type name matching unit is used to extract the target JavaScript object and the caller type name related to the current access behavior from the stack frame information, and when it is found that the caller type name matches the string "Proxy", it determines that the target JavaScript object has been proxied by Proxy.

[0030] In a third aspect, the present invention provides a computer device comprising a memory, a processor and a transceiver which are communicatively connected in sequence, wherein the memory is used to store a computer program, the transceiver is used to send and receive messages, and the processor is used to read the computer program and execute the proxy agent detection method as described in the first aspect or any possible design of the first aspect.

[0031] In a fourth aspect, the present invention provides a computer-readable storage product having instructions stored thereon. When the instructions are run on a computer, the proxy agent detection method as described in the first aspect or any possible design of the first aspect is executed.

[0032] In a fifth aspect, the present invention provides a computer program product, comprising a computer program or instructions, which, when executed by a computer, implements the proxy agent detection method as described in the first aspect or any possible design of the first aspect.

[0033] Beneficial effects of the above scheme:

[0034] (1) The present invention creatively provides a practical, stable and cross-platform proxy detection mechanism, which first binds a virtual property for triggering the detection logic through a getter function on the target JavaScript object through the object operation tool Object.defineProperty, then actively accesses the virtual property to trigger the getter function, and implements a custom error stack processing method in the getter function to obtain the stack frame information of the target object. Finally, the target object and the caller type name related to the current access behavior are extracted from the stack frame information. When the name matches the string "Proxy", it is determined that the target object has been proxied by Proxy. In this way, without modifying the original object or relying on the specific implementation, it can accurately and stably determine whether the target object is proxied by Proxy, filling a gap in object state recognition in the JavaScript ecosystem, having good application value and commercial prospects, and facilitating practical application and promotion.

[0035] (2) Ability to handle cross-engine compatibility: Considering that different JavaScript engines (such as V8, SpiderMonkey, and JavaScriptCore) may have different implementation details of Proxy, a solution that can adapt to multiple operating environments is proposed. This means that it is not just designed for a specific platform, but aims to develop a detection algorithm that can work stably in various mainstream browsers and Node.js environments;

[0036] (3) Support for dynamic analysis: A technology has been developed that can dynamically monitor object state changes at runtime, allowing the system to identify in real time whether an object has been transformed into a proxy. This is particularly important for maintaining the security and stability of applications, especially in the presence of potential malicious code;

[0037] (4) Providing an efficient and low-intrusive implementation: We designed an efficient and low-overhead detection process to minimize the impact on application performance while maintaining low intrusion, meaning that this detection function can be integrated without large-scale modifications to the existing code structure;

[0038] (5) It solves the current problem of lack of reliable methods to detect JavaScript proxies and provides developers with powerful tools to enhance application security, debugging efficiency and performance optimization. It also achieves accurate judgment of whether an object is proxied by a proxy by combining various technical means such as exception capture, cross-platform adaptation and metadata management.

[0039] (5) Compared with the existing Proxy agent detection scheme, the following advantages are provided: non-intrusiveness, i.e., without changing the original object structure, triggering logic through attribute access; dynamic, i.e., executing on demand at runtime, saving resources; high precision, i.e., combining stack information and type identification to accurately determine whether the object is proxied; strong extensibility, i.e., further extended to other type detection (such as Reflect and Map / WeakMap, etc.); improving debugging efficiency, i.e., helping developers quickly identify whether the object is proxied, improving the ability to troubleshoot complex behaviors; enhancing security, i.e., preventing third-party code from tampering with critical objects without being detected; supporting dynamic analysis, i.e., applicable to runtime monitoring and object protection in sandbox environments; strong cross-platform compatibility, i.e., applicable to mainstream browsers, Node.js, and small program engines, etc.; and the like;

[0040] (6) A flexible and extensible dynamic detection framework is constructed, which is applicable to various advanced application scenarios, such as identifying whether the object is proxied in the development and debugging tool; preventing objects from being illegally proxied and tampered in the security detection module; dynamically determining whether the target has implanted aspect logic in the AOP (Aspect-Oriented-Progranning, aspect-oriented programming) programming framework; identifying the additional overhead caused by the proxy in the performance monitoring system; detecting whether malicious scripts have hijacked global objects in the front-end security framework; ensuring that the plug-in does not tamper with the core API (Application Programming Interface, application programming interface) in the plug-in system; identifying the proxy object in the IDE (Integrated Development Environment, integrated development environment) and debugger of the development tool; enhancing the security boundary control of the Web container in the sandbox isolation; and the like. BRIEF DESCRIPTION OF DRAWINGS

[0041] In order to more clearly illustrate the technical solutions in the embodiments of the present application or the prior art, the drawings needed to be used in the embodiments or the prior art description will be briefly introduced. Obviously, the drawings in the following description are only some embodiments of the present application, and other drawings can be obtained by those skilled in the art without creative labor.

[0042] Figure 1 The flowchart of the Proxy agent detection method for JavaScript objects provided by the embodiments of the present application is shown.

[0043] Figure 2 The structure diagram of the Proxy agent detection system for JavaScript objects provided by the embodiments of the present application is shown.

[0044] Figure 3 A schematic diagram of the structure of a computer device provided in an embodiment of the present application. DETAILED DESCRIPTION

[0045] In order to more clearly illustrate the embodiments of the present invention or the technical solutions in the prior art, the present invention will be briefly introduced below in conjunction with the drawings and the description of the embodiments or the prior art. Obviously, the following description of the structures of the drawings is only some embodiments of the present invention. For those skilled in the art, other embodiments can be obtained based on these embodiments without creative work. It should be noted that the description of these embodiments is used to help understand the present invention, but does not constitute a limitation of the present invention.

[0046] It should be understood that although the terms first, second, etc. may be used herein to describe various objects, these objects should not be limited by these terms. These terms are merely used to distinguish one object from another. For example, a first object can be referred to as a second object, and similarly, a second object can be referred to as a first object without departing from the scope of the exemplary embodiments of the present invention.

[0047] It should be understood that the term "and / or" that may appear in this document is merely a description of the association relationship between associated objects, indicating that there may be three relationships. For example, A and / or B can indicate three situations: A exists alone, B exists alone, or A and B exist at the same time. For another example, A, B and / or C can indicate the existence of any one of A, B and C or any combination of them. The term " / and" that may appear in this document describes another type of association object relationship, indicating that there may be two relationships. For example, A / and B can indicate two situations: A exists alone or A and B exist at the same time. In addition, the character " / " that may appear in this document generally indicates that the previous and next associated objects are in an "or" relationship.

[0048] Example

[0049] like Figure 1 As shown, the Proxy agent detection method provided in the first aspect of this embodiment and applicable to JavaScript objects can be executed by, but is not limited to, a computer device with certain computing resources, such as a cloud server, a personal computer (PC, a multi-purpose computer with a size, price, and performance suitable for personal use; desktops, laptops, small laptops, tablets, and ultrabooks are all personal computers), a smart phone, a personal digital assistant (PDA), or a wearable device. Figure 1As shown, the Proxy agent detection method may include, but is not limited to, the following steps S1 to S5.

[0050] S1. Determine the target JavaScript object to be detected.

[0051] In step S1, the target JavaScript object is the target object for behavior monitoring or type identification. This object may be a regular object, a function, or a class instance, or even a proxy object constructed using a proxy. In advanced scenarios such as browser environments, Node.js environments, and embedded JavaScript engines, users may wish to dynamically identify whether the object is encapsulated within a proxy to avoid misjudging its original type. Furthermore, the target JavaScript object may be determined, specifically but not limited to, through conventional manual specification or automatic screening.

[0052] S2. Bind a virtual property for triggering the detection logic through a getter function to the target JavaScript object through the object operation tool Object.defineProperty.

[0053] In step S2, to transparently monitor the target JavaScript object, a "virtual property"—that is, one that doesn't actually store a value—is bound to it, and specific detection logic is triggered via a getter function. This process is implemented using Object.defineProperty (a powerful and flexible object manipulation tool in JavaScript that can be used for a variety of purposes, including defining new properties, modifying existing properties, precisely controlling property attributes, and implementing property accessors). The virtual property is preferably set to non-enumerable (i.e., enumerable: false) to prevent discovery through conventional traversal. Specifically, the name of the virtual property can be a randomly generated unique identifier or a preset fixed name (e.g., _$$internalCheck$$). The getter function does not return any actual data, but instead serves as a trigger to initiate subsequent call stack analysis and type identification logic (i.e., detection logic). Specifically, when the virtual property is accessed, the JavaScript engine automatically calls the getter function to execute the predetermined behavior. This design enables a non-intrusive property injection mechanism, allowing monitoring capabilities to be embedded into existing code without modification.

[0054] S3. Actively access the virtual attribute to trigger the getter function.

[0055] In step S3, in order to activate the above-mentioned detection logic, it is necessary to explicitly or implicitly access this virtual attribute at runtime (when the attribute is accessed, the function body of the getter function will be automatically entered) so as to start executing a series of deep detection operations, including error stack capture, context analysis, and type determination. Specifically, actively accessing the virtual attribute includes but is not limited to: explicitly accessing the virtual attribute by inserting a line of access statement during the debugging phase, or triggering implicit access to the virtual attribute in any lifecycle hook. The above-mentioned design can embody the idea of ​​delayed execution and on-demand triggering, ensuring that resources are consumed only when necessary.

[0056] S4. Implement a custom error stack processing method in the getter function to obtain stack frame information of the target JavaScript object.

[0057] In step S4, inside the getter function, in order to precisely control the format and content of the stack frame information, it is necessary to introduce a custom mechanism called Error.prepareStackTrace (in JavaScript, Error.prepareStackTrace is a static method used to customize the format of the error stack; this method is very useful when the user wants to control how the stack trace information of the error object is displayed when it is printed or captured). Specifically, a custom error stack processing method is implemented in the getter function to obtain the stack frame information of the target JavaScript object, including but not limited to the following steps S41 to S43.

[0058] S41. Introduce the Error.prepareStackTrace custom mechanism into the getter function and temporarily rewrite the Error.prepareStackTrace function as follows: replace the Error.prepareStackTrace function with a custom function for receiving the error object itself and a structured stack frame array, wherein each stack frame array represents a function call and includes but is not limited to metadata of the corresponding call, etc., and the metadata includes but is not limited to the file path, line number, column number, function name and / or constructor flags, etc.

[0059] In step S41, the stack frame array is also an array of CallSite objects, where CallSite is a concept in the Java virtual machine used for dynamic method calls; it is an abstract class that does not allow users to directly subclass; CallSite represents a variable method handle whose target can be changed at runtime, which is very useful for implementing dynamic behavior.

[0060] S42. Create and throw a temporary error object in the getter function to trigger the call of the overridden Error.prepareStackTrace function to capture the current call stack of the target JavaScript object and eliminate unnecessary stack frames.

[0061] In step S42, the temporary error object may be an empty error object created using the new Error() function. The rewritten Error.prepareStackTrace function may be represented by Error.captureStackTrace(error, targetObj), where error represents the temporary error object and targetObj represents the target JavaScript object. The unnecessary stack frame may be, but is not limited to, a stack frame corresponding to the target JavaScript object's wrapper layer.

[0062] S43. Traverse the stack frame array corresponding to the current call stack, and extract the field contents of each frame, such as the function name field, the type name field, and the constructor identification field, as the stack frame information of the target JavaScript object.

[0063] In step S43 , special attention needs to be paid to the context of the current call frame during traversal, especially the call hierarchy related to the target JavaScript object.

[0064] S5. Extract the target JavaScript object and the caller type name related to the current access behavior from the stack frame information, and when it is found that the caller type name matches the string "Proxy", determine that the target JavaScript object has been proxied by Proxy.

[0065] In the step S5, specifically, the target JavaScript object and the caller type name related to the current access behavior are extracted from the stack frame information. The caller type name includes but is not limited to: calling the function getTypeName() to directly obtain the target JavaScript object and the caller type name related to the current access behavior from the stack frame information. The function getTypeName() is an existing function. When the target JavaScript object is a CallSite object, if the environment supports, the function getTypeName() can be called to directly obtain the name of the type to which the caller belongs (i.e., the caller type name). If direct obtaining is not possible, the possible type name can also be inferred through getFunctionName() or other methods, i.e., after calling the function getTypeName(), the method further includes but is not limited to: if direct obtaining fails, the target JavaScript object and the caller type name related to the current access behavior are inferred through the function getFunctionName() according to the stack frame information. The function getFunctionName() is also an existing function. In addition, the caller type name can be compared with the string "Proxy" through a string comparison method. If the comparison is successful, it indicates that the current access behavior is triggered by a Proxy object, and it can be inferred that the target JavaScript object has been proxied. Otherwise, it is not. Thus, the meta information in the JavaScript stack trace can be used in combination with the reflection capability at the language level to implement a type detection mechanism without relying on instanceof.

[0066] Therefore, based on the proxy detection method described in the aforementioned steps S1 to S5, a practical, stable, and cross-platform proxy detection mechanism is provided. That is, first, a virtual property for triggering the detection logic through a getter function is bound to the target JavaScript object through the object operation tool Object.defineProperty. Then, the virtual property is actively accessed to trigger the getter function, and a custom error stack processing method is implemented in the getter function to obtain the stack frame information of the target object. Finally, the caller type name of the target object and related to the current access behavior is extracted from the stack frame information. When the name matches the string "Proxy", it is determined that the target object has been proxied. In this way, without modifying the original object or relying on the specific implementation, it is possible to accurately and stably determine whether the target object is proxied. This fills a gap in object state recognition in the JavaScript ecosystem, has good application value and commercial prospects, and is easy to apply and promote in practice.

[0067] like Figure 2 As shown, the second aspect of this embodiment provides a virtual system for implementing the proxy agent detection method described in the first aspect, including a target object determination unit, an object attribute binding unit, an attribute function triggering unit, a stack information acquisition unit, and a type name matching unit that are sequentially connected in communication;

[0068] The target object determination unit is used to determine the target JavaScript object to be detected;

[0069] The object property binding unit is used to bind a virtual property for triggering the detection logic through a getter function on the target JavaScript object through the object operation tool Object.defineProperty;

[0070] The property function triggering unit is used to actively access the virtual property and trigger the getter function;

[0071] The stack information acquisition unit is configured to implement a custom error stack processing method in the getter function to acquire stack frame information of the target JavaScript object;

[0072] The type name matching unit is used to extract the target JavaScript object and the caller type name related to the current access behavior from the stack frame information, and when it is found that the caller type name matches the string "Proxy", it determines that the target JavaScript object has been proxied by Proxy.

[0073] The working process, working details and technical effects of the aforementioned system provided by the second aspect of the embodiment can be referred to the Proxy proxy detection method described in the first aspect, which will not be repeated here.

[0074] As shown in Figure 3 The third aspect of the embodiment provides a computer device for executing the Proxy proxy detection method described in the first aspect, which includes a memory, a processor and a transceiver connected in sequence, wherein the memory is used to store a computer program, the transceiver is used to transceive messages, and the processor is used to read the computer program and execute the Proxy proxy detection method described in the first aspect. Specifically, the memory can include, but is not limited to, a random access memory (RAM), a read-only memory (ROM), a flash memory, a first-in first-out memory (FIFO) and / or a first-in last-out memory (FILO), etc.; and the processor can be, but is not limited to, a microprocessor with a model number of STM32F105 series. In addition, the computer device can further include, but is not limited to, a power module, a display screen and other necessary components.

[0075] The working process, working details and technical effects of the aforementioned computer device provided by the third aspect of the embodiment can be referred to the Proxy proxy detection method described in the first aspect, which will not be repeated here.

[0076] The fourth aspect of the embodiment provides a computer readable storage product storing instructions of the Proxy proxy detection method described in the first aspect, i.e. the computer readable storage product stores instructions, when the instructions run on a computer, the Proxy proxy detection method described in the first aspect is executed. Wherein the computer readable storage product refers to a carrier for storing data, which can include, but is not limited to, floppy disks, optical disks, hard disks, flash memories, USB flash disks and / or memory sticks, etc. The computer can be a general-purpose computer, a special-purpose computer, a computer network or other programmable devices.

[0077] The working process, working details and technical effects of the aforementioned computer readable storage product provided by the fourth aspect of the embodiment can be referred to the Proxy proxy detection method described in the first aspect, which will not be repeated here.

[0078] The fifth aspect of the embodiment provides a computer program product comprising computer programs or instructions which, when executed by a computer, implement the Proxy agent detection method according to the first aspect. The computer can be a general-purpose computer, a special-purpose computer, a computer network or other programmable devices.

[0079] Finally, it should be noted that the above only describes the preferred embodiments of the present application and is not used to limit the protection scope of the present application. Any modification, equivalent replacement, improvement, etc. made within the spirit and principle of the present application shall be included in the protection scope of the present application.

Claims

1. A proxy detection method applicable to JavaScript objects, characterized in that: include: Determine the target JavaScript object to be detected; Bind a virtual property for triggering detection logic through a getter function on the target JavaScript object through the object operation tool Object.defineProperty; Actively access the virtual attribute to trigger the getter function; Implementing a custom error stack processing method in the getter function to obtain stack frame information of the target JavaScript object, specifically comprising: introducing an Error.prepareStackTrace custom mechanism in the getter function, and temporarily rewriting the Error.prepareStackTrace function in the following manner: replacing the Error.prepareStackTrace function with a custom function for receiving an error object itself and a structured stack frame array, wherein each stack frame array represents a function call and contains meta-information of the corresponding call, the meta-information including a file path, line number, column number, function name, and / or constructor flag; creating and throwing a temporary error object in the getter function to trigger calling the rewritten Error.prepareStackTrace function to capture the current call stack of the target JavaScript object and eliminate unnecessary stack frames; traversing the stack frame array corresponding to the current call stack, extracting the field contents of the function name field, type name field, and constructor identification field of each frame as the stack frame information of the target JavaScript object; The target JavaScript object and the caller type name related to the current access behavior are extracted from the stack frame information, and when it is found that the caller type name matches the string "Proxy", it is determined that the target JavaScript object has been proxied by Proxy.

2. The Proxy detection method according to claim 1, characterized in that: The virtual attribute is a non-enumerable attribute, and / or the name of the virtual attribute is a randomly generated unique identifier or a preset fixed name.

3. The Proxy detection method according to claim 1, characterized in that: Actively accessing the virtual attributes includes: The virtual property is explicitly accessed by inserting a line of access statement during the debugging phase, or the virtual property is implicitly accessed by triggering it in any lifecycle hook.

4. The Proxy detection method according to claim 1, characterized in that: Extracting the target JavaScript object and the caller type name related to the current access behavior from the stack frame information includes: The function getTypeName() is called to directly obtain the caller type name of the target JavaScript object and related to the current access behavior from the stack frame information.

5. The Proxy detection method according to claim 4, characterized in that: After calling the function getTypeName(), the method further includes: If direct acquisition fails, the target JavaScript object and the caller type name related to the current access behavior are inferred through the function getFunctionName() according to the stack frame information.

6. A proxy detection system for JavaScript objects, characterized in that: It includes a target object determination unit, an object attribute binding unit, an attribute function triggering unit, a stack information acquisition unit and a type name matching unit which are sequentially connected in communication; The target object determining unit is used to determine the target JavaScript object to be detected; The object property binding unit is used to bind a virtual property for triggering the detection logic through a getter function on the target JavaScript object through the object operation tool Object.defineProperty; The property function triggering unit is used to actively access the virtual property and trigger the getter function; The stack information acquisition unit is configured to implement a customized error stack processing method in the getter function to obtain stack frame information of the target JavaScript object, specifically comprising: introducing an Error.prepareStackTrace customized mechanism in the getter function, and temporarily rewriting the Error.prepareStackTrace function in the following manner: replacing the Error.prepareStackTrace function with a customized function for receiving an error object itself and a structured stack frame array, wherein each stack frame array represents a function call and contains meta-information of the corresponding call, the meta-information including a file path, line number, column number, function name, and / or constructor flag; creating and throwing a temporary error object in the getter function to trigger calling the rewritten Error.prepareStackTrace function to capture the current call stack of the target JavaScript object and eliminate unnecessary stack frames; traversing the stack frame array corresponding to the current call stack, extracting the field contents of the function name field, type name field, and constructor identification field of each frame as the stack frame information of the target JavaScript object; The type name matching unit is used to extract the caller type name of the target JavaScript object and related to the current access behavior from the stack frame information, and when it is found that the caller type name matches the string "Proxy", it determines that the target JavaScript object has been proxied by Proxy.

7. A computer device, characterized in that: The invention comprises a memory, a processor and a transceiver which are communicatively connected in sequence, wherein the memory is used to store a computer program, the transceiver is used to send and receive messages, and the processor is used to read the computer program and execute the proxy agent detection method according to any one of claims 1 to 5.

8. A computer-readable storage product, characterized in that The computer-readable storage product stores instructions, and when the instructions are run on a computer, the proxy agent detection method according to any one of claims 1 to 5 is executed.

9. A computer program product comprising a computer program or instructions, characterized in that When the computer program or the instruction is executed by a computer, the proxy detection method according to any one of claims 1 to 5 is implemented.

Citation Information

Patent Citations

  • System interface calling detection method and device

    CN112560022A

  • System and method for data communication

    CN116601925A