Search

CN-121524030-B - Method, device, medium and program product for full path verification of interpreted script based on executor rewriting

CN121524030BCN 121524030 BCN121524030 BCN 121524030BCN-121524030-B

Abstract

The application provides an interpretation script full path verification method, device, medium and program product based on executor rewriting, wherein the method comprises the steps of acquiring an interpretation script and analyzing to generate an abstract syntax tree; the method comprises the steps of configuring a verification executor as an explanation execution main body of an abstract syntax tree, directing an explanation execution flow of the abstract syntax tree to the verification executor to carry out traversal explanation execution, adopting an overlay execution rule in the traversal explanation execution process to enable a plurality of execution paths corresponding to syntax nodes to be executed and continuously verifying the rest execution paths when abnormality occurs, and synchronously identifying a called script access object and carrying out white list verification processing in the traversal explanation execution process so as to realize safety verification of the accessible object range of the script when complete full path execution verification. The application performs collaborative verification on the execution logic and the access authority of the interpretation script, and improves the integrity, safety and reliability of script verification.

Inventors

  • HUANG TIANCI
  • LIU GUOPENG
  • FANG YUJUN

Assignees

  • 上海上湖信息技术有限公司

Dates

Publication Date
20260508
Application Date
20260113

Claims (9)

  1. 1. An interpretation script full path verification method based on executor rewriting, which is characterized by comprising the following steps: acquiring an explanation script to be verified, and analyzing the explanation script to generate an abstract syntax tree; Configuring a verification executor as an interpretation execution main body of an abstract syntax tree, directing an interpretation execution flow of the abstract syntax tree to the verification executor, and performing traversal type interpretation execution on the abstract syntax tree by the verification executor, wherein the method comprises the following steps of: The native classes of the interpreted Script engine include a builder class JexlBuilder, a Script engine core class JexlEngine, a Script interface or abstract definition class JexlScript, a Script implementation class Script, and an interpreted executor class Interpreter; The core classes for inheriting the corresponding native classes and generating the service rewriting on the premise of not changing the whole architecture of the native engine comprise KooBossJexlBuilder classes, kooBossJexlEngine classes, kooBossJexlScript classes and KooBossJexlInterpreter classes; Wherein KooBossJexlBuilder class inherits from JexlBuilder class, and is used for replacing the original script engine instance with the script engine instance for verification execution in the script engine instance creation stage by rewriting the construction method used for creating the script engine instance in the original constructor; The KooBossJexlEngine class inherits from the JexlEngine class and is used for respectively generating a script object for storing the abstract syntax tree and a verification executor for verifying execution by the script engine instance in a script parsing and execution object creating stage so as to replace a native script object and a native interpretation executor in the interpretation script engine; the KooBossJexlScript class inherits from the JexlScript class and is used for guiding a script execution request to a verification executor when the script object is triggered to be executed; The KooBossJexlInterpreter class inherits from the Interpter class and is used for rewriting default interpretation and execution semantics of various grammar nodes in the abstract grammar tree, and the KooBossJexlInterpreter class instance is used as a verification executor and is used for performing traversal interpretation and execution on the abstract grammar tree in a verification execution mode; In the process of traversing type interpretation and execution, adopting an overlay type execution rule for at least one type of grammar node in the abstract grammar tree, so that a plurality of execution paths corresponding to the grammar node are all executed, and when abnormal script execution occurs, the traversing type interpretation and execution is not interrupted due to the abnormal script execution, and verification and execution are continuously carried out on other grammar nodes and the execution paths, thereby realizing full-path execution verification of the interpretation script; in the traversing type interpretation executing process, synchronously identifying script access objects called by the interpretation script in the verification executing stage, and carrying out white list verification processing on the script access objects so as to realize safety verification of the accessible object range of the script when completing full-path execution verification.
  2. 2. The actuator rewriting-based interpreted script full path verification method of claim 1, wherein, The construction method generates a script engine instance for verification execution on the premise of keeping the original engine configuration parameters effective, and the script engine instance is configured to adopt a verification execution mechanism different from an interpretation script engine when analyzing and interpreting the script.
  3. 3. The method according to claim 1, wherein the step of generating, by the script engine instance, script objects for storing the abstract syntax tree and verification executors for verifying execution, respectively, in a script parsing and execution object creation phase, instead of native script objects and native interpretation executors in the interpreted script engine, comprises: the script engine instance rewrites the creation logic of the original script object, so that the generated script object has the execution scheduling capability of transmitting the script execution request to the verification executor while keeping the original script semantic representation capability; The script engine instance rewrites the creation logic of the original interpretation executor to generate a verification executor associated with the script object, wherein the verification executor is used for replacing the original interpretation executor in a script execution stage and performing traversal interpretation execution on the abstract syntax tree; And the script execution request is processed by a verification executor associated with the script object in a mode of redirecting an execution entry of the script object, so that the verification executor performs traversal interpretation and execution on the abstract syntax tree.
  4. 4. The method of claim 1, further comprising, prior to the step of verifying that the executor performs the traversal-type interpretation of the abstract syntax tree: rewriting, by the verification executor, default interpretation-execution semantics of at least one type of grammar node in the abstract syntax tree, including: for the branch control grammar node, adopting an overlay branch execution rule to execute a plurality of branch logics one by one without selecting a single execution path based on a running period condition; The method comprises the steps of canceling a short circuit evaluation rule for a logical operation class grammar node, completely evaluating each operand and recording an evaluation process; For the loop control grammar node, recording loop start-stop information and iteration state in the loop execution process, and continuing the subsequent iteration execution when the abnormality occurs in part of the iteration execution; the method calls class grammar nodes, records method call objects and method information, captures and degrades preset business anomalies, and avoids interrupting traversal interpretation and execution; And for the judgment type grammar node, when an abnormality occurs or an execution result is not determined, returning a preset verification result and recording abnormality information.
  5. 5. The method for full path verification of an interpreted script based on an executor rewrite according to claim 1, wherein the step of synchronously recognizing script access objects called by the interpreted script in a verification execution stage and performing a white list verification process on the script access objects during a traversal type interpretation execution process includes: Analyzing and identifying script access objects called in the verification execution process of the script from grammar nodes related to script execution semantics in the abstract grammar tree based on a reflection mechanism, wherein the script access objects comprise variable access objects and method call objects; Based on the script access object, respectively extracting the corresponding identifier name, access path and call parameter information, and respectively carrying out structural encapsulation on the variable access object and the method call object according to a preset data structure to form a variable call list and a method call list; Acquiring a preset access object white list, wherein the access object white list comprises a script access object set which is allowed to be accessed under a current script execution scene; and comparing and checking script access objects in the variable call list and the method call list with the access object white list, and determining abnormal script access objects which are not covered by the access object white list.
  6. 6. The method for full path verification of an interpreted script based on an executor overwrite as claimed in claim 1, wherein in the process of performing verification on the full path of the interpreted script, further comprising: Constructing a global execution state container for aggregating execution state data generated in a traversal interpretation execution process; Writing execution events generated by different grammar nodes in the traversing type interpretation execution process into the global execution state container in a unified data structure, wherein the execution events at least comprise one of grammar node identification, branch selection identification, execution sequence identification or abnormal state identification; And generating execution track data for representing the coverage condition of each execution path of the interpretation script in the verification execution process by carrying out association analysis on the aggregated execution events in the global execution state container.
  7. 7. An electronic device, the electronic device comprising: and a memory storing computer program instructions that, when executed, cause the processor to perform the interpreted script full path verification method based on executor re-writing of any of claims 1-6.
  8. 8. A computer readable storage medium having stored thereon a computer program and/or instructions which, when executed by a processor, implement the method of actuator overwrite based interpreted script full path verification of any of claims 1-6.
  9. 9. A computer program product comprising a computer program and/or instructions which, when executed by a processor, implement the method of actuator-based re-writing interpreted script full path verification of any of claims 1-6.

Description

Method, device, medium and program product for full path verification of interpreted script based on executor rewriting Technical Field The present application relates to the field of computer technologies, and in particular, to an interpretation script full path verification method, apparatus, medium, and program product based on executor rewriting. Background In a business system based on rule or policy driving, a target object is often screened, judged and controlled through a scripting language, so as to realize flexible configuration and dynamic adjustment of business logic. The interpretation script language is widely applied to business scenes such as user screening, rule calculation, condition judgment, strategy control and the like because of the characteristics of flexible deployment, no need of compiling, quick iteration and the like, and is used for dynamically executing corresponding business logic according to input parameters and context data. The conventional interpretation-type script language generally adopts an interpretation execution mechanism, and when the script execution engine runs the script, the actual execution path of the script is dynamically determined according to input conditions by analyzing line by line and calling corresponding methods or operation logic line by line. In practical application, to adapt to the requirements of frequent change of business rules and rapid deployment of scripts, the verification process of script logic usually depends on automatic execution of programs to complete, rather than manually constructing test data to test each logic branch one by one. Under the application scene, the characteristic that the interpretation type script language can only cover a single path in the execution process can directly cause the problem that branch logic coverage is incomplete in the script verification process, namely normal execution verification can only cover logic on one execution path, and other logic branches lack effective verification. In addition, the interpreted script language usually has weak type or dynamic binding characteristics, and the problems of whether the method exists, whether the number of the parameters of the method is correct, whether the parameter types are matched or not and the like are usually not found in the script parsing or loading stage, but are exposed in the running period when the script is actually executed to the corresponding method call node. When the above-mentioned operation period error is located in the logic branch which is not actually executed, even if the script has passed the verification or is on-line operation, the error may be hidden for a long period of time and triggered only under the specific input condition or service scene, thereby adversely affecting the operation stability of the system and the reliability of service processing. Therefore, the execution and verification modes of the conventional interpretation script are difficult to realize the full coverage verification of all execution paths of the script under a multi-logic branch scene, and have the defects of incomplete branch logic verification, difficult early discovery of running-period errors hidden in the untouched branches and the like. Disclosure of Invention Aiming at the defects existing in the prior art, the application provides an interpretation script full-path verification method, device, medium and program product based on executor rewriting, which are at least used for solving the problem that the prior art cannot realize the effective verification of full paths and full branches for scripts containing multiple logic branches. To achieve the above objects and other advantages, some embodiments of the application provide the following aspects: In a first aspect, some embodiments of the present application provide an interpreted script full path verification method based on executor rewriting, including: acquiring an explanation script to be verified, and analyzing the explanation script to generate an abstract syntax tree; Configuring a verification executor as an interpretation execution main body of an abstract syntax tree, directing an interpretation execution flow of the abstract syntax tree to the verification executor, and performing traversal interpretation execution on the abstract syntax tree by the verification executor; In the process of traversing type interpretation and execution, adopting an overlay type execution rule for at least one type of grammar node in the abstract grammar tree, so that a plurality of execution paths corresponding to the grammar node are all executed, and when abnormal script execution occurs, the traversing type interpretation and execution is not interrupted due to the abnormal script execution, and verification and execution are continuously carried out on other grammar nodes and the execution paths, thereby realizing full-path execution verification of the interpretation script; in the t