Interface collection method, device and computer equipment

By automatically identifying interface classes and annotation information, and combining this with a request information database for permission verification, the problem of frequent interface permission configuration errors has been solved, achieving efficient and secure interface collection and detection.

CN115795496BActive Publication Date: 2026-11-27HANGZHOU DBAPPSECURITY CO LTD
View PDF 2 Cites 0 Cited by

Patent Information

Application Number
CN202211375151.6
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2022-11-04
Publication Date
2026-11-27
Estimated Expiration
2042-11-04

AI Technical Summary

Technical Problem

Existing technologies rely on introducing third-party interface documentation libraries and manually annotating each interface, which leads to frequent errors in interface permission configuration, low efficiency, and security risks.

Method used

By obtaining the code scanning results of the code to be detected, the interface class and its annotation information are identified, the initial interface access path is generated, and permission verification is performed in conjunction with the request information database. The interface is automatically collected and permission detection is performed.

Benefits of technology

It improves the efficiency of interface collection, reduces omissions, enhances data security, and avoids the workload of manual annotation and the security risks introduced by third-party libraries.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN115795496B_ABST
    Figure CN115795496B_ABST
Patent Text Reader

Abstract

The application relates to an interface collection method, device and computer equipment. The method comprises the following steps: obtaining a to-be-detected code and a code scanning result of the to-be-detected code; wherein the to-be-detected code comprises a to-be-collected interface; obtaining an interface class of the to-be-detected code and annotation information of the interface class according to the code scanning result, and obtaining an initial interface access path according to the annotation information; and generating an interface collection result of the to-be-collected interface according to the initial access path. The method can break away from the method of introducing a third-party interface document library and manually annotating the interface, so that the collection of the interface can be completed more safely and efficiently.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This application relates to the field of digital data processing technology, and in particular to an interface collection method, apparatus and computer equipment. Background Technology

[0002] In current enterprise product security self-testing, API permission verification is a crucial step. Normally, important APIs are restricted to users with specific permissions. However, commercial products typically have numerous APIs, and developers and users are widely distributed, making it easy for API permission configuration errors to occur, creating security vulnerabilities. These vulnerabilities can range from minor information leaks to serious malicious attacks that disrupt normal business operations. Traditionally, third-party API documentation libraries are used, with specific annotations added to each API. All annotated APIs are then collected to obtain all API paths. However, this traditional approach requires developers to annotate each API individually. This increases workload and increases the risk of omissions. Furthermore, using third-party API documentation libraries can introduce security risks and increase the probability of dependency conflicts.

[0003] Currently, no effective solution has been proposed for the problem that related technologies can only rely on introducing third-party interface documentation libraries and manually annotating each interface, resulting in missing interfaces and low efficiency in interface collection. Summary of the Invention

[0004] Therefore, it is necessary to provide an interface collection method, apparatus, computer device, and storage medium to address the aforementioned technical problems.

[0005] Firstly, this application provides an interface collection method. The method includes:

[0006] Obtain the code to be detected and the code scanning results for the code to be detected; the code to be detected includes the interfaces to be collected;

[0007] Based on the code scanning results, obtain the interface class of the code to be detected, as well as the annotation information for the interface class, and obtain the initial interface access path based on the annotation information;

[0008] Generate interface collection results for the interfaces to be collected based on the initial access path.

[0009] In one embodiment, after generating the interface collection result for the interface to be collected based on the initial access path, the interface collection method further includes:

[0010] Obtain the request information database, which contains at least one target request message;

[0011] The initial interface access path is concatenated with at least one type of request header, which includes request information. The request information is then matched with the target request information to obtain a request matching result. Based on the request matching result, the permission verification of the initial access path is completed.

[0012] In one embodiment, generating interface collection results for the interface to be collected based on the initial access path includes:

[0013] Obtain the interface access request; generate the information to be concatenated based on the code to be detected, and generate the new interface access path based on the interface access request and the information to be concatenated; generate the target access path based on the initial interface access path and the new interface access path, and generate the interface collection results based on the target access path.

[0014] In one embodiment, the information to be concatenated includes interface parameter annotations; generating the information to be concatenated based on the code to be detected, and generating a new interface access path based on the interface access request and the information to be concatenated includes:

[0015] The code scan results are checked to see if the interface parameter comments are included. If the interface parameter comments are included, they are appended to the interface access request to obtain a new interface access request. A new interface access path is then generated based on the new interface access request.

[0016] In one embodiment, the interface collection method further includes:

[0017] If a placeholder character is detected in the code to be inspected, the code scan results are traversed to query the configuration value corresponding to the placeholder character, and the new interface access path is obtained based on the configuration value.

[0018] In one embodiment, generating concatenation information based on the code to be detected, and generating a new interface access path based on the interface access request and the concatenation information, includes:

[0019] The code to be detected includes at least one sub-application, and the sub-application includes a root directory;

[0020] The root directory is checked. If a root path exists in the root directory, the root directory corresponding to the root path is concatenated with the interface access request to generate a new interface access request. The new interface access path is obtained based on the new interface access request.

[0021] In one embodiment, obtaining the code to be detected includes:

[0022] Obtain the preset target name information and the bytecode to be scanned;

[0023] Parsing information is generated based on the bytecode to be scanned. The parsing information includes at least one data packet and name information for the data packet. Target data packets with the same name information as the target name information are selected from the data packets and the target data packets are saved as the code to be detected.

[0024] In one embodiment, the code to be detected includes at least one interface class file; the interface class file includes a first interface file, a second interface file, and a third interface file, the first interface file includes a first interface annotation in the interface class, the third interface file includes a third interface class annotation and a third interface method annotation in the interface method, and the annotation information includes the first interface annotation, the third interface class annotation, and the third interface method annotation;

[0025] The initial interface access path is obtained based on the annotation information, including:

[0026] If the first interface annotation is detected in the code to be detected, the first interface file is saved as the first interface access path;

[0027] Check if the parent class name of the code to be tested is the same as the name of the second interface file. If they are the same, save the second interface file as the access path for the second basic interface. If they are different, check if the parent class name of the code to be tested is the same as the subclass name of the second interface file. If they are the same, save the second interface file as the access path for the second extended interface.

[0028] If a third interface class annotation and / or a third interface method annotation are detected in the code to be detected, the third interface file will be saved as the third interface access path.

[0029] The initial interface access path is generated based on the first interface access path, the second basic interface access path, the second extended interface access path, and the third interface access path.

[0030] Secondly, this application also provides an interface collection device. The device includes:

[0031] The acquisition module is used to acquire the code to be detected and the code scanning results for the code to be detected; the code to be detected includes the interfaces to be collected.

[0032] The calculation module is used to obtain the interface class of the code to be detected and the annotation information of the interface class based on the code scanning results, and to obtain the initial interface access path based on the annotation information.

[0033] The generation module is used to generate interface collection results for the interfaces to be collected based on the initial access path.

[0034] Thirdly, this application also provides a computer device. The computer device includes a memory and a processor, the memory storing a computer program, and the processor executing the computer program to perform the following steps:

[0035] Obtain the code to be detected and the code scanning results for the code to be detected; the code to be detected includes the interfaces to be collected;

[0036] Based on the code scanning results, obtain the interface class of the code to be detected, as well as the annotation information for the interface class, and obtain the initial interface access path based on the annotation information;

[0037] Generate interface collection results for the interfaces to be collected based on the initial access path.

[0038] The aforementioned interface collection method, apparatus, and computer equipment first obtain the interface class and annotation information of the code to be detected based on the code scanning results. Then, based on the annotation information, they obtain the initial interface access path. Finally, based on the initial interface access path, they generate the interface collection results for the interface to be collected. This interface collection method solves the problems of low efficiency and high risk associated with traditional technologies that rely on third-party interface documentation libraries and manual annotation. It significantly improves the efficiency of collecting large batches of interfaces. Furthermore, by performing permission checks after completing the interface collection, it greatly ensures data security. Attached Figure Description

[0039] Figure 1 This is a flowchart illustrating an interface collection method in one embodiment;

[0040] Figure 2 This is a flowchart illustrating the interface collection method in another embodiment;

[0041] Figure 3 A flowchart illustrating the interface collection method for another embodiment;

[0042] Figure 4 This is a flowchart illustrating the interface collection method in a preferred embodiment;

[0043] Figure 5 This is a schematic diagram of the interface collection device in one embodiment;

[0044] Figure 6 This is an internal structural diagram of a computer device in one embodiment. Detailed Implementation

[0045] To make the objectives, technical solutions, and advantages of this application clearer, the following detailed description is provided in conjunction with the accompanying drawings and embodiments. It should be understood that the specific embodiments described herein are merely illustrative and not intended to limit the scope of this application.

[0046] In one embodiment, such as Figure 1 As shown, an interface collection method is provided. Figure 1 This is a flowchart of an interface collection method according to an embodiment of this application, which includes the following steps:

[0047] Step S110: Obtain the code to be detected and the code scanning results for the code to be detected; wherein, the code to be detected includes interfaces to be collected.

[0048] The code to be detected typically includes a large number of interfaces to be collected.

[0049] Step S120: Obtain the interface class of the code to be detected and the annotation information for the interface class based on the code scanning results, and obtain the initial interface access path based on the annotation information.

[0050] The code to be detected includes a large number of class files. Based on the code scanning results, the interface classes and comment information of the interface classes are obtained. There are multiple types of interface classes and comment information. A large number of initial interface access paths can be obtained based on different comment information. Taking common Java web applications as an example, common interface design schemes in Java web include Spring, Servlet, and Jersey. For Spring-type interface classes, they usually directly contain Spring-type annotations. Therefore, if the scan results contain Spring-type annotations, the file can be identified as an interface class, and the initial interface access path can be obtained. For Servlet-type interface classes, they generally inherit from the Servlet abstract class or a subclass of the Servlet abstract class, such as the common HttpServlet class. Therefore, when scanning the code to be detected, it is only necessary to check whether the parent class name is the same as the Servlet interface class or a subclass of the interface class. If they are the same, the file can be identified as an interface class, and the initial interface access path can be obtained. For Jersey-type interface classes, unlike Spring interface classes, there are no corresponding annotations. Therefore, it is necessary to check both class annotations and method annotations. As long as one of them has Jersey interface characteristics, the file can be identified as an interface class, and the initial interface access path can be obtained.

[0051] Step S130: Generate interface collection results for the interface to be collected based on the initial access path.

[0052] The above steps are used to collect a large number of initial interface access paths, and these initial interface access paths are saved as interface collection results.

[0053] Through steps S110 to S130, firstly, the code to be detected and its corresponding code scanning results are obtained. The code to be detected includes a large number of interfaces to be collected, which have various types. Secondly, based on the code scanning results, the interface classes and corresponding annotation information of the code to be detected are obtained. Corresponding to the interfaces to be collected, the interface classes and annotation information also have various types. Taking a common Java web application as an example... Common web interface design schemes include Spring, Servlet, and Jersey. For Spring-type interface classes, they usually contain Spring-type annotations. Therefore, if the scan results contain Spring-type annotations, the file can be identified as an interface class, and the initial interface access path can be obtained. For Servlet-type interface classes, they generally inherit from the Servlet abstract class or a subclass of the Servlet abstract class, such as the common HttpServlet class. Therefore, when scanning the code to be checked, it is only necessary to check if the parent class name is the same as the Servlet interface class or a subclass of the interface class. If they are the same, the file is identified as an interface class, and the initial interface access path can be obtained. For Jersey-type interface classes, unlike Spring interface classes, there are no corresponding annotations. Therefore, it is necessary to check both class annotations and method annotations. As long as either one contains Jersey interface characteristics, the file can be identified as an interface class, and the initial interface access path can be obtained. Finally, the interface collection results are obtained based on the initial interface access paths obtained in the above steps. As can be seen, unlike existing interface collection methods, this application chooses to determine whether a class file is an interface file by scanning the interface classes and corresponding annotation information in the code to be detected, and further obtains the initial interface access path and saves it as the interface collection result. Compared with the prior art, this application not only abandons the method of manual annotation, which greatly improves efficiency, but also reduces the occurrence of interface omissions.

[0054] In one embodiment, Figure 2 This is a flowchart illustrating the interface collection method in another embodiment. The interface collection method further includes:

[0055] Step S240: Obtain the request information database, which includes at least one target request information; concatenate the initial interface access path with at least one type of request header, which includes request information; match the request information with the target request information to obtain the request matching result; and complete the permission verification of the initial access path based on the request matching result.

[0056] Specifically, after obtaining the interface collection results from the interfaces to be collected, the initial interface access path is concatenated with different types of request headers, which include request information. Currently, most existing technologies only check the existence of request headers without further checking the legality of the request header content. Therefore, this application needs to obtain a request information database containing a large amount of target request information, including user account passwords, and perform legality checks on the different types of request headers concatenated with the initial interface access path. This includes matching the request information in the request header with the target request information. If the request matching result is successful, the request header passes the permission verification. If the request matching result is unsuccessful, the completeness of the backend restrictions needs to be checked, including the logic for adding request header content verification in the backend, as well as the complexity of adding request header content in the backend to prevent forgery. It can be seen that, unlike existing technologies, this application does not stop at checking the existence of request headers, but further checks the content of request headers, and improves the backend restriction mechanism after detecting anomalies.

[0057] In one embodiment, Figure 3 This is a flowchart illustrating the interface collection method in another embodiment. The interface collection method further includes:

[0058] Step S340: Obtain the interface access request; generate the information to be concatenated based on the code to be detected, and generate the new interface access path based on the interface access request and the information to be concatenated; generate the target access path based on the initial interface access path and the new interface access path, and generate the interface collection result based on the target access path.

[0059] Specifically, based on the code to be detected, concatenation information is generated. This concatenation information includes interface parameter comments, root directory, etc. In practical applications, this concatenation information has various types. A new interface access path is generated based on the concatenation information and the interface access request. Furthermore, a target interface access path is generated based on the initial interface access path and the new interface access path, and various request methods, such as GET requests and POST requests, are used to obtain the interface collection results. It can be seen that, to avoid omissions in the above interface collection method, this application has supplemented it by dividing the different class files and different concatenation information contained in the code to be detected into different cases, further supplementing the interface collection results.

[0060] In one embodiment, the information to be concatenated includes interface parameter annotations; the method for collecting the aforementioned interfaces further includes:

[0061] The code scan results are checked to see if the interface parameter comments are included. If the interface parameter comments are included, they are appended to the interface access request to obtain a new interface access request. A new interface access path is then generated based on the new interface access request.

[0062] Specifically, in practical applications, interface parameter annotations come in various types, such as the `@Require` format. If the code scanning results indicate that the information to be concatenated includes interface parameter annotations, it means that the interface access request must contain the same parameters. Therefore, when generating a new interface access path, the corresponding interface parameter annotations must be concatenated. Alternatively, a full concatenation approach can be used, concatenating all parameters from the interface method into the interface access request to avoid omissions. The appropriate strategy can be selected based on actual needs. Thus, this application proposes a corresponding solution for a special case to supplement the aforementioned interface collection results, making the interface collection more comprehensive. Furthermore, it provides two different methods to more flexibly adapt to different practical environments.

[0063] In one embodiment, the above-mentioned interface collection method further includes:

[0064] If a placeholder character is detected in the code to be inspected, the code scan results are traversed to query the configuration value corresponding to the placeholder character, and the new interface access path is obtained based on the configuration value.

[0065] Specifically, in practical applications, to facilitate setting different routes according to specific business environments, some newly added interface access paths are written into configuration files for easy modification. However, after scanning the code to be detected, the code scan results show these newly added interface access paths as placeholder characters because they are written into the configuration files. Therefore, when placeholder characters are detected in the code scan results, it is necessary to query the configuration value corresponding to the placeholder character to obtain the newly added interface access path. Thus, this application proposes a solution to address the issue of newly added interface access paths being written into configuration files, leading to missed detections through conventional retrieval steps. This solution supplements the aforementioned interface collection results, making the interface collection more comprehensive and adaptable to different practical environments.

[0066] In one embodiment, the above-mentioned interface collection method further includes:

[0067] The code to be detected includes at least one sub-application, and the sub-application includes a root directory; the root directory is detected, and if a root path exists in the root directory, the root directory corresponding to the root path is concatenated with the interface access request to generate a new interface access request, and the new interface access path is obtained based on the new interface access request.

[0068] Specifically, in practical applications, the code to be detected may exist in multiple different sub-applications. Each sub-application includes a root directory, and each sub-application has a different root directory. Therefore, it is necessary to concatenate the different root directories in the interface access request according to the actual situation. When a root path is detected in the root directory, the root directory of the English root path is concatenated with the interface access request to obtain a new interface access request. The new interface access path is obtained from the new access request. It can be seen that this application proposes a corresponding solution for the situation where the existence of multiple sub-applications leads to omissions in interface detection, thereby supplementing the above-mentioned interface collection results, making the interface collection more comprehensive, and more flexibly adaptable to different actual environments.

[0069] In one embodiment, the above-mentioned interface collection method further includes:

[0070] Obtain the preset target name information and the bytecode to be scanned;

[0071] Parsing information is generated based on the bytecode to be scanned. The parsing information includes at least one data packet and name information for the data packet. Target data packets with the same name information as the target name information are selected from the data packets and the target data packets are saved as the code to be detected.

[0072] Specifically, the first step is to clearly define the target name information corresponding to the interface to be collected. This name can be used as a keyword. When scanning the bytecode to be scanned, target data packets with names that match the target name information are selected from the data packets and saved as the code to be detected. Data packets with names that do not match the target name information are ignored. Therefore, this application can prevent the occurrence of false positives caused by mistakenly treating third-party dependency libraries as detection targets in the initial step of obtaining the code to be detected.

[0073] In one embodiment, the code to be detected includes at least one class file; the class file includes a first interface file, a second interface file, and a third interface file, the first interface file includes a first interface annotation in the interface class, the third interface file includes a third interface class annotation and a third interface method annotation in the interface method, the annotation information including the first interface annotation, the third interface class annotation, and the third interface method annotation; the above-mentioned interface collection method further includes:

[0074] The step of obtaining the initial interface access path based on annotation information includes:

[0075] If the first interface annotation is detected in the code to be detected, the first interface file is saved as the first interface access path;

[0076] Check if the parent class name of the code to be tested is the same as the name of the second interface file. If they are the same, save the second interface file as the access path for the second basic interface. If they are different, check if the parent class name of the code to be tested is the same as the subclass name of the second interface file. If they are the same, save the second interface file as the access path for the second extended interface.

[0077] If a third interface class annotation and / or a third interface method annotation are detected in the code to be detected, the third interface file will be saved as the third interface access path.

[0078] The initial interface access path is generated based on the first interface access path, the second basic interface access path, the second extended interface access path, and the third interface access path.

[0079] Specifically, in practical applications, the class files in the code to be tested include three types, and the methods for obtaining the interface access paths of these three types of files are different. If a first interface annotation is detected in the code to be tested, the first interface file corresponding to the first interface annotation is directly saved as the first interface access path. Specifically, this first interface file can be a Spring type interface class file. Spring type interface classes usually directly carry Spring's special annotations, i.e., the first interface annotation. Therefore, if a Spring special annotation is detected, the Spring interface class file corresponding to the Spring special annotation can be directly saved as the first interface access path. For the second interface file, it is checked whether the parent class name in the code to be tested is the same as the name of the second interface file. If they are the same, the second interface file is saved as the second base interface access path. If they are different, it is checked whether the parent class name in the code to be tested is the same as the subclass name of the second interface file. If they are the same, the second interface file is saved as... The second extended interface access path, specifically, involves a Servlet-type interface class file. It checks if the parent class name is the same as the Servlet-type interface class file. If they are the same, the Servlet-type interface class file is saved as the second basic interface access path. If they are different, it checks if the parent class name is the same as the subclass name of the Servlet-type interface class file. If they are the same, the Servlet-type interface class file is saved as the second extended interface access path. For the third interface file, it checks if the code to be checked contains a third interface class annotation or a third interface method annotation. If either exists, the third interface file is saved as the third interface access path. Specifically, this third interface file can be a Jersey-type interface class file. If the Jersey interface feature is detected in the interface class annotation or interface method annotation, the Jersey-type interface class file, i.e., the third interface file, is saved as the third interface access path. An initial interface access path is generated based on the first interface access path, the second basic interface access path, the second extended interface access path, and the third interface access path.

[0080] This embodiment also provides a specific implementation of a method for generating a customized question bank, such as... Figure 4 As shown, Figure 4 This is a flowchart of an interface collection method in a preferred embodiment.

[0081] Step S410: Obtain preset target name information and bytecode to be scanned. Obtain the code to be detected based on the bytecode to be scanned, where the code to be detected includes the interface to be collected. Specifically, generate parsing information based on the bytecode to be scanned. This parsing information includes at least one data packet and the name information corresponding to the data packet. Data packets of the same product usually contain the same target name information. During scanning, the target name information can be used as a keyword to retain target data packets containing target name information and ignore data packets without target name information. Save the target data packet as the code to be detected. The above steps can prevent the incorrect detection of third-party dependency libraries during scanning, thereby causing false alarms.

[0082] Step S420: Obtain code scanning results based on the code to be detected, obtain the interface class of the code to be detected and the annotation information corresponding to the interface class based on the code scanning results, and obtain the initial interface access path based on the annotation information. Specifically, the interface class and annotation information can be of various types. Taking common Java web interfaces as an example, common interface design schemes in Java web include Spring, Servlet, and Jersey. For Spring type interface classes, they usually directly contain Spring type annotation information. Therefore, if the scan results contain Spring type annotation information, the class file can be identified as an interface class, and the initial interface access path can be obtained. For Servlet type interface classes, they generally inherit from the Servlet abstract class or a subclass of the Servlet abstract class, such as the common HttpServlet class. Therefore, when scanning the code to be detected, it is only necessary to check whether the parent class name is the same as the Servlet interface class or a subclass of the interface class. If they are the same, the class file is identified as an interface class, and the initial interface access path can be obtained. For Jersey type interface classes, unlike Spring interface classes, there is no corresponding annotation information. Therefore, it is necessary to check both class annotations and method annotations. As long as one of them has Jersey interface characteristics, the class file can be identified as an interface class, and the initial interface access path can be obtained.

[0083] Step S430 involves obtaining the interface access request, generating concatenation information based on the code to be inspected, and generating a new interface access path based on the interface access request and the concatenation information. This involves inspecting the interface access request using various request methods, such as GET or POST requests, to determine the completeness of the backend restriction mechanism. Specifically, taking Java web as an example, Spring and Jersey type interface files in Java web typically contain interface parameter annotations, such as the `@Require` annotation. This indicates that when generating the interface access request, the concatenation information needs to be concatenated with the interface access request. A new interface access request is generated based on the concatenation information and the interface access request, and the new interface access path is obtained from the new interface access request. In practical applications, to facilitate setting different routes according to specific business environments, the new interface access path is often written in a configuration file. The configuration file can be obtained based on the code scan results. Therefore, it is necessary to check whether there are placeholder characters or other special characters in the code to be inspected. When placeholder characters or other special characters are present, the code scan results need to be traversed to find the configuration value corresponding to the placeholder characters or other special characters, and the new interface access path is obtained based on the configuration value. In practical applications, there may be situations where the code to be tested includes many different sub-applications, each with a different root directory. If a root path exists in the root directory, the root directory corresponding to the root path is concatenated with the interface access request to generate a new interface access request, and a new interface access path is generated based on the new interface access request.

[0084] Step S440: Obtain the interface collection results based on the initial interface access path and the newly added interface access path. Deduplicate the interface collection results and delete duplicate access paths to reduce server maintenance costs and improve the efficiency of interface collection.

[0085] Step S450: Concatenate the interface collection results with various types of request headers to complete the permission verification of the interface collection results. Specifically, obtain the request information database, which contains a large number of target request information. Concatenate the interface collection results with various types of request headers, each containing request information. Match the request information with the target request information to obtain the request matching result. If the match is successful, the permission verification passes. If the match fails, the backend needs to add logic to verify the request header content or increase the complexity of the request header content to prevent forgery.

[0086] It should be understood that although the steps in the flowcharts of the embodiments described above are shown sequentially according to the arrows, these steps are not necessarily executed in the order indicated by the arrows. Unless explicitly stated herein, there is no strict order restriction on the execution of these steps, and they can be executed in other orders. Moreover, at least some steps in the flowcharts of the embodiments described above may include multiple steps or multiple stages. These steps or stages are not necessarily completed at the same time, but can be executed at different times. The execution order of these steps or stages is not necessarily sequential, but can be performed alternately or in turn with other steps or at least some of the steps or stages of other steps.

[0087] Based on the same inventive concept, this application also provides an interface collection device for implementing the interface collection method described above. The solution provided by this device is similar to the implementation described in the above method; therefore, the specific limitations in one or more interface collection device embodiments provided below can be found in the limitations of the interface collection method described above, and will not be repeated here.

[0088] In one embodiment, such as Figure 5 As shown, an interface collection device is provided, including: an acquisition module 51, a calculation module 52, and a generation module 53, wherein:

[0089] The acquisition module 51 is used to acquire the code to be detected and the code scanning results for the code to be detected; wherein, the code to be detected includes interfaces to be collected. In practical applications, there are usually a large number of interfaces to be collected.

[0090] The calculation module 52 is used to obtain the interface class of the code to be detected and the annotation information for the interface class based on the code scanning results, and to obtain the initial interface access path based on the annotation information. The code to be detected typically includes a large number of class files, which contain different types of interface files. The interface files contain different types of annotation information, mainly including class annotations and method annotations. In this application, the initial interface access path can be obtained based on the annotation information.

[0091] The generation module 53 is used to generate interface collection results for the interface to be collected based on the initial access path.

[0092] Specifically, the acquisition module 51 is connected to the calculation module 52. The acquisition module 51 is used to acquire the code to be detected and the corresponding code scanning results. The code to be detected typically includes a large number of interfaces to be collected. The code scanning results and the code to be detected are sent to the calculation module 52. The calculation module 52 obtains the interface classes of the code to be detected and the corresponding annotation information based on the code scanning results. Depending on the situation, the initial interface access path is obtained through the annotation information. Taking common Java web applications as an example, common interface design schemes in Java web include Spring, Servlet, and Jersey. For Spring-type interface classes, they usually directly contain Spring-type annotations. Therefore, if the scan results contain Spring-type annotations, the calculation module 52 can determine that the file is an interface class and obtain the initial interface access path. For Servlet-type interface classes, they generally inherit from the Servlet abstract class or a subclass of the Servlet abstract class, such as the common HttpServlet class. Therefore, when scanning the code to be detected, it is only necessary to check whether the parent class name is the same as the Servlet interface class or a subclass of the interface class. If they are the same, the calculation module 52 determines that the file is an interface class and obtains the initial interface access path. For Jersey-type interface classes, unlike Spring interface classes, they do not have corresponding annotations. Therefore, it is necessary to check both class annotations and method annotations. As long as one of them contains Jersey interface characteristics, the calculation module 52 can determine that the file is an interface class and obtain the initial interface access path. The initial interface access path is then sent to the generation module 53, which generates the interface collection results based on the initial interface access path.

[0093] The aforementioned interface collection device completely eliminates the need for manual annotation of each interface, reducing a significant amount of manpower and resources, and greatly improving the efficiency of interface collection; at the same time, it does not require a built-in third-party interface documentation library, reducing the possibility of introducing security risks.

[0094] Each module in the aforementioned device for generating a customized question bank can be implemented entirely or partially through software, hardware, or a combination thereof. These modules can be embedded in the processor of a computer device in hardware form or independent of it, or stored in the memory of a computer device in software form, so that the processor can call and execute the corresponding operations of each module.

[0095] In one embodiment, a computer device is provided, which may be a terminal, and its internal structure diagram may be as follows: Figure 6As shown, the computer device includes a processor, memory, communication interface, display screen, and input devices connected via a system bus. The processor provides computing and control capabilities. The memory includes non-volatile storage media and internal memory. The non-volatile storage media stores the operating system and computer programs. The internal memory provides an environment for the operation of the operating system and computer programs stored in the non-volatile storage media. The communication interface is used for wired or wireless communication with external terminals; wireless communication can be achieved through Wi-Fi, mobile cellular networks, NFC (Near Field Communication), or other technologies. When the computer program is executed by the processor, it implements an interface information synchronization method. The display screen can be an LCD screen or an e-ink screen. The input devices can be a touch layer covering the display screen, buttons, a trackball, or a touchpad mounted on the computer device casing, or an external keyboard, touchpad, or mouse.

[0096] Those skilled in the art will understand that Figure 6 The structure shown is merely a block diagram of a portion of the structure related to the present application and does not constitute a limitation on the segmented data statistics device to which the present application is applied. A specific segmented data statistics device may include more or fewer components than those shown in the figure, or combine certain components, or have different component arrangements.

[0097] Those skilled in the art should understand that the technical features of the above embodiments can be combined in any way. For the sake of brevity, not all possible combinations of the technical features in the above embodiments have been described. However, as long as there is no contradiction in the combination of these technical features, they should be considered to be within the scope of this specification.

[0098] The embodiments described above are merely illustrative of several implementation methods of this application, and while the descriptions are relatively specific and detailed, they should not be construed as limiting the scope of the invention patent. It should be noted that those skilled in the art can make various modifications and improvements without departing from the concept of this application, and these all fall within the protection scope of this application. Therefore, the protection scope of this patent application should be determined by the appended claims.

Claims

1. An interface collection method, characterized in that, The method includes: Obtain the code to be detected and the code scanning results for the code to be detected; wherein, the code to be detected includes interfaces to be collected; the code to be detected includes at least one class file; the class file includes a first interface file, a second interface file and a third interface file, the first interface file includes a first interface annotation in the interface class, and the third interface file includes a third interface class annotation and a third interface method annotation in the interface method; The interface class of the code to be detected and the annotation information for the interface class are obtained based on the code scanning results, and the initial interface access path is obtained based on the annotation information; the annotation information includes the first interface annotation, the third interface class annotation and the third interface method annotation; The step of obtaining the initial interface access path based on the annotation information includes: If the first interface annotation is detected in the code to be detected, the first interface file is saved as the first interface access path; The system checks whether the parent class name of the code to be tested is the same as the name of the second interface file. If they are the same, the second interface file is saved as the second basic interface access path. If they are not the same, the system checks whether the parent class name of the code to be tested is the same as the subclass name of the second interface file. If they are the same, the second interface file is saved as the second extended interface access path. If the third interface class annotation and / or the third interface method annotation are detected in the code to be detected, then the third interface file is saved as the third interface access path; The initial interface access path is generated based on the first interface access path, the second basic interface access path, the second extended interface access path, and the third interface access path. Generate interface collection results for the interface to be collected based on the initial interface access path; Obtain a request information database, wherein the request information database includes at least one target request information; The initial interface access path is concatenated with at least one type of request header, the request header including request information. The request information is matched with the target request information to obtain a request matching result. The permission verification of the initial interface access path is completed based on the request matching result.

2. The method according to claim 1, characterized in that, The step of generating interface collection results for the interface to be collected based on the initial interface access path includes: Get the API access request; Generate concatenation information based on the code to be detected, and generate a new interface access path based on the interface access request and the concatenation information; A target access path is generated based on the initial interface access path and the newly added interface access path, and the interface collection result is generated based on the target access path.

3. The method according to claim 2, characterized in that, The information to be concatenated includes interface parameter annotations; the process of generating the information to be concatenated based on the code to be detected, and generating a new interface access path based on the interface access request and the information to be concatenated includes: The code scan result is checked to see if the interface parameter annotation is included. If the interface parameter annotation exists, the interface parameter annotation is concatenated into the interface access request to obtain a new interface access request, and the new interface access path is generated based on the new interface access request.

4. The method according to claim 2, characterized in that, The method further includes: If a placeholder character is detected in the code to be detected, the code scan results are traversed to query the configuration value corresponding to the placeholder character, and the new interface access path is obtained based on the configuration value.

5. The method according to claim 2, characterized in that, The step of generating concatenated information based on the code to be detected, and generating a new interface access path based on the interface access request and the concatenated information, includes: The code to be detected includes at least one sub-application, and the sub-application includes a root directory; If the root directory is detected and a root path exists in the root directory, the root directory corresponding to the root path is concatenated with the interface access request to generate a new interface access request, and the new interface access path is obtained based on the new interface access request.

6. The method according to claim 1, characterized in that, The acquisition of the code to be detected includes: Obtain the preset target name information and the bytecode to be scanned; Parsing information is generated based on the bytecode to be scanned. The parsing information includes at least one data packet and name information for the data packet. Target data packets with the same name information as the target name information are selected from the data packets, and the target data packets are saved as the code to be detected.

7. An interface collection device, characterized in that, The device includes: An acquisition module is used to acquire the code to be detected and the code scanning results for the code to be detected; wherein, the code to be detected includes an interface to be collected; the code to be detected includes at least one class file; the class file includes a first interface file, a second interface file and a third interface file, the first interface file includes a first interface annotation in the interface class, and the third interface file includes a third interface class annotation and a third interface method annotation in the interface method; The calculation module is used to obtain the interface class of the code to be detected and the annotation information for the interface class based on the code scanning results, and to obtain the initial interface access path based on the annotation information; the annotation information includes the first interface annotation, the third interface class annotation and the third interface method annotation; The step of obtaining the initial interface access path based on the annotation information includes: If the first interface annotation is detected in the code to be detected, the first interface file is saved as the first interface access path; The system checks whether the parent class name of the code to be tested is the same as the name of the second interface file. If they are the same, the second interface file is saved as the second basic interface access path. If they are not the same, the system checks whether the parent class name of the code to be tested is the same as the subclass name of the second interface file. If they are the same, the second interface file is saved as the second extended interface access path. If the third interface class annotation and / or the third interface method annotation are detected in the code to be detected, then the third interface file is saved as the third interface access path; The initial interface access path is generated based on the first interface access path, the second basic interface access path, the second extended interface access path, and the third interface access path. The generation module is used to generate interface collection results for the interface to be collected based on the initial interface access path; Obtain a request information database, wherein the request information database includes at least one target request information; The initial interface access path is concatenated with at least one type of request header, the request header including request information. The request information is matched with the target request information to obtain a request matching result. The permission verification of the initial interface access path is completed based on the request matching result.

8. A computer device comprising a memory and a processor, wherein the memory stores a computer program, characterized in that, When the processor executes the computer program, it implements the steps of the method according to any one of claims 1 to 6.

Citation Information

Patent Citations

  • Request path acquisition method and device, computer equipment and storage medium

    CN112965749A

  • Method and device for analyzing program interface and computer equipment

    CN113760690A