Mybatis framework SQL statement anomaly detection method, server and system

Through the Mybatis framework SQL statement exception detection method, SQL configuration files are parsed and preset scanning rules are applied to perform exception detection of SQL statements in Mybatis framework applications, solving the problems of SQL statement quality verification lag and high cost in the existing technology , realizes SQL statement quality detection in the development stage, and improves the efficiency and security of SQL execution.

CN114116765BActive Publication Date: 2024-12-20CCB FINTECH CO LTD
View PDF 2 Cites 0 Cited by

Patent Information

Application Number
CN202111414284.5
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2021-11-25
Publication Date
2024-12-20
Estimated Expiration
2041-11-25

AI Technical Summary

Technical Problem

The quality inspection of SQL statements in the fields of financial business IT and other fields in the existing technology is mainly carried out in the testing stage, which leads to late discovery of problems and high resolution costs. Moreover, the quality inspection of SQL statements that have not been executed is not obtained, and the abnormality in the development stage is lacking. Detection affects system performance and reliability.

Method used

Provides an exception detection method for SQL statements in Mybatis framework. By parsing SQL configuration files and preset scanning rules, exception detection is performed on SQL statements. If there are any problems, feedback is given to the user to modify the application, improving the efficiency and security of SQL statements, including code parsing Module, exception detection module and information feedback module to realize SQL statement exception detection for Mybatis framework applications.

Benefits of technology

During the development stage, potential problems of SQL statements are discovered in a timely and comprehensive manner, improving the efficiency and security of SQL execution, reducing problem location and repair costs, and avoiding the lag of quality verification of running SQL statements.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN114116765B_ABST
    Figure CN114116765B_ABST
Patent Text Reader

Abstract

The present invention provides a Mybatis framework SQL statement anomaly detection method, server and system, which can be used in the field of artificial intelligence technology. The method comprises: parsing an SQL configuration file of a Mybatis framework application to obtain an SQL statement; performing anomaly detection on the SQL statement through at least one preset scanning rule, specifically comprising: determining whether it is necessary to scan a calling program corresponding to the SQL statement according to the preset scanning rule, if so, performing anomaly detection on the SQL statement and the calling program according to the preset scanning rule to obtain an anomaly detection result of the calling program, if not, performing anomaly detection on the SQL statement according to the preset scanning rule to obtain an anomaly detection result of the SQL statement. The present invention can perform SQL statement anomaly detection on a program code of a Mybatis framework in a development stage, thereby improving the efficiency and security of SQL statement execution.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present invention relates to the field of artificial intelligence technology, in particular to the field of text recognition technology, and more particularly to a Mybatis framework SQL statement anomaly detection method, server and system. Background Art

[0002] The performance and reliability of current business systems in the financial IT and other fields are largely related to the efficiency and robustness of SQL statements. SQL statement quality defects are one of the main causes of production incidents. Current SQL statement quality verification tools mainly conduct verification based on running SQL statements in the testing phase. Problems are discovered late, and the cost of solving them is relatively high. In addition, SQL statements that are not executed in the test cannot be quality verified. Summary of the invention

[0003] One object of the present invention is to provide a Mybatis framework SQL statement anomaly detection method, which performs SQL statement anomaly detection on the program code of the Mybatis framework in the development stage. If there is a problem, the anomaly detection result is fed back to the user so that the user can modify the application program to improve the efficiency and security of SQL statement execution. Another object of the present invention is to provide a scanning engine server. Another object of the present invention is to provide a Mybatis framework SQL statement anomaly detection system. Another object of the present invention is to provide a computer device. Another object of the present invention is to provide a readable medium.

[0004] In order to achieve the above objectives, the present invention discloses a Mybatis framework SQL statement anomaly detection method, comprising:

[0005] Parse the SQL configuration file of the Mybatis framework application to obtain SQL statements;

[0006] Performing anomaly detection on the SQL statement by using at least one preset scanning rule specifically includes: determining whether it is necessary to scan the calling program corresponding to the SQL statement according to the preset scanning rule, and if so, performing anomaly detection on the SQL statement and the calling program according to the preset scanning rule to obtain an anomaly detection result of the calling program, and if not, performing anomaly detection on the SQL statement according to the preset scanning rule to obtain an anomaly detection result of the SQL statement;

[0007] If the abnormal detection result indicates that there is a problem, the abnormal detection result is fed back to the user so that the user can modify the application.

[0008] Preferably, the step of parsing the SQL configuration file of the Mybatis framework application to obtain the SQL statement specifically includes:

[0009] The XML mapping file used as the SQL configuration file is parsed according to the Mybatis parsing rules to obtain the SQL statement.

[0010] Preferably, performing anomaly detection on the SQL statement and the calling program according to the preset scanning rule to obtain anomaly detection results specifically includes:

[0011] Determine, according to the SQL identifier of the SQL statement, a calling function in the calling program that calls the SQL statement;

[0012] Determine a calling function rule corresponding to the SQL statement in the preset scanning rule;

[0013] The calling function is subjected to an abnormality detection according to the calling function rule to obtain an abnormality detection result of the calling program.

[0014] Preferably, the preset scanning rule further includes an SQL statement rule, and the method further includes:

[0015] Anomaly detection is performed on the SQL statement according to the SQL statement rule to obtain an anomaly detection result of the SQL statement.

[0016] Preferably, further comprising:

[0017] If the abnormal detection result indicates that there is a problem, a unique identifier for each problem in the abnormal detection result is formed;

[0018] An anomaly detection result table is formed according to the unique identifier, the corresponding preset scanning rule and the relevant information of the problem.

[0019] Preferably, forming a unique identifier for each problem in the anomaly detection result specifically includes:

[0020] The unique identifier is formed based on the SQL ID of the problematic SQL statement and the namespace of the SQL configuration file.

[0021] Preferably, further comprising:

[0022] Perform SQL statement anomaly detection on the Mybatis framework application after the version update to obtain the update anomaly detection result;

[0023] If there is a problem with the update anomaly detection result, a unique identifier of the SQL statement in the update anomaly detection result is formed;

[0024] Check whether there is a corresponding unique identifier in the anomaly detection result table. If so, add the unique identifier, the corresponding preset scanning rule, and relevant information of the problem in the updated anomaly detection result to the anomaly detection result table. If not, add the unique identifier, the corresponding preset scanning rule, and relevant information of the problem to the anomaly detection result table.

[0025] The present invention also discloses a scanning engine server, comprising:

[0026] Code parsing module, used to parse the SQL configuration file of the Mybatis framework application to obtain SQL statements;

[0027] an anomaly detection module, configured to perform anomaly detection on the SQL statement through at least one preset scanning rule, specifically comprising: determining whether it is necessary to scan the calling program corresponding to the SQL statement according to the preset scanning rule, and if so, performing anomaly detection on the SQL statement and the calling program according to the preset scanning rule to obtain an anomaly detection result of the calling program; if not, performing anomaly detection on the SQL statement according to the preset scanning rule to obtain an anomaly detection result of the SQL statement;

[0028] The information feedback module is used to feed back the abnormality detection result to the user if the abnormality detection result shows that there is a problem, so that the user can modify the application.

[0029] Preferably, the code parsing module is specifically used to parse the XML mapping file as the SQL configuration file according to the Mybatis parsing rules to obtain the SQL statement.

[0030] Preferably, the anomaly detection module is specifically used to determine the calling function that calls the SQL statement in the calling program according to the SQL identifier of the SQL statement; determine the calling function rule corresponding to the SQL statement in the preset scanning rule; and perform anomaly detection on the calling function according to the calling function rule to obtain anomaly detection results of the calling program.

[0031] Preferably, the preset scanning rules further include SQL statement rules, and the anomaly detection module is further used to perform anomaly detection on the SQL statement according to the SQL statement rules to obtain an anomaly detection result of the SQL statement.

[0032] Preferably, it further includes a data processing module, which is used to form a unique identifier for each problem in the abnormal detection result if the abnormal detection result is a problem; and form an abnormal detection result table according to the unique identifier, the corresponding preset scanning rule and the relevant information of the problem.

[0033] Preferably, the data processing module is specifically used to form the unique identifier according to the SQL ID of the problematic SQL statement and the namespace of the SQL configuration file.

[0034] Preferably, the data processing module is further used to perform SQL statement anomaly detection on the Mybatis framework application after the version is updated to obtain an update anomaly detection result; if there is a problem with the update anomaly detection result, a unique identifier of the SQL statement in the update anomaly detection result is formed; check whether there is a corresponding unique identifier in the anomaly detection result table, if so, add the unique identifier, the corresponding preset scanning rule and the relevant information of the problem in the update anomaly detection result to the anomaly detection result table; if not, add the unique identifier, the corresponding preset scanning rule and the relevant information of the problem to the anomaly detection result table.

[0035] The present invention also discloses a Mybatis framework SQL statement anomaly detection system, including an application server and a scanning engine server;

[0036] The application server is used to send a scanning task to the engine server;

[0037] The scanning engine server is used to parse the SQL configuration file of the Mybatis framework application based on the scanning task to obtain an SQL statement, and perform anomaly detection on the SQL statement through at least one preset scanning rule, specifically including: determining whether it is necessary to scan the calling program corresponding to the SQL statement according to the preset scanning rule, if so, performing anomaly detection on the SQL statement and the calling program according to the preset scanning rule to obtain an anomaly detection result of the calling program, if not, performing anomaly detection on the SQL statement according to the preset scanning rule to obtain an anomaly detection result of the SQL statement, and if the anomaly detection result is a problem, feeding back the anomaly detection result to the user so that the user can modify the application.

[0038] The present invention also discloses a computer program product, comprising a computer program / instruction,

[0039] When the computer program / instructions are executed by a processor, the method described above is implemented.

[0040] The present invention also discloses a computer device, comprising a memory, a processor, and a computer program stored in the memory and executable on the processor.

[0041] When the processor executes the program, the method described above is implemented.

[0042] The present invention also discloses a computer readable medium having a computer program stored thereon.

[0043] When the program is executed by a processor, the method described above is implemented.

[0044] The Mybatis framework SQL statement anomaly detection method of the present invention parses the SQL configuration file of the Mybatis framework application to obtain SQL statements, and performs anomaly detection on the SQL statements through at least one preset scanning rule, specifically including: determining whether it is necessary to scan the calling program corresponding to the SQL statement according to the preset scanning rule, if so, performing anomaly detection on the SQL statement and the calling program according to the preset scanning rule to obtain the anomaly detection result of the calling program, if not, performing anomaly detection on the SQL statement according to the preset scanning rule to obtain the anomaly detection result of the SQL statement, if the anomaly detection result is a problem, the anomaly detection result is fed back to the user so that the user can modify the application. It can be seen that the present invention is based on the characteristics of the Mybatis framework, and the SQL configuration file of the Mybatis framework application in the development stage is parsed to obtain SQL statements, and the SQL statements are anomaly detected by preset scanning rules. In order to determine whether there will be problems with the execution of SQL statements when the Mybatis framework application is running, it can be determined whether the execution of the SQL statement of the anomaly detection is related to its calling program according to the rule content of the preset scanning rule, and if it is related, the calling program of the SQL statement is further anomaly detected to obtain the anomaly detection result. Therefore, in order to improve the problem location capability, the present invention performs SQL statement anomaly detection on the SQL configuration file and the corresponding calling program through preset scanning rules during the development process, moves the work of SQL statement anomaly detection forward to the development stage, performs standardization and security scans on the SQL statements in the submitted code files, analyzes the static code in the development stage, achieves the effect of running SQL statement quality anomaly detection, can timely and comprehensively discover potential problems of SQL statements so that users can adjust and modify the application in time, and improve the efficiency and security of SQL execution. BRIEF DESCRIPTION OF THE DRAWINGS

[0045] In order to more clearly illustrate the embodiments of the present invention or the technical solutions in the prior art, the drawings required for use in the embodiments or the description of the prior art will be briefly introduced below. Obviously, the drawings described below are only some embodiments of the present invention. For ordinary technicians in this field, other drawings can be obtained based on these drawings without paying creative work.

[0046] Figure 1 A structural diagram showing a specific embodiment of the Mybatis framework SQL statement anomaly detection system of the present invention;

[0047] Figure 2 A flowchart showing a specific embodiment of the Mybatis framework SQL statement anomaly detection method of the present invention;

[0048] Figure 3 A flowchart showing a specific embodiment of the Mybatis framework SQL statement anomaly detection method of the present invention includes S110;

[0049] Figure 4 A flowchart of a specific embodiment S200 of the Mybatis framework SQL statement anomaly detection method of the present invention is shown;

[0050] Figure 5 A flowchart showing a specific embodiment of the Mybatis framework SQL statement anomaly detection method of the present invention includes S240;

[0051] Figure 6 A flowchart of a specific embodiment S400 of the Mybatis framework SQL statement anomaly detection method of the present invention is shown;

[0052] Figure 7 A flowchart showing a specific embodiment of the Mybatis framework SQL statement anomaly detection method of the present invention includes S411;

[0053] Figure 8 A flowchart of a specific embodiment S500 of the Mybatis framework SQL statement anomaly detection method of the present invention is shown;

[0054] Fig. 9 A structural diagram showing a specific embodiment of a scanning engine server of the present invention;

[0055] Fig.10 A structural diagram showing a specific embodiment of the scanning engine server of the present invention including a data processing module;

[0056] Fig.11 A schematic diagram showing the structure of a computer device suitable for implementing an embodiment of the present invention is shown. DETAILED DESCRIPTION

[0057] The following will be combined with the drawings in the embodiments of the present invention to clearly and completely describe the technical solutions in the embodiments of the present invention. Obviously, the described embodiments are only part of the embodiments of the present invention, not all of the embodiments. Based on the embodiments of the present invention, all other embodiments obtained by ordinary technicians in this field without creative work are within the scope of protection of the present invention.

[0058] It should be noted that the Mybatis framework SQL statement anomaly detection method, server and system disclosed in the present application can be used in the field of artificial intelligence technology, and can also be used in any field outside the field of artificial intelligence technology. The application field of the Mybatis framework SQL statement anomaly detection method, server and system disclosed in the present application is not limited.

[0059] It should be noted that, in one or more embodiments of the present invention, Mybatis refers to a JAVA-based persistence layer framework, which is an open source project of Apache and is widely used in JAVA-type application systems.

[0060] Due to the excellent performance of JAVA language in terms of performance, cross-platform, robustness, and security, most of the current financial business IT systems and other application systems are developed using JAVA, and the persistence layer basically uses the Mybatis framework. The Mybatis framework supports custom SQL, stored procedures, and advanced mapping. MyBatis can configure and map primitive types, interfaces, and JAVA POJO (Plain Ordinary JAVA Objects) to records in the database through simple XML or annotations.

[0061] The MyBatis framework is mainly divided into the following four parts: (1) Loading configuration: There are two types of configuration. One is the configuration of the framework itself, such as data source configuration (for example, database configuration information) and mapper configuration. The SQL configuration information is loaded into a MappedStatement object (including the input parameter mapping configuration, the executed SQL statement, and the result mapping configuration) and stored in the memory. The other is the annotation of the JAVA code. (2) SQL parsing: When the API interface layer receives a call request, it will receive the SQL ID and the input object (which can be a Map, JAVABean or a basic data type) of the incoming SQL. Mybatis will find the corresponding MappedStatement based on the SQL ID, and then parse the MappedStatement based on the incoming parameter object. After parsing, the final SQL statement and parameters to be executed can be obtained. (3) SQL execution: The final SQL and parameters are taken to the database for execution to obtain the result of operating the database. (4) Result mapping: The result of operating the database is converted according to the mapping configuration, which can be converted into a HashMap, JAVABean or a basic data type, and the final result is returned to the service caller.

[0062] The existing SQL statement anomaly detection usually only performs troubleshooting when SQL execution problems are encountered during testing or production, which results in delayed problem discovery. The later the repair phase is, the higher the cost. In addition, SQL statement anomaly detection requires high database SQL capabilities of development and testing personnel, high problem diagnosis costs, and incomplete diagnosis. Only running SQL will be checked, which may miss potential problems.

[0063] Based on the problems existing in the prior art, the present invention can preliminarily confirm the SQL statements in the code by parsing the SQL configuration file of the Mybatis framework application, and further determine the executable SQL statements in combination with the calling program of the SQL statement. By determining whether the characteristics of the SQL statements extracted from the SQL configuration file and the calling program match the SQL scanning rules, it is possible to identify the existence of security risks, inefficient execution and other problems. The present invention solves the problems of lag, low efficiency and high cost of the current existing methods, and achieves the effect of automatically, timely and comprehensively discovering the quality problems of SQL statements in the Mybatis framework application in the development stage.

[0064] Figure 1 The following is a schematic diagram showing the structure of the Mybatis framework SQL statement anomaly detection system provided by an embodiment of the present invention. Figure 1 As shown, the Mybatis framework SQL statement anomaly detection system provided by the embodiment of the present invention includes an application server 1 and a scanning engine server 2.

[0065] The application server 1 is used to send a scanning task to the engine server based on the test instructions of the tester. The scanning task may include relevant information of the Mybatis framework application to be detected, so that the scanning engine server 2 determines the SQL configuration file and calling program code of the Mybatis framework application to be detected according to the scanning task, and performs SQL statement anomaly detection.

[0066] The scanning engine server 2 is used to parse the SQL configuration file of the Mybatis framework application based on the scanning task to obtain an SQL statement; perform anomaly detection on the SQL statement through at least one preset scanning rule, specifically including: determining whether it is necessary to scan the calling program corresponding to the SQL statement according to the preset scanning rule, if so, perform anomaly detection on the SQL statement and the calling program according to the preset scanning rule to obtain an anomaly detection result of the calling program, if not, perform anomaly detection on the SQL statement according to the preset scanning rule to obtain an anomaly detection result of the SQL statement, if the anomaly detection result is a problem, feed back the anomaly detection result to the user so that the user can modify the application.

[0067] In a preferred embodiment, the application server 1 includes a management layer, a task scheduling engine, an application layer and a presentation layer.

[0068] The display layer is used to display page information to users, including task lists, task information, and result information. The result information is mainly the detailed information of the scanned problems, such as the anomaly detection result table. The problem audit page mainly displays the detailed information of the problem audit to users on the page and receives the audit operation of the user.

[0069] The application layer is used to handle program processing that interacts with users (tester), mainly for scanning task management, adding, deleting, checking and modifying tasks, and problem auditing. It also performs false positive marking and audit review on SQL problems in the scan results based on the user's audit operations.

[0070] The task scheduling engine is used for the scheduling configuration, execution and management of scanning tasks, and also includes the management of scanning engine server 2. The SQL scanning engine service is separate from the application service, and the scanning engine server 2 is set separately from the application server 1. For example, in order to improve the scanning computing power and scanning efficiency, a separate server cluster can be set up, and multiple scanning engine servers 2 can be deployed in the separate server cluster to separate the scanning service from the application service, thereby allowing the dynamic expansion of the scanning service. The application service needs to manage the list of scanning engine servers 2, maintain the idle and busy status of each scanning engine server 2, and which servers can be assigned scanning tasks. After the task is created, the application server 1 can transfer the scanning task to the scanning engine server 2. The task scheduling engine allocates tasks according to the scanning task priority and the scanning engine server status, and schedules the scanning engine server 2 to perform scanning. When the scanning engine server 2 is not idle, the task scheduling engine periodically checks the status of the scanning engine server and initiates scanning when it is idle.

[0071] The management and analysis layer is used to provide administrators with system management and report analysis functions, such as the management of scanning rules, and system-dimensional and department-dimensional scanning result report analysis related functions.

[0072] In a specific example, the scanning process of the application server 1 may include:

[0073] (1) The user initiates a scanning task on the presentation layer page and starts scanning.

[0074] (2) The background application layer creates a scan task, adds it to the scan task list, and displays it to the user through the page of the presentation layer.

[0075] (3) The application layer obtains the relevant files of the Mybatis framework application to be scanned, including the code files of the calling program corresponding to the SQL configuration file. The code can be obtained by uploading files or connecting to the git code repository, or the user can add steps in the production pipeline in the development platform, and automatically transfer the code to the application server 1 when the pipeline is built. The application server 1 can add the relevant files of the Mybatis framework application to the scanning task and transmit them to the scanning engine server 2.

[0076] It is understandable that the application server 1 can add the acquisition information of the Mybatis framework application to the scanning task, and the scanning engine server 2 scans and downloads the relevant files of the Mybatis framework application according to the acquisition information. The present invention does not limit the acquisition method of the relevant files of the Mybatis framework application.

[0077] (4) Scanning scheduling. After the scanning task is created, the scheduling engine checks whether there are idle scanning engine servers and whether there are any unexecuted scanning tasks. If there are idle scanning engine servers and no unexecuted scanning tasks, the idle servers are notified to perform the scanning task analysis. If not, the scanning task is included in the list of tasks to be scanned, and the scanning engine initiates scanning scheduling every 5 minutes. In actual applications, the scheduling of scanning tasks can also adopt other scheduling methods, which are not limited by the present invention.

[0078] (5) The SQL scanning engine server 2 performs an anomaly detection on the Mybatis framework application. After the detection is completed and a report is generated, the application server 1 is notified that the scanning is completed. The application server 1 sets the scanning engine server 2 to an idle state.

[0079] (6) Result processing. This step mainly imports the anomaly detection results into the anomaly detection result table of the database and performs false alarm filtering. The anomaly detection result table includes a task information table and a problem detail table, which store problem summary data and problem detail data respectively. Parse the XML format scanning result report and store the scanning situation overview and problem summary information into the task information table in the database. The problem detail table has the system ID and the problem unique identifier as the joint primary key. This table stores the problem details and false alarm marking information. Read the problem details in the report and insert the problem data into the problem detail table. If the system already has a problem with this unique identifier, the insertion will fail due to the primary key conflict, and the marking status of the problem will also be retained. If a system ID and a problem unique identifier already exist, and the marking status is a false alarm, the problem does not need to be displayed again and is removed from the final result, thus achieving problem filtering. After all problems are stored in the database, count the non-false alarm problems and update the number of high, medium, and low risk problems and the total number of problems in the task information table. At this time, opening the problem list on the page will display all filtered problems.

[0080] The following takes the scanning engine server 2 as an example to illustrate the implementation process of the Mybatis framework SQL statement anomaly detection method provided by the embodiment of the present invention. It is understandable that the execution subject of the Mybatis framework SQL statement anomaly detection method provided by the embodiment of the present invention includes but is not limited to the scanning engine server 2.

[0081] According to one aspect of the present invention, this embodiment discloses a Mybatis framework SQL statement anomaly detection method. Figure 2 As shown, in this embodiment, the method includes:

[0082] S100: Parse the SQL configuration file of the Mybatis framework application to obtain SQL statements.

[0083] S200: performing anomaly detection on the SQL statement by at least one preset scanning rule, specifically comprising: determining whether it is necessary to scan the calling program corresponding to the SQL statement according to the preset scanning rule, and if so, performing anomaly detection on the SQL statement and the calling program according to the preset scanning rule to obtain an anomaly detection result of the calling program, and if not, performing anomaly detection on the SQL statement according to the preset scanning rule to obtain an anomaly detection result of the SQL statement;

[0084] S300: If the abnormality detection result indicates that there is a problem, the abnormality detection result is fed back to the user so that the user can modify the application.

[0085] The Mybatis framework SQL statement anomaly detection method of the present invention parses the SQL configuration file of the Mybatis framework application to obtain SQL statements, and performs anomaly detection on the SQL statements through at least one preset scanning rule, specifically including: determining whether it is necessary to scan the calling program corresponding to the SQL statement according to the preset scanning rule, if so, performing anomaly detection on the SQL statement and the calling program according to the preset scanning rule to obtain the anomaly detection result of the calling program, if not, performing anomaly detection on the SQL statement according to the preset scanning rule to obtain the anomaly detection result of the SQL statement, if the anomaly detection result is a problem, the anomaly detection result is fed back to the user so that the user can modify the application. It can be seen that the present invention is based on the characteristics of the Mybatis framework, and the SQL configuration file of the Mybatis framework application in the development stage is parsed to obtain SQL statements, and the SQL statements are anomaly detected by preset scanning rules. In order to determine whether there will be problems with the execution of SQL statements when the Mybatis framework application is running, it can be determined whether the execution of the SQL statement of the anomaly detection is related to its calling program according to the rule content of the preset scanning rule, and if it is related, the calling program of the SQL statement is further anomaly detected to obtain the anomaly detection result. Therefore, in order to improve the problem location capability, the present invention performs SQL statement anomaly detection on the SQL configuration file and the corresponding calling program through preset scanning rules during the development process, moves the work of SQL statement anomaly detection forward to the development stage, performs standardization and security scans on the SQL statements in the submitted code files, analyzes the static code in the development stage, achieves the effect of running SQL statement quality detection, can timely and comprehensively discover potential problems of SQL statements, and improves the efficiency and security of SQL execution.

[0086] In a preferred embodiment, Figure 3 As shown, the S100 parses the SQL configuration file of the Mybatis framework application to obtain the SQL statements including:

[0087] S110: Parse the XML mapping file as the SQL configuration file according to the Mybatis parsing rules to obtain SQL statements.

[0088] Specifically, it can be understood that in the Mybatis framework, the SQL configuration file is usually an XML mapping file in the XML file format, in which the MappedStatement object formed by the SQL configuration information is stored, and the MappedStatement object may include information such as the incoming parameter mapping configuration, the executed SQL statement, and the result mapping configuration. The corresponding SQL statement can be obtained by parsing the MappedStatement object according to the mapping rules of the MappedStatement object.

[0089] In the XML mapping file, different types of SQL statements that implement different functions need to be configured and identified using different XML tags. These XML tags provide many attributes, that is, different types of XML tags are preset and correspond to MappedStatement objects. MappedStatement objects can be SQL statements, and XML tags can define the execution behavior of each SQL statement. Therefore, in this preferred embodiment, the SQL configuration file is an XML mapping file, and the Mybatis parsing rules include the correspondence between the XML tags and the types of SQL statements, parse the XML tags in the SQL configuration file, and determine whether there is a corresponding SQL statement by identifying the XML tags.

[0090] In a preferred embodiment, Figure 4 As shown, the S200 performs anomaly detection on the SQL statement and the calling program according to the preset scanning rule to obtain anomaly detection results, which may specifically include:

[0091] S210: Determine a calling function in the calling program that calls the SQL statement according to the SQL identifier of the SQL statement.

[0092] S220: Determine a calling function rule corresponding to the SQL statement in the preset scanning rule.

[0093] S230: Performing anomaly detection on the calling function according to the calling function rule to obtain an anomaly detection result of the calling program.

[0094] Specifically, the program code of the Mybatis framework includes two types of files, one is the XML mapping file, and the other is the calling function that calls SQL. The calling function can be a JAVA API method, such as selectOne, selectList, insert, delete, update and other methods in SQLSession.

[0095] In the process of performing SQL statement anomaly detection on the program code of the Mybatis framework, the SQL statements in the XML mapping file are analyzed one by one according to the preset scanning rules. Among them, when the application is running, after receiving the call request, the application parses the SQL ID and the incoming object, and then parses the XML mapping file by calling the function to obtain the final executable SQL statement and sends it to the database for processing. Therefore, the statement quality of the executable SQL statement finally obtained is not only related to the SQL statement as the MappedStatement object in the XML mapping file, but also to the calling function of the SQL ID. Therefore, in this preferred embodiment, the preset scanning rules include calling function rules, and the corresponding calling function can be determined by the SQL ID in the XML mapping file, and then the calling function is detected by the calling function rules, which can achieve the purpose of running state detection of SQL statements.

[0096] Specifically, some preset scanning rules are only related to SQL statements, and it is only necessary to detect the SQL statements parsed from the SQL configuration file. In this case, it is necessary to perform anomaly detection on the SQL statements according to the preset scanning rules to obtain anomaly detection results of the SQL statements. Another part of the preset scanning rules is only related to the calling functions of the SQL statements, and it is only necessary to detect the calling functions of the SQL statements. In this case, it is necessary to perform anomaly detection on the calling functions of the SQL statements according to the preset scanning rules to obtain anomaly detection results of the calling functions. Other preset scanning rules are related to both SQL statements and their calling functions, and on the basis of detecting the SQL statements, it is necessary to further detect their calling functions.

[0097] In a specific embodiment, the preset scanning rule does not need to scan the calling program corresponding to the SQL statement. When the preset scanning rule is a SQL injection rule, it is necessary to detect whether there is a "$" in the SQL statement in the XML mapping file. If this symbol is present, the SQL has not been preprocessed and variable binding cannot be performed. The attacker can splice harmful SQL statements in the variables, causing SQL injection attacks. Therefore, if the "$" symbol does not exist in the SQL statement of the XML mapping file, the abnormality detection result of the SQL statement is that there is an abnormality, that is, there is a problem. The SQL injection rule does not need to further detect the JAVA API calling method (calling function), that is, there is no need to detect the JAVAAPI method.

[0098] In another specific embodiment, the preset scanning rule needs to scan the calling program corresponding to the SQL statement. The calling function that needs to be detected can be determined based on the SQL ID of the SQL statement. In a specific example, the calling function is a JAVAAPI method, and then the calling function rule detects the JAVA API method to obtain the abnormal detection result of the calling program. The calling function rule included in the preset scanning rule is a no-query condition rule. Specifically, if the where statement of the calling function does not have a query condition, the entire table will be scanned, the SQL execution efficiency is low, the query result set is large, and it is easy to cause memory overflow. The no-query condition rule mainly analyzes whether there are preset characters or strings such as "=" and "like" in the where substatement (query condition). If not, the abnormal detection result of the calling program is that there is a problem.

[0099] In a preferred embodiment, Figure 5 As shown, the preset scanning rule further includes an SQL statement rule, and S200 further includes:

[0100] S240: Perform anomaly detection on the SQL statement according to the SQL statement rule to obtain an anomaly detection result of the SQL statement.

[0101] Specifically, the preset scanning rules may include a call function rule and an SQL statement rule. When performing SQL statement scanning, since the preset scanning rules include a call function rule, the call function of the SQL statement is detected. In this preferred embodiment, the preset scanning rules further include an SQL statement rule, and it is necessary to further detect the SQL statement according to the SQL statement rule in the preset scanning rules to obtain an abnormal detection result of the SQL statement.

[0102] For example, in a specific example, the preset scanning rule is a result set range rule. According to the result set range rule, it is determined that the corresponding JAVA API method needs to be detected, and it is determined whether the SQL statement in the JAVA API method is a query list statement. If so, an abnormality detection result of the SQL statement calling function abnormality is obtained. According to the result set range rule, an abnormality detection is performed on the SQL statement to determine whether the SQL statement has a query result restriction condition. If not, an abnormality detection result of the SQL statement abnormality is obtained.

[0103] Specifically, when the preset scanning rule is a result set range rule, that is, the query result set is too large, the rule mainly targets the SQL query statement to determine whether it has a query result restriction condition of "limit". If there is no limit restriction on the query result, an abnormal detection result of the SQL statement calling the function abnormality is obtained. The result set range rule needs to further detect the JAVAAPI calling method, and the JAVAAPI method is matched according to the preset scanning rule to obtain the abnormal detection result, that is, the SQL statement called in the JAVA API method is a query list of select List (query list, not a single query API), then there is a problem with the statement, which may cause a risk of memory overflow due to the excessive size of the query result set. Among them, the SQL ID is added to the namespace of the XML mapping file, and the SQL ID of the query statement is the select id attribute value, then the SQL statement can be identified in the source code file of a project, and the calling code can be identified by matching the SQL ID in the calling API in the JAVA code.

[0104] In a preferred embodiment, Figure 6 As shown, the method further includes S400:

[0105] S410: If the abnormal detection result shows that there is a problem, a unique identifier for each problem in the abnormal detection result is generated.

[0106] S420: Form an abnormality detection result table according to the unique identifier, the corresponding preset scanning rule and the relevant information of the problem.

[0107] It is understandable that, according to whether there is a statement abnormality problem in the abnormality detection result, an abnormality detection result table of SQL statements can be generated to feedback the abnormality detection results of the application SQL statements to developers and other users. When the abnormality detection result is a problem, it means that there is a problem in at least one of the XML mapping files and JAVA API methods of the Mybatis framework, which will cause operation errors or low efficiency when the API method is called externally. It is necessary to form an abnormality detection result table to feedback to the developer, so that the developer can correct the problems in the SQL statement in time according to the abnormality detection result table, and improve the efficiency and robustness of the SQL statement.

[0108] Specifically, the scan result table generated after SQL statement anomaly detection is mainly used to record the overview of the scan situation, the summary information of the statement anomaly problem, and the problem details. The scanning engine server running the scanning task can generate a scan result report in the form of a file. In order to facilitate the program analysis report to form an anomaly detection result table, it is preferred to generate a report in XML format. Among them, the scan situation overview recorded in the scan result report mainly includes information such as the name of the scan analysis task, the scan time, the scan duration, the total number of scanned files, and the total number of scanned code lines. The problem summary information may include the total number of problems in the SQL statement anomaly detection results, the number of high-risk problems, the number of medium-risk problems, the number of low-risk problems, and the number of problems corresponding to each preset scanning rule. The problem details include the preset scanning rule ID, the problem unique identifier, the problem danger level, the file name where the problem is located, the path of the file where the problem is located, the statement details of the problem SQL, and the caller abbreviated code.

[0109] Further, a scan anomaly detection result table is generated according to the scan result report. Specifically, the scan anomaly detection result table is generated according to the scan result report mainly by importing the relevant information of the scan obtained by parsing the result report into a table in the database, and performing false alarm filtering. A task information table and a problem detail table can be generated to store problem summary data and problem detail data respectively. The scan result report in XML format is parsed, and the scan situation overview and problem summary information are stored in the task information table in the database. The problem detail table uses the system ID and the problem ID as the joint primary key, and the table stores the detailed information of the problem and the false alarm marking information. Read the problem details in the report, insert the problem data into the problem detail table, if the system already has a problem with this ID, the insertion will fail due to the primary key conflict, and the marking status of the problem will also be retained. If a system ID and a problem ID already exist, and the marking status is a false alarm, the problem does not need to be displayed again, and is eliminated in the final result, that is, the filtering processing of the problem is achieved. After all the problems are stored in the database, the non-false positive problems are counted, and the number of high-, medium-, and low-risk problems and the total number of problems in the task information table are updated. Then, all the filtered problems can be displayed, that is, the abnormal situations of all the filtered SQL statements can be displayed.

[0110] Specifically, since the actual situation of SQL statement writing is ever-changing and the actual usage scenarios are also diverse, the scanning analysis will inevitably be inconsistent with the actual situation and there will be false positives. Therefore, after the scanning is completed, the SQL statement scanning application platform will carry out a problem audit process. The audit process can be implemented through the following steps: the developer checks the details of the anomaly detection result. If the anomaly detection result is a statement anomaly, the anomaly detection result is marked. If the analysis is a false positive, it is marked as a false positive. The audit reviewer reviews and confirms the developer's mark. If the audit review confirms that it is a false positive, the anomaly detection result is set as a false positive and recorded or updated as the problem summary information in the scanning task. In the next scan, according to the marking status of the problem, if the anomaly detection result that is the same as the anomaly detection result marked as a false positive appears, the anomaly detection result will no longer be fed back to the developer, so that the false positive problem can be filtered, and the problematic SQL statement can be extracted more accurately.

[0111] In a preferred embodiment, Figure 7 As shown, S410 forming a unique identifier for each problem in the abnormal detection result may specifically include:

[0112] S411: The unique identifier is formed according to the SQL ID of the problematic SQL statement and the namespace of the SQL configuration file.

[0113] It is understandable that in order to facilitate the analysis and audit of problems and to perform differential analysis of multiple versions of program codes, in this preferred embodiment, the problematic SQL statements in the matching results can be uniquely identified to prevent repeated errors of SQL statements with the same SQLID. Preferably, the global SQL ID of the XML mapping file mapper namespace plus the SQLID can be used as the unique identifier of the problem. By forming this unique identifier, when the directory structure of the application code file changes, adding or deleting code in the code file will not cause a change in the unique identifier, and scanning of different code versions can also uniquely locate the problem, avoiding repeated analysis of the same problem during the audit process.

[0114] In a preferred embodiment, Figure 8 As shown, the method further includes S500:

[0115] S510: Perform SQL statement anomaly detection on the Mybatis framework application after the version update to obtain an update anomaly detection result.

[0116] S520: If there is a problem with the update anomaly detection result, a unique identifier of the SQL statement in the update anomaly detection result is formed.

[0117] S530: Check whether there is a corresponding unique identifier in the anomaly detection result table. If so, add the unique identifier, the corresponding preset scanning rule, and relevant information of the problem in the updated anomaly detection result to the anomaly detection result table. If not, add the unique identifier, the corresponding preset scanning rule, and relevant information of the problem to the anomaly detection result table.

[0118] It is understandable that the developer can modify the current Mybatis framework application to form a new version of the application. Then, the SQL statement anomaly detection of the updated Mybatis framework application can obtain a new anomaly detection result, that is, an updated anomaly detection result. Similarly, if there is a problem with the updated anomaly detection result, a unique identifier of the SQL statement in the updated anomaly detection result is formed. According to the unique identifier, find out whether there is a corresponding unique identifier in the anomaly detection result table formed during the previous scanning task. If so, find out whether there is a corresponding unique identifier in the anomaly detection result table. If so, add the unique identifier, the corresponding preset scanning rules and the relevant information of the problem in the updated anomaly detection result to the anomaly detection result table. Only the problem information with the same unique identifier in the anomaly detection result table is updated, and the abnormal problems with the same unique identifier SQL ID are not recorded repeatedly, so as to facilitate the audit of the anomaly detection results.

[0119] More preferably, if there is a corresponding unique identifier in the abnormal detection result table, the abnormal detection result can be further compared with the relevant information of the problem corresponding to the unique identifier in the abnormal detection result table. If they are different, the relevant information of the problem corresponding to the unique identifier in the abnormal detection result table is updated. If they are the same, no operation can be performed to reduce the number of repeated writes.

[0120] In the prior art, SQL statement quality detection is mainly carried out during the testing phase, when the program is running, which is a relatively late opportunity. Developers also need to correspond the SQL execution problems found during the test process to the program code, which is a large workload, high repair cost, and lacks the automation, timeliness and comprehensiveness of performance problem discovery. Commonly used code scanning technologies are based on grammatical analysis, semantic analysis, control flow analysis, data flow analysis and other technologies, which are difficult to implement, difficult to customize detection rules, high resource consumption and low detection efficiency. The present invention only needs to parse the Mybatis sql mapper mapping file according to the XML rules, and perform regular matching on the call API in the JAVA code, which has low technical implementation difficulty, low detection resource consumption and high detection efficiency. The main advantages of the present invention are that the SQL statement quality in the source code developed based on the Mybatis framework can be checked in the development phase, the check rules can be customized, and the SQL statements with problems can be automatically scanned and analyzed online in one stop, with high detection efficiency, and false positive audit can be performed online to improve the accuracy of the check.

[0121] Based on the same principle, this embodiment also discloses a scanning engine server. Fig. 9 As shown, the scanning engine server includes a code parsing module 11, an anomaly detection module 12 and an information feedback module 13.

[0122] Wherein, the code parsing module 11 is used to parse the SQL configuration file of the Mybatis framework application to obtain SQL statements.

[0123] The anomaly detection module 12 is used to perform anomaly detection on the SQL statement through at least one preset scanning rule, specifically including: determining whether it is necessary to scan the calling program corresponding to the SQL statement according to the preset scanning rule; if so, performing anomaly detection on the SQL statement and the calling program according to the preset scanning rule to obtain an anomaly detection result of the calling program; if not, performing anomaly detection on the SQL statement according to the preset scanning rule to obtain an anomaly detection result of the SQL statement.

[0124] The information feedback module 13 is used for feeding back the abnormality detection result to the user if the abnormality detection result indicates that there is a problem so that the user can modify the application.

[0125] The present invention is based on the characteristics of the Mybatis framework, and the SQL configuration file of the Mybatis framework application in the development stage is parsed to obtain SQL statements, and the SQL statements are subjected to abnormal detection through preset scanning rules. In order to determine whether there will be problems in the execution of SQL statements when the Mybatis framework application is running, it can be determined whether there is a problem in the execution of the SQL statements of the abnormal detection and whether it is related to its calling program according to the rule content of the preset scanning rules. If it is related, the calling program of the SQL statement is further subjected to abnormal detection to obtain the abnormal detection result. If the abnormal detection result is that there is a problem, the abnormal detection result is fed back to the user so that the user can modify the application. Thus, in order to improve the problem location capability, the present invention performs SQL statement abnormal detection on the SQL configuration file and the corresponding calling program through preset scanning rules during the development process, moves the work of SQL statement abnormal detection forward to the development stage, performs standardization and security scanning on the SQL statements in the submitted code files, analyzes the static code in the development stage, achieves the effect of running state SQL statement quality detection, can timely and comprehensively discover SQL statement potential problems, and improves the efficiency and security of SQL execution.

[0126] In a preferred embodiment, the code parsing module 11 is specifically used to parse the XML mapping file as the SQL configuration file according to the Mybatis parsing rules to obtain the SQL statement.

[0127] Specifically, it can be understood that in the Mybatis framework, the SQL configuration file is usually an XML mapping file in the XML file format, in which the MappedStatement object formed by the SQL configuration information is stored, and the MappedStatement object may include information such as the incoming parameter mapping configuration, the executed SQL statement, and the result mapping configuration. The corresponding SQL statement can be obtained by parsing the MappedStatement object according to the mapping rules of the MappedStatement object.

[0128] In the XML mapping file, different types of SQL statements that implement different functions need to be configured and identified using different XML tags. These XML tags provide many attributes, that is, different types of XML tags are preset and correspond to MappedStatement objects. MappedStatement objects can be SQL statements, and XML tags can define the execution behavior of each SQL statement. Therefore, in this preferred embodiment, the SQL configuration file is an XML mapping file, and the Mybatis parsing rules include the correspondence between the XML tags and the types of SQL statements, parse the XML tags in the SQL configuration file, and determine whether there is a corresponding SQL statement by identifying the XML tags.

[0129] In a preferred embodiment, the anomaly detection module 12 can be specifically used to determine the calling function that calls the SQL statement in the calling program according to the SQL identifier of the SQL statement, determine the calling function rule corresponding to the SQL statement in the preset scanning rule, and perform anomaly detection on the calling function according to the calling function rule to obtain an anomaly detection result of the calling program.

[0130] Specifically, the program code of the Mybatis framework includes two types of files, one is the XML mapping file, and the other is the calling function that calls SQL. The calling function can be a JAVA API method, such as selectOne, selectList, insert, delete, update and other methods in SQLSession.

[0131] In the process of performing SQL statement anomaly detection on the program code of the Mybatis framework, the SQL statements in the XML mapping file are analyzed one by one according to the preset scanning rules. Among them, when the application is running, after receiving the call request, the application parses the SQL ID and the incoming object, and then parses the XML mapping file by calling the function to obtain the final executable SQL statement and sends it to the database for processing. Therefore, the statement quality of the executable SQL statement finally obtained is not only related to the SQL statement as the MappedStatement object in the XML mapping file, but also to the calling function of the SQL ID. Therefore, in this preferred embodiment, the preset scanning rules include calling function rules, and the corresponding calling function can be determined by the SQL ID in the XML mapping file, and then the calling function is detected by the calling function rules, which can achieve the purpose of running state detection of SQL statements.

[0132] Specifically, some preset scanning rules are only related to SQL statements, and it is only necessary to detect the SQL statements parsed from the SQL configuration file. In this case, it is necessary to perform anomaly detection on the SQL statements according to the preset scanning rules to obtain anomaly detection results of the SQL statements. Another part of the preset scanning rules is only related to the calling functions of the SQL statements, and it is only necessary to detect the calling functions of the SQL statements. In this case, it is necessary to perform anomaly detection on the calling functions of the SQL statements according to the preset scanning rules to obtain anomaly detection results of the calling functions. Other preset scanning rules are related to both SQL statements and their calling functions, and on the basis of detecting the SQL statements, it is necessary to further detect their calling functions.

[0133] In a specific embodiment, the preset scanning rule does not need to scan the calling program corresponding to the SQL statement. When the preset scanning rule is a SQL injection rule, it is necessary to detect whether there is a "$" in the SQL statement in the XML mapping file. If this symbol is present, the SQL is not preprocessed and variable binding cannot be performed. The attacker can splice harmful SQL statements in the variables, causing SQL injection attacks. Therefore, if there is no "$" symbol in the SQL statement of the XML mapping file, the abnormality detection result of the SQL statement is that there is an abnormality and a problem. The SQL injection rule does not need to further detect the JAVAAPI calling method (calling function), that is, there is no need to detect the JAVA API method.

[0134] In another specific embodiment, the preset scanning rule needs to scan the calling program corresponding to the SQL statement. The calling function that needs to be detected can be determined based on the SQL ID of the SQL statement. In a specific example, the calling function is a JAVA API method, and then the calling function rule detects the JAVA API method to obtain the abnormal detection result of the calling program. The calling function rule included in the preset scanning rule is a no-query condition rule. Specifically, if the where statement of the calling function does not have a query condition, the entire table will be scanned, the SQL execution efficiency is low, the query result set is large, and it is easy to cause memory overflow. The no-query condition rule mainly analyzes whether there are preset characters or strings such as "=" and "like" in the where substatement (query condition). If not, the abnormal detection result of the calling program is that there is a problem.

[0135] In a preferred embodiment, the preset scanning rules further include SQL statement rules, and the anomaly detection module 12 is further configured to perform anomaly detection on the SQL statement according to the SQL statement rules to obtain an anomaly detection result of the SQL statement.

[0136] Specifically, the preset scanning rules may include a call function rule and an SQL statement rule. When performing SQL statement scanning, since the preset scanning rules include a call function rule, the call function of the SQL statement is detected. In this preferred embodiment, the preset scanning rules further include an SQL statement rule, and it is necessary to further detect the SQL statement according to the SQL statement rule in the preset scanning rules to obtain an abnormal detection result of the SQL statement.

[0137] For example, in a specific example, the preset scanning rule is a result set range rule. According to the result set range rule, it is determined that the corresponding JAVA API method needs to be detected, and it is determined whether the SQL statement in the JAVA API method is a query list statement. If so, an abnormality detection result of the SQL statement calling function abnormality is obtained. According to the result set range rule, an abnormality detection is performed on the SQL statement to determine whether the SQL statement has a query result restriction condition. If not, an abnormality detection result of the SQL statement abnormality is obtained.

[0138] Specifically, when the preset scanning rule is a result set range rule, that is, the query result set is too large, the rule mainly targets the SQL query statement to determine whether it has a query result restriction condition of "limit". If there is no limit restriction on the query result, an abnormal detection result of the SQL statement calling the function abnormality is obtained. The result set range rule needs to further detect the JAVA API calling method, and the JAVA API method is matched according to the preset scanning rule to obtain the abnormal detection result, that is, the SQL statement called in the JAVA API method is a query list of select List (query list, not a single query API), then there is a problem with the statement, which may cause a risk of memory overflow due to the query result set being too large. Among them, the SQL ID is added to the namespace of the XML mapping file, and the SQL ID of the query statement is the select id attribute value, then the SQL statement can be identified in the source code file of a project, and the calling code can be identified by matching the SQL ID in the calling API in the JAVA code.

[0139] In a preferred embodiment, Fig.10 As shown, the system further includes a data processing module 14. The data processing module 14 is used to form a unique identifier for each problem in the abnormal detection result if the abnormal detection result is a problem. An abnormal detection result table is formed according to the unique identifier, the corresponding preset scanning rule and the relevant information of the problem.

[0140] It should be noted that the data processing module 14 may be arranged in the application server 1 or in the scanning engine server 2 , and is preferably arranged in the application server 1 .

[0141] It is understandable that, according to whether there is a statement abnormality problem in the abnormality detection result, an abnormality detection result table of SQL statements can be generated to feedback the abnormality detection results of the application SQL statements to developers and other users. When there is a problem with the abnormality detection result, it means that there is a problem with at least one of the XML mapping files and JAVA API methods of the Mybatis framework, which will cause operation errors or low efficiency when the API method is called externally. It is necessary to form an abnormality detection result table to feedback to the developer, so that the developer can correct the problems in the SQL statement in time according to the abnormality detection result table, and improve the efficiency and robustness of the SQL statement.

[0142] Specifically, the scan result table generated after SQL statement anomaly detection is mainly used to record the overview of the scan situation, the summary information of the statement anomaly problem, and the problem details. The scanning engine server running the scanning task can generate a scan result report in the form of a file. In order to facilitate the program analysis report to form an anomaly detection result table, it is preferred to generate a report in XML format. Among them, the scan situation overview recorded in the scan result report mainly includes information such as the name of the scan analysis task, the scan time, the scan duration, the total number of scanned files, and the total number of scanned code lines. The problem summary information may include the total number of problems in the SQL statement anomaly detection results, the number of high-risk problems, the number of medium-risk problems, the number of low-risk problems, and the number of problems corresponding to each preset scanning rule. The problem details include the preset scanning rule ID, the problem unique identifier, the problem danger level, the file name where the problem is located, the path of the file where the problem is located, the statement details of the problem SQL, and the caller abbreviated code.

[0143] Further, a scan anomaly detection result table is generated according to the scan result report. Specifically, the scan anomaly detection result table is generated according to the scan result report mainly by importing the relevant information of the scan obtained by parsing the result report into a table in the database, and performing false alarm filtering. A task information table and a problem detail table can be generated to store problem summary data and problem detail data respectively. The scan result report in XML format is parsed, and the scan situation overview and problem summary information are stored in the task information table in the database. The problem detail table uses the system ID and the problem ID as the joint primary key, and the table stores the detailed information of the problem and the false alarm marking information. Read the problem details in the report, insert the problem data into the problem detail table, if the system already has a problem with this ID, the insertion will fail due to the primary key conflict, and the marking status of the problem will also be retained. If a system ID and a problem ID already exist, and the marking status is a false alarm, the problem does not need to be displayed again, and is eliminated in the final result, that is, the filtering processing of the problem is achieved. After all the problems are stored in the database, the non-false positive problems are counted, and the number of high-, medium-, and low-risk problems and the total number of problems in the task information table are updated. Then, all the filtered problems can be displayed, that is, the abnormal situations of all the filtered SQL statements can be displayed.

[0144] Specifically, since the actual situation of SQL statement writing is ever-changing and the actual usage scenarios are also diverse, the scanning analysis will inevitably be inconsistent with the actual situation and there will be false positives. Therefore, after the scanning is completed, the SQL statement scanning application platform will carry out a problem audit process. The audit process can be implemented through the following steps: the developer checks the details of the anomaly detection result. If the anomaly detection result is a statement anomaly, the anomaly detection result is marked. If the analysis is a false positive, it is marked as a false positive. The audit reviewer reviews and confirms the developer's mark. If the audit review confirms that it is a false positive, the anomaly detection result is set as a false positive and recorded or updated as the problem summary information in the scanning task. In the next scan, according to the marking status of the problem, if the anomaly detection result that is the same as the anomaly detection result marked as a false positive appears, the anomaly detection result will no longer be fed back to the developer, so that the false positive problem can be filtered, and the problematic SQL statement can be extracted more accurately.

[0145] In a preferred embodiment, the data processing module 14 can be specifically configured to form the unique identifier according to the SQLID of the problematic SQL statement and the namespace of the SQL configuration file.

[0146] It is understandable that in order to facilitate the analysis and audit of problems and to perform differential analysis of multiple versions of program codes, in this preferred embodiment, the problematic SQL statements in the matching results can be uniquely identified to prevent repeated errors of SQL statements with the same SQLID. Preferably, the global SQL ID of the XML mapping file mapper namespace plus the SQLID can be used as the unique identifier of the problem. By forming this unique identifier, when the directory structure of the application code file changes, adding or deleting code in the code file will not cause a change in the unique identifier, and scanning of different code versions can also uniquely locate the problem, avoiding repeated analysis of the same problem during the audit process.

[0147] In a preferred embodiment, the anomaly detection module 12 further performs SQL statement anomaly detection on the Mybatis framework application after the version update to obtain an update anomaly detection result. The data processing module 14 is used to form a unique identifier of the SQL statement in the update anomaly detection result if there is a problem with the update anomaly detection result. Check whether there is a corresponding unique identifier in the anomaly detection result table. If so, add the unique identifier, the corresponding preset scanning rule, and the relevant information of the problem in the update anomaly detection result to the anomaly detection result table. If not, add the unique identifier, the corresponding preset scanning rule, and the relevant information of the problem to the anomaly detection result table.

[0148] It is understandable that the developer can modify the current Mybatis framework application to form a new version of the application. Then, the SQL statement anomaly detection of the updated Mybatis framework application can obtain a new anomaly detection result, that is, an updated anomaly detection result. Similarly, if there is a problem with the updated anomaly detection result, a unique identifier of the SQL statement in the updated anomaly detection result is formed. According to the unique identifier, find out whether there is a corresponding unique identifier in the anomaly detection result table formed during the previous scanning task. If so, find out whether there is a corresponding unique identifier in the anomaly detection result table. If so, add the unique identifier, the corresponding preset scanning rules and the relevant information of the problem in the updated anomaly detection result to the anomaly detection result table. Only the problem information with the same unique identifier in the anomaly detection result table is updated, and the abnormal problems with the same unique identifier SQL ID are not recorded repeatedly, so as to facilitate the audit of the anomaly detection results.

[0149] More preferably, if there is a corresponding unique identifier in the abnormal detection result table, the abnormal detection result can be further compared with the relevant information of the problem corresponding to the unique identifier in the abnormal detection result table. If they are different, the relevant information of the problem corresponding to the unique identifier in the abnormal detection result table is updated. If they are the same, no operation can be performed to reduce the number of repeated writes.

[0150] In the prior art, SQL statement quality detection is mainly carried out during the testing phase, when the program is running, which is a relatively late opportunity. Developers also need to correspond the SQL execution problems found during the test process to the program code, which is a large workload, high repair cost, and lacks the automation, timeliness and comprehensiveness of performance problem discovery. Commonly used code scanning technologies are based on grammatical analysis, semantic analysis, control flow analysis, data flow analysis and other technologies, which are difficult to implement, difficult to customize detection rules, high resource consumption and low detection efficiency. The present invention only needs to parse the Mybatis sql mapper mapping file according to the XML rules, and perform regular matching on the call API in the JAVA code, which has low technical implementation difficulty, low detection resource consumption and high detection efficiency. The main advantages of the present invention are that the SQL statement quality in the source code developed based on the Mybatis framework can be checked in the development phase, the check rules can be customized, and the SQL statements with problems can be automatically scanned and analyzed online in one stop, with high detection efficiency, and false positive audit can be performed online to improve the accuracy of the check.

[0151] Since the principle of solving the problem by this server is similar to that of the above method, the implementation of this server can refer to the implementation of the method and will not be repeated here.

[0152] The systems, devices, modules or units described in the above embodiments may be implemented by computer chips or entities, or by products with certain functions. A typical implementation device is a computer device, and specifically, the computer device may be, for example, a personal computer, a laptop computer, a cellular phone, a camera phone, a smart phone, a personal digital assistant, a media player, a navigation device, an email device, a game console, a tablet computer, a wearable device, or a combination of any of these devices.

[0153] In a typical example, the computer device specifically includes a memory, a processor, and a computer program stored in the memory and executable on the processor. When the processor executes the program, the method executed by the client as described above is implemented; or, when the processor executes the program, the method executed by the server as described above is implemented.

[0154] Reference below Fig.11 , which shows a schematic diagram of the structure of a computer device 600 suitable for implementing an embodiment of the present application.

[0155] like Fig.11 As shown, the computer device 600 includes a central processing unit (CPU) 601, which can perform various appropriate operations and processes according to a program stored in a read-only memory (ROM) 602 or a program loaded from a storage part 608 to a random access memory (RAM) 603. In the RAM 603, various programs and data required for the operation of the system 600 are also stored. The CPU 601, the ROM 602, and the RAM 603 are connected to each other via a bus 604. An input / output (I / O) interface 605 is also connected to the bus 604.

[0156] The following components are connected to the I / O interface 605: an input section 606 including a keyboard, a mouse, etc.; an output section 607 including a cathode ray tube (CRT), a liquid crystal feedback device (LCD), etc., and a speaker, etc.; a storage section 608 including a hard disk, etc.; and a communication section 609 including a network interface card such as a LAN card, a modem, etc. The communication section 609 performs communication processing via a network such as the Internet. A drive 610 is also connected to the I / O interface 605 as needed. A removable medium 611, such as a magnetic disk, an optical disk, a magneto-optical disk, a semiconductor memory, etc., is installed on the drive 610 as needed, so that a computer program read therefrom is installed as needed as the storage section 608.

[0157] In particular, according to an embodiment of the present invention, the process described above with reference to the flowchart can be implemented as a computer software program. For example, an embodiment of the present invention includes a computer program product, which includes a computer program tangibly contained on a machine-readable medium, and the computer program includes program code for executing the method shown in the flowchart. In such an embodiment, the computer program can be downloaded and installed from a network through the communication part 609, and / or installed from the removable medium 611.

[0158] Computer readable media include permanent and non-permanent, removable and non-removable media that can be implemented by any method or technology to store information. 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 technology, compact disk read-only memory (CD-ROM), digital versatile disk (DVD) or other optical storage, magnetic cassettes, magnetic tape magnetic disk storage or other magnetic storage devices or any other non-transmission media that can be used to store information that can be accessed by a computing device. As defined herein, computer readable media does not include temporary computer readable media (transitory media), such as modulated data signals and carrier waves.

[0159] For the convenience of description, the above device is described in various units according to their functions. Of course, when implementing the present application, the functions of each unit can be implemented in the same or multiple software and / or hardware.

[0160] The present invention is described with reference to flowcharts and / or block diagrams of methods, devices (systems), and computer program products according to embodiments of the present invention. It should be understood that each process and / or block in the flowchart and / or block diagram, as well as the combination of processes and / or blocks in the flowchart and / or block diagram, can be implemented by computer program instructions. These computer program instructions can be provided to a processor of a general-purpose computer, a special-purpose computer, an embedded processor, or other programmable data processing device to produce a machine, so that the instructions executed by the processor of the computer or other programmable data processing device generate instructions for implementing the processes in the flowchart and / or block diagram. Figure 1 A process or multiple processes and / or boxes Figure 1 A device that provides the functions specified in a block or multiple blocks.

[0161] These computer program instructions may also be stored in a computer-readable memory capable of directing a computer or other programmable data processing device to operate in a specific manner, so that the instructions stored in the computer-readable memory produce an article of manufacture comprising an instruction device, which implements the process Figure 1 A process or multiple processes and / or boxes Figure 1 A function specified in one or more boxes.

[0162] These computer program instructions can also be loaded onto a computer or other programmable data processing device so that a series of operating steps are executed on the computer or other programmable device to produce a computer-implemented process, thereby providing instructions for implementing the process. Figure 1 A process or multiple processes and / or boxes Figure 1 The steps for the functions specified in one or more boxes.

[0163] It should also be noted that the terms "include", "comprises" or any other variations thereof are intended to cover non-exclusive inclusion, so that a process, method, commodity or device including a series of elements includes not only those elements, but also other elements not explicitly listed, or also includes elements inherent to such process, method, commodity or device. In the absence of more restrictions, the elements defined by the sentence "comprises a ..." do not exclude the existence of other identical elements in the process, method, commodity or device including the elements.

[0164] Those skilled in the art will appreciate that the embodiments of the present application may be provided as methods, systems or computer program products. Therefore, the present application may adopt the form of a complete hardware embodiment, a complete software embodiment or an embodiment in combination with software and hardware. Moreover, the present application may adopt the form of a computer program product implemented on one or more computer-usable storage media (including but not limited to disk storage, CD-ROM, optical storage, etc.) that contain computer-usable program code.

[0165] The present application may be described in the general context of computer-executable instructions executed by a computer, such as program modules. Generally, program modules include routines, programs, objects, components, data structures, etc. that perform specific tasks or implement specific abstract data types. The present application may also be practiced in distributed computing environments where tasks are performed by remote processing devices connected through a communication network. In a distributed computing environment, program modules may be located in local and remote computer storage media, including storage devices.

[0166] Each embodiment in this specification is described in a progressive manner, and the same or similar parts between the embodiments can be referred to each other, and each embodiment focuses on the differences from other embodiments. In particular, for the system embodiment, since it is basically similar to the method embodiment, the description is relatively simple, and the relevant parts can be referred to the partial description of the method embodiment.

[0167] The above is only an embodiment of the present application and is not intended to limit the present application. For those skilled in the art, the present application may have various changes and variations. Any modification, equivalent replacement, improvement, etc. made within the spirit and principle of the present application should be included in the scope of the claims of the present application.

Claims

1. A Mybatis framework SQL statement anomaly detection method, characterized in that: include: Parse the SQL configuration file of the Mybatis framework application to obtain SQL statements; Performing anomaly detection on the SQL statement by using at least one preset scanning rule specifically includes: determining whether it is necessary to scan the calling program corresponding to the SQL statement according to the preset scanning rule, and if so, performing anomaly detection on the SQL statement and the calling program according to the preset scanning rule to obtain an anomaly detection result of the calling program, and if not, performing anomaly detection on the SQL statement according to the preset scanning rule to obtain an anomaly detection result of the SQL statement; If the abnormal detection result indicates that there is a problem, feeding back the abnormal detection result to the user so that the user can modify the application; The performing anomaly detection on the SQL statement and the calling program according to the preset scanning rule to obtain an anomaly detection result specifically includes: Determine, according to the SQL identifier of the SQL statement, a calling function in the calling program that calls the SQL statement; Determine a calling function rule corresponding to the SQL statement in the preset scanning rule; Performing anomaly detection on the calling function according to the calling function rule to obtain an anomaly detection result of the calling program; Wherein, the preset scanning rule further includes an SQL statement rule, and the method further includes: Anomaly detection is performed on the SQL statement according to the SQL statement rule to obtain an anomaly detection result of the SQL statement.

2. The Mybatis framework SQL statement anomaly detection method according to claim 1, characterized in that: The SQL statement obtained by parsing the SQL configuration file of the Mybatis framework application specifically includes: The XML mapping file as the SQL configuration file is parsed according to the Mybatis parsing rules to obtain the SQL statement.

3. The Mybatis framework SQL statement anomaly detection method according to claim 1, characterized in that: Further including: If the abnormal detection result indicates that there is a problem, a unique identifier for each problem in the abnormal detection result is formed; An anomaly detection result table is formed according to the unique identifier, the corresponding preset scanning rule and the relevant information of the problem.

4. The Mybatis framework SQL statement anomaly detection method according to claim 3, characterized in that: The unique identifier of each problem in the anomaly detection result specifically includes: The unique identifier is formed based on the SQL ID of the problematic SQL statement and the namespace of the SQL configuration file.

5. The Mybatis framework SQL statement anomaly detection method according to claim 3, characterized in that: Further including: Perform SQL statement anomaly detection on the Mybatis framework application after the version update to obtain the update anomaly detection result; If there is a problem with the update anomaly detection result, a unique identifier of the SQL statement in the update anomaly detection result is formed; Check whether there is a corresponding unique identifier in the anomaly detection result table. If so, add the unique identifier, the corresponding preset scanning rule, and relevant information of the problem in the updated anomaly detection result to the anomaly detection result table. If not, add the unique identifier, the corresponding preset scanning rule, and relevant information of the problem to the anomaly detection result table.

6. A scanning engine server, characterized in that: include: Code parsing module, used to parse the SQL configuration file of the Mybatis framework application to obtain SQL statements; an anomaly detection module, configured to perform anomaly detection on the SQL statement through at least one preset scanning rule, specifically comprising: determining whether it is necessary to scan the calling program corresponding to the SQL statement according to the preset scanning rule, and if so, performing anomaly detection on the SQL statement and the calling program according to the preset scanning rule to obtain an anomaly detection result of the calling program; if not, performing anomaly detection on the SQL statement according to the preset scanning rule to obtain an anomaly detection result of the SQL statement; An information feedback module, for feeding back the abnormality detection result to the user if the abnormality detection result indicates that there is a problem so that the user can modify the application; The anomaly detection module is specifically used to determine the calling function that calls the SQL statement in the calling program according to the SQL identifier of the SQL statement; determine the calling function rule corresponding to the SQL statement in the preset scanning rule; perform anomaly detection on the calling function according to the calling function rule to obtain an anomaly detection result of the calling program; The preset scanning rules further include SQL statement rules, and the anomaly detection module is further used to perform anomaly detection on the SQL statement according to the SQL statement rules to obtain an anomaly detection result of the SQL statement.

7. The scanning engine server according to claim 6, characterized in that: The code parsing module is specifically used to parse the XML mapping file as the SQL configuration file according to the Mybatis parsing rules to obtain the SQL statement.

8. The scanning engine server according to claim 6, characterized in that: Further comprising a data processing module, for forming a unique identifier for each problem in the abnormal detection result if the abnormal detection result indicates that there is a problem; An anomaly detection result table is formed according to the unique identifier, the corresponding preset scanning rule and the relevant information of the problem.

9. The scanning engine server according to claim 8, characterized in that: The data processing module is specifically used to form the unique identifier according to the SQL ID of the problematic SQL statement and the namespace of the SQL configuration file.

10. The scanning engine server according to claim 8, characterized in that: The data processing module is further used to perform SQL statement anomaly detection on the Mybatis framework application after the version update to obtain an update anomaly detection result; if there is a problem with the update anomaly detection result, a unique identifier of the SQL statement in the update anomaly detection result is formed; Check whether there is a corresponding unique identifier in the anomaly detection result table. If so, add the unique identifier, the corresponding preset scanning rule, and relevant information of the problem in the updated anomaly detection result to the anomaly detection result table. If not, add the unique identifier, the corresponding preset scanning rule, and relevant information of the problem to the anomaly detection result table.

11. A Mybatis framework SQL statement anomaly detection system, characterized in that: Includes application server and scanning engine server; The application server is used to send a scanning task to the engine server; The scanning engine server is used to parse the SQL configuration file of the Mybatis framework application based on the scanning task to obtain an SQL statement, and perform anomaly detection on the SQL statement through at least one preset scanning rule, specifically including: determining whether it is necessary to scan the calling program corresponding to the SQL statement according to the preset scanning rule, if so, performing anomaly detection on the SQL statement and the calling program according to the preset scanning rule to obtain an anomaly detection result of the calling program, if not, performing anomaly detection on the SQL statement according to the preset scanning rule to obtain an anomaly detection result of the SQL statement, and if the anomaly detection result is a problem, feeding back the anomaly detection result to the user so that the user can modify the application; The anomaly detection module is specifically used to determine the calling function that calls the SQL statement in the calling program according to the SQL identifier of the SQL statement; determine the calling function rule corresponding to the SQL statement in the preset scanning rule; perform anomaly detection on the calling function according to the calling function rule to obtain an anomaly detection result of the calling program; The preset scanning rules further include SQL statement rules, and the anomaly detection module is further used to perform anomaly detection on the SQL statement according to the SQL statement rules to obtain an anomaly detection result of the SQL statement.

12. A computer program product comprising a computer program / instructions, characterized in that When the computer program / instructions are executed by a processor, the method according to any one of claims 1 to 5 is implemented.

13. A computer 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, the method according to any one of claims 1 to 5 is implemented.

14. A computer readable medium having a computer program stored thereon, characterized in that: When the program is executed by a processor, the method according to any one of claims 1 to 5 is implemented.

Citation Information

Patent Citations

  • Query statement boundary problem detection method, device, equipment and storage medium

    CN110851346A

  • Multi-source database statement checking method and device

    CN111949541A