A method for large model security detection and code auditing
Patent Information
- Application Number
- CN202610766814.9
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2026-05-29
- Publication Date
- 2026-08-28
AI Technical Summary
然而,大模型的深度应用也带来了内容安全风险和代码安全风险安全挑战
Smart Images

Figure CN122653672A_ABST
Abstract
Description
Technical Field
[0001] This invention relates to the field of large model technology, and more specifically to a method for large model security detection and code auditing. Background Technology
[0002] With the rapid development of artificial intelligence (AI) technology, large language models are increasingly being applied in the power industry, covering core business areas such as power dispatching, equipment operation and maintenance, fault diagnosis, marketing and customer service, and code development. The State Grid Corporation of China's massive, billion-level Bright Power large-scale model integrates various basic model capabilities and deeply empowers power grid business scenarios with AI capabilities through "incremental pre-training + industry fine-tuning." However, the deep application of large models also brings content security risks and code security challenges. Therefore, a method for large-scale model security detection and code auditing is needed to perform text security detection and code auditing. Summary of the Invention
[0003] The purpose of this invention is to provide a method for large-scale model security detection and code auditing, which can perform text security detection and code auditing.
[0004] To achieve the above objectives, embodiments of the present invention provide a method for large-scale model security detection and code auditing, the method comprising: Safety standard data and code data related to the power industry are collected to construct a safety evaluation set and a code standard constraint library. The safety evaluation set includes a subset of evaluation questions and a subset of corresponding standard answers, as well as a subset of code questions. Obtain a subset of evaluation question requests and their corresponding code requests, and enter the appropriate detection channel based on the request type; Based on the evaluation question subset request, the content of the corresponding evaluation question subset is sent into the large model security detection channel to obtain the large model generation result subset, and the generation result subset is evaluated based on the obtained standard answer subset; Based on the code request, the corresponding subset of code issues is sent to the code security audit channel of the large model to obtain code analysis results, and the code analysis results are evaluated according to the code standard constraint library; Based on the evaluation of the generated subset of results and the evaluation of the code analysis results, a comprehensive risk assessment result is generated, and the risk level is determined based on the comprehensive risk assessment result.
[0005] Optionally, based on the evaluation question subset request, the content of the corresponding evaluation question subset is sent to the large model security detection channel to obtain the large model generation result subset, and the generation result subset is evaluated based on the obtained standard answer subset, including: Obtain the generated results from the subset of generated results and the standard answers from the corresponding subset of standard answers; The generated results and the corresponding standard answers are fed into the embedding layer of the Siam architecture, which generates corresponding vectors from the input text using the Transformer model. Based on the generated vectors, calculate the similarity between the generated result and the standard answer; Based on the obtained similarity, a security assessment is performed on the generated results for the large model.
[0006] Optionally, based on the generated corresponding vector, the similarity between the generated result and the standard answer is calculated, including: Obtain the vectors corresponding to the generated results and the standard answer; Based on the obtained vectors, the similarity between the generated result and the standard answer is calculated using formula (1): , formula (1) in, These represent the generated result and the standard answer, respectively. Vectors representing the generated result and the standard answer, respectively. Indicates similarity.
[0007] Optionally, based on the evaluation question subset request, the content of the corresponding evaluation question subset is sent to the large model security detection channel to obtain the large model generation result subset, and the generation result subset is evaluated based on the obtained standard answer subset, including: Obtain the vectors corresponding to the generated results and the standard answers; Based on the vectors corresponding to the generated result and the standard answer, obtain the Euclidean distance between the generated result and the standard answer; Based on the obtained Euclidean distance, the comparison loss function between the generated result and the standard answer is calculated using formula (2): , formula (2) in, Represents the loss function. This represents the input to the embedded layer of the Siamese architecture. When the value is 0, it indicates that the inputs are of the same type. A value of 1 indicates that the inputs are not of the same type. This represents the input Euclidean distance. This represents the average Euclidean distance. Indicates margin; The Siamese architecture is optimized based on the contrast loss function in formula (2).
[0008] Optionally, a security evaluation is performed on the generated results of the large model based on the obtained similarity, including: Obtain the similarity score and the corresponding standard answer; Select the answer with the highest similarity among the standard answers as the classification answer, and determine the number of nearest neighbors to select; Calculate the Euclidean distance between the remaining standard answers and the categorical answers; Standard answers whose Euclidean distance to the categorized answers is within the range of nearest neighbors are selected as a class.
[0009] Optionally, a security evaluation is performed on the generated results of the large model based on the obtained similarity, including: Obtain the standard answer and corresponding similarity for each category; The average similarity is calculated as the average similarity of the standard answers for each category. The overall similarity is calculated using formula (3) based on the average similarity of each category: , formula (3) in, Indicates overall similarity. Indicates the first Average similarity The corresponding constant factor; The overall similarity is obtained, and the security level of the generated results of the large model is evaluated based on the overall similarity.
[0010] Optionally, based on the code request, a subset of corresponding code issues is sent to the code security audit channel of the large model to obtain code analysis results. These results are then evaluated against a code style constraint library, including: The language front-end parser converts the subset of code problems into an abstract syntax tree structure. Based on the abstract syntax tree structure and the vulnerability feature patterns of each rule in the code specification constraint library, a structural comparison is performed to obtain the vulnerability object; Based on the vulnerability object, the risk score of the vulnerability object is calculated using formula (4): , formula (4) in, Indicates risk score, Rules for representing vulnerable objects The basic risk score is set based on the severity of the vulnerability. Indicates code context risk factors, Indicates the power industry scenario enhancement factor; The code context risk factor is obtained through formula (5): , formula (5) in, , Indicates risk parameters, This represents the data stream contamination factor. It takes a value of 1 when the data involved in the vulnerability originates from external input, and 0 otherwise. This represents the reachability factor, which is 1 if the code containing the vulnerability is located on the critical business main control flow path, and 0 otherwise. The power industry scenario enhancement factor is obtained through formula (6): , formula (6) in, , Indicates the enhancement coefficient. This represents the scheduling business association factor. When the function containing the vulnerability involves power grid scheduling instruction processing logic, it takes the value of 1; otherwise, it takes the value of 0. This represents a protection business-related factor. When the function containing the vulnerability involves relay protection setting calculation or modification logic, it takes the value of 1; otherwise, it takes the value of 0.
[0011] Optionally, based on the code request, a subset of corresponding code issues is sent to the code security audit channel of the large model to obtain code analysis results. These results are then evaluated against a code style constraint library, including: Security level evaluation of the code analysis results corresponding to the vulnerable object; Based on the security level evaluation of the code analysis results and the vulnerability severity of the corresponding vulnerability object, the basic risk score of the rule is obtained through formula (7): , formula (9) in, This indicates the security level of the inference request corresponding to the vulnerable object. Indicates the severity of the vulnerability in the target object. , This represents the adjustment factor.
[0012] Optionally, a structural comparison is performed based on the abstract syntax tree structure and the vulnerability feature patterns of each rule in the code style constraint library to obtain vulnerability objects, including: Obtain the abstract syntax tree structure and code style constraint library, and process the tree structure in the abstract syntax tree structure and code style constraint library into an ordered tree; For the abstract syntax tree structure and the tree structure in the code style constraint library, a fixed local substructure is generated for each node through a sliding window; Deduplication is performed on the local substructures of the tree structures in the Abstract Syntax Tree (AST) structure and the code style constraint library to obtain a set of trees related to the AST structure and the code style constraint library. For the set of trees in the Abstract Syntax Tree (AST) structure and the code style constraint library, the size of the union of the two sets is subtracted from the size of the intersection to obtain the closeness between the AST structure and the trees in the code style constraint library. Vulnerabilities corresponding to the trees in the code style constraint library whose abstract syntax tree structure is closest to the one with the highest degree of similarity are selected as vulnerability objects.
[0013] Through the above technical solution, the method for large-scale model security testing and code auditing provided by this invention can collect safety specification data and code data related to the power industry to construct a security evaluation set and a code specification constraint library. The security evaluation set includes a subset of evaluation questions, a corresponding subset of standard answers, and a subset of code questions. Then, it can obtain evaluation question subset requests and corresponding code requests, and enter the appropriate detection channel based on the request type. When the request type is an evaluation question subset request, the content of the corresponding evaluation question subset can be sent to the large-scale model security testing channel according to the request, thereby obtaining a subset of large-scale model generated results, and evaluating the generated results subset based on the obtained standard answer subset. When the request type is a code request, the corresponding subset of code questions can be sent to the large-scale model code security auditing channel according to the code request, thereby obtaining code analysis results, and evaluating the code analysis results based on the code specification constraint library. After obtaining evaluations of the generated result subset and code analysis results, a comprehensive risk assessment result can be generated based on these evaluations, and the risk level can be determined based on this comprehensive risk assessment result. This comprehensive risk assessment result can be a weighted sum of the evaluations of the generated result subset and the code analysis results. Risk levels can be divided based on expert experience, with corresponding risk warnings within each range. This method can perform text security detection and code auditing.
[0014] Other features and advantages of the embodiments of the present invention will be described in detail in the following detailed description section. Attached Figure Description
[0015] The accompanying drawings are provided to further illustrate embodiments of the present invention and form part of the specification. They are used together with the following detailed description to explain the embodiments of the present invention, but do not constitute a limitation thereof. In the drawings: Figure 1 This is a flowchart of a method for large-scale model security testing and code auditing according to an embodiment of the present invention. Detailed Implementation
[0016] The specific embodiments of the present invention will be described in detail below with reference to the accompanying drawings. It should be understood that the specific embodiments described herein are for illustration and explanation only and are not intended to limit the scope of the present invention.
[0017] In the embodiments of this application, certain software, components, models and other existing solutions in the industry may be mentioned. These should be regarded as exemplary and are only intended to illustrate the feasibility of implementing the technical solution of this application. However, they do not mean that the applicant has used or necessarily used the solution.
[0018] Figure 1 This is a flowchart of a method for large-scale model security testing and code auditing according to an embodiment of the present invention. The method may include: In step S1, safety standard data and code data related to the power industry are collected to construct a safety evaluation set and a code standard constraint library. The safety evaluation set includes a subset of evaluation questions and a corresponding subset of standard answers, as well as a subset of code questions.
[0019] In step S2, the evaluation problem subset request and the corresponding code request are obtained, and the corresponding detection channel is entered based on the request type.
[0020] In step S3, the content of the corresponding evaluation question subset is sent to the large model security detection channel according to the evaluation question subset request to obtain the large model generation result subset, and the generation result subset is evaluated according to the obtained standard answer subset.
[0021] In step S4, the corresponding subset of code issues is sent to the code security audit channel of the large model according to the code request to obtain the code analysis results, and the code analysis results are evaluated according to the code standard constraint library.
[0022] In step S5, a comprehensive risk assessment result is generated based on the evaluation of the generated result subset and the evaluation of the code analysis result, and the risk level is determined based on the comprehensive risk assessment result.
[0023] In this invention, safety standard data and code data related to the power industry can be collected to construct a safety evaluation set and a code specification constraint library. The safety evaluation set includes a subset of evaluation questions, a corresponding subset of standard answers, and a subset of code questions. Then, evaluation question subset requests and corresponding code requests can be obtained, and appropriate detection channels can be entered based on the request type. When the request type is an evaluation question subset request, the content of the corresponding evaluation question subset can be sent to the large model security detection channel, thereby obtaining a large model generated result subset, which can be evaluated based on the obtained standard answer subset. When the request type is a code request, the corresponding code question subset can be sent to the large model code security audit channel, thereby obtaining code analysis results, which can be evaluated based on the code specification constraint library. After obtaining the evaluation of the generated result subset and the code analysis results, a comprehensive risk assessment result can be generated based on the evaluation of the generated result subset and the code analysis results, and the risk level can be determined based on the comprehensive risk assessment result. The comprehensive risk assessment result can be a weighted sum of the evaluations of the generated subset and the code analysis results. Risk levels can be categorized based on expert experience, with corresponding risk warnings within each range. This method can perform text security detection and code auditing.
[0024] In one embodiment of the present invention, the evaluation process may include: In step S6, the generated results in the generated result subset and the standard answers in the corresponding standard answer subset are obtained.
[0025] In step S7, the generated results and the corresponding standard answers are fed into the embedding layer of the Siam architecture. The embedding layer generates corresponding vectors from the input text using the Transformer model.
[0026] In step S8, the similarity between the generated result and the standard answer is calculated based on the corresponding generated vector.
[0027] In step S9, a security evaluation is performed on the generated results of the large model based on the obtained similarity.
[0028] In this invention, the generated results from the subset of generated results and the standard answers from the corresponding subset of standard answers are obtained. These results and standard answers are then fed into the embedding layer of the Siam architecture. The embedding layer can generate corresponding vectors from the input text using a Transformer model. Based on the generated vectors, the similarity between the generated results and the standard answers is calculated. Based on the obtained similarity, a security evaluation can be performed on the generated results of the large model.
[0029] In one embodiment of the present invention, the process of obtaining similarity may include: In step S10, the vectors corresponding to the generated results and the standard answer are obtained.
[0030] In step S11, based on the obtained vector, the similarity between the generated result and the standard answer is calculated using formula (1): , formula (1) in, These represent the generated result and the standard answer, respectively. Vectors representing the generated result and the standard answer, respectively. Indicates similarity.
[0031] In this invention, when obtaining similarity, the vectors corresponding to the generated result and the standard answer can be obtained first. After obtaining the corresponding vectors, the similarity between the generated result and the standard answer can be calculated using formula (1) based on the obtained vectors. As can be seen from formula (1), the similarity in this application does not use Euclidean distance for evaluation. Because the similarity in this application is calculated by the vectors corresponding to the generated result and the standard answer, if the usual Euclidean distance or cosine similarity is used for calculation, the inconspicuous differences between the generated result and the standard answer will be masked, and the difference between the two cannot be accurately evaluated. Therefore, formula (1) in this application can amplify the difference between the two by using Euclidean distance, thereby better evaluating the difference between the two.
[0032] In one embodiment of the present invention, the process of optimizing the Siamese structure may include: In step S12, the vectors corresponding to the generated results and the standard answers are obtained.
[0033] In step S13, the Euclidean distance between the generated result and the standard answer is obtained based on the vectors corresponding to the generated result and the standard answer.
[0034] In step S14, based on the obtained Euclidean distance, the contrast loss function between the generated result and the standard answer is calculated using formula (2): , formula (2) in, Represents the loss function. This represents the input to the embedded layer of the Siamese architecture. When the value is 0, it indicates that the inputs are of the same type. A value of 1 indicates that the inputs are not of the same type. This represents the input Euclidean distance. This represents the average Euclidean distance. Indicates margin.
[0035] In step S15, the Siamese architecture is optimized according to the contrast loss function of formula (2).
[0036] In this invention, after obtaining the vectors corresponding to the generated result and the standard answer, the Euclidean distance between the generated result and the standard answer can be obtained based on the vectors corresponding to the generated result and the standard answer. After obtaining the Euclidean distance, the contrast loss function between the generated result and the standard answer can be calculated using formula (2). From formula (2), it can be seen that when the generated result and the standard answer do not belong to the same category, their distance will be at least greater than [a certain value]. In the case of samples within the same class, the squared distance between them is generally used as the loss, thus encouraging samples of the same class to maintain a small distance, while the distance between samples of different classes should be at least greater than the average distance between them. The Siamese architecture can be optimized by using the contrast loss function in formula (2) to improve the classification effect.
[0037] In one embodiment of the present invention, the classification process may include: In step S16, the similarity and the corresponding standard answer are obtained.
[0038] In step S17, the answer with the highest similarity among the standard answers is selected as the classification answer, and the number of nearest neighbors to be selected is determined.
[0039] In step S18, the Euclidean distance between the remaining standard answers and the categorical answers is calculated.
[0040] In step S19, standard answers whose Euclidean distance to the categorized answer is within the range of nearest neighbors are selected as a class.
[0041] In this invention, after obtaining the similarity scores and corresponding standard answers, classification can be performed using these standard answers. The most representative answer among the standard answers can be selected as the classification answer to classify all answers. This most representative answer can be the answer with the highest similarity score, and the number of nearest neighbors to be selected can be determined; this number of nearest neighbors can be a set threshold known to those skilled in the art. After selecting representative classification answers, the Euclidean distance between the remaining standard answers and the classification answers can be calculated. Standard answers whose Euclidean distance to the classification answer is within the range of the number of nearest neighbors can be considered as one category; that is, standard answers within this range of the number of nearest neighbors can be regarded as one category. This operation, while classifying the standard answers, can further filter the classification answers, removing some unrepresentative standard answers.
[0042] In one embodiment of the present invention, the evaluation process may include: In step S20, the standard answer and the corresponding similarity for each category are obtained.
[0043] In step S21, the average similarity of the standard answers for each category is calculated as the average similarity.
[0044] In step S22, the overall similarity is calculated using formula (3) based on the average similarity of each category: , formula (3) in, Indicates overall similarity. Indicates the first Average similarity The corresponding constant factor.
[0045] In step S23, the overall similarity is obtained, and the security level of the generated results of the large model is evaluated based on the overall similarity.
[0046] In this invention, when evaluating a large model, the standard answer and corresponding similarity for each category can be obtained. After obtaining the similarity, the average similarity of the standard answers for each category can be calculated as the average similarity. After obtaining the average similarity for each category, the overall similarity can be calculated using formula (3). The safety level of the large model's generated results can be evaluated using this overall similarity.
[0047] In one embodiment of the present invention, the process for evaluating code analysis results may include: In step S24, the subset of code problems is converted into an abstract syntax tree structure by the language front-end parser.
[0048] In step S25, a structural comparison is performed based on the abstract syntax tree structure and the vulnerability feature patterns of each rule in the code specification constraint library to obtain the vulnerability object.
[0049] In step S26, based on the vulnerable object, the risk score of the vulnerable object is calculated using formula (4): , formula (4) in, Indicates risk score, Rules for representing vulnerable objects The basic risk score is set based on the severity of the vulnerability. Indicates code context risk factors, This represents the scenario enhancement factor in the power industry.
[0050] In step S27, the code context risk factor is obtained using formula (5): , formula (5) in, , Indicates risk parameters, This represents the data stream contamination factor. It takes a value of 1 when the data involved in the vulnerability originates from external input, and 0 otherwise. This represents the reachability factor. It takes a value of 1 if the code containing the vulnerability is located on the critical business main control flow path, and 0 otherwise.
[0051] In step S28, the power industry scenario enhancement factor is obtained through formula (6): , formula (6) in, , Indicates the enhancement coefficient. This represents the scheduling business association factor. When the function containing the vulnerability involves power grid scheduling instruction processing logic, it takes the value of 1; otherwise, it takes the value of 0. This represents a protection business-related factor. When the function containing the vulnerability involves relay protection setting calculation or modification logic, it takes the value of 1; otherwise, it takes the value of 0.
[0052] In this invention, a subset of code problems can be converted into an abstract syntax tree structure using a language front-end parser. Based on the structural comparison of the abstract syntax tree structure with the vulnerability feature patterns of each rule in the code specification constraint library, vulnerability objects can be obtained. Based on the vulnerability objects, a risk score can be calculated using formula (4). Then, the code context risk factor can be obtained using formula (5). The power industry scenario enhancement factor can be obtained using formula (6).
[0053] The basic risk score for this rule can be obtained by evaluating the security level of the code analysis results corresponding to the vulnerability object. Based on the security level evaluation of the code analysis results and the vulnerability severity of the corresponding vulnerability object, the basic risk score for the rule is obtained through formula (7): , formula (9) in, This indicates the security level of the code analysis results corresponding to the vulnerable object. Indicates the severity of the vulnerability in the target object. , This represents the adjustment factor.
[0054] In one embodiment of the present invention, the process of obtaining the vulnerability object may include: In step S29, the abstract syntax tree structure and code style constraint library are obtained, and the tree structure in the abstract syntax tree structure and code style constraint library is processed into an ordered tree.
[0055] In step S30, for the abstract syntax tree structure and the tree structure in the code style constraint library, a fixed local substructure is generated for each node through a sliding window.
[0056] In step S31, duplicates are removed from the local substructures of the tree structures in the abstract syntax tree structure and the code style constraint library to obtain a tree set related to the abstract syntax tree structure and the code style constraint library.
[0057] In step S32, for the set of trees in the abstract syntax tree structure and the code style constraint library, the size of the union of the two sets is subtracted from the size of the intersection to obtain the proximity between the trees in the abstract syntax tree structure and the code style constraint library.
[0058] In step S33, the vulnerabilities corresponding to the trees in the code style constraint library with the greatest similarity in the abstract syntax tree structure are selected as vulnerability objects.
[0059] In this invention, when acquiring vulnerability objects, an abstract syntax tree (API) structure and a code style constraint library can be obtained, and the tree structures in the API and code style constraint library can be processed into ordered trees. For the tree structures in the API and code style constraint library, a fixed local substructure can be generated for each node using a sliding window. The local substructures of the tree structures in the API and code style constraint library can be deduplicated to obtain a set of trees related to the API and code style constraint library. For the set of trees in the API and code style constraint library, the size of the union of the two sets can be subtracted from the size of the intersection to obtain the proximity of the trees in the API and code style constraint library. Then, the vulnerability corresponding to the tree with the highest proximity in the API and code style constraint library can be selected as the vulnerability object.
[0060] Through the above technical solution, the method for large-scale model security testing and code auditing provided by this invention can collect safety specification data and code data related to the power industry to construct a security evaluation set and a code specification constraint library. The security evaluation set includes a subset of evaluation questions, a corresponding subset of standard answers, and a subset of code questions. Then, it can obtain evaluation question subset requests and corresponding code requests, and enter the appropriate detection channel based on the request type. When the request type is an evaluation question subset request, the content of the corresponding evaluation question subset can be sent to the large-scale model security testing channel according to the request, thereby obtaining a subset of large-scale model generated results, and evaluating the generated results subset based on the obtained standard answer subset. When the request type is a code request, the corresponding subset of code questions can be sent to the large-scale model code security auditing channel according to the code request, thereby obtaining code analysis results, and evaluating the code analysis results based on the code specification constraint library. After obtaining evaluations of the generated result subset and code analysis results, a comprehensive risk assessment result can be generated based on these evaluations, and the risk level can be determined based on this comprehensive risk assessment result. This comprehensive risk assessment result can be a weighted sum of the evaluations of the generated result subset and the code analysis results. Risk levels can be divided based on expert experience, with corresponding risk warnings within each range. This method can perform text security detection and code auditing.
[0061] Those skilled in the art will understand that embodiments of this application can be provided as methods, systems, or computer program products. Therefore, this application can take the form of a completely hardware embodiment, a completely software embodiment, or an embodiment combining software and hardware aspects. Furthermore, this application can take the form of a computer program product embodied on one or more computer-usable storage media (including but not limited to disk storage, CD-ROM, optical storage, etc.) containing computer-usable program code.
[0062] This application is described with reference to flowchart illustrations and / or block diagrams of methods, apparatus (systems), and computer program products according to embodiments of this application. It will be understood that each block of the flowchart illustrations and / or block diagrams, and combinations of blocks in the flowchart illustrations and / or block diagrams, can be implemented by computer program instructions. These computer program instructions can be provided to a processor of a general-purpose computer, special-purpose computer, embedded processor, or other programmable data processing apparatus to produce a machine, such that the instructions, which execute via the processor of the computer or other programmable data processing apparatus, generate instructions for implementing the flowchart... Figure 1 One or more processes and / or boxes Figure 1 A device that provides the functions specified in one or more boxes.
[0063] These computer program instructions may also be stored in a computer-readable storage medium that can direct a computer or other programmable data processing device to function in a particular manner, such that the instructions stored in the computer-readable storage medium produce an article of manufacture including instruction means, which are implemented in a process Figure 1 One or more processes and / or boxes Figure 1 The function specified in one or more boxes.
[0064] These computer program instructions may also be loaded onto a computer or other programmable data processing equipment to cause a series of operational steps to be performed on the computer or other programmable equipment to produce a computer-implemented process, thereby providing instructions that execute on the computer or other programmable equipment for implementing the process. Figure 1 One or more processes and / or boxes Figure 1 The steps of the function specified in one or more boxes.
[0065] In a typical configuration, a computing device includes one or more processors (CPU), input / output interfaces, network interfaces, and memory.
[0066] Memory may include non-persistent memory in computer-readable media, such as random access memory (RAM) and / or non-volatile memory, such as read-only memory (ROM) or flash RAM. Memory is an example of computer-readable media.
[0067] Computer-readable media includes both permanent and non-permanent, removable and non-removable media that can store information using any method or technology. Information can be computer-readable instructions, data structures, modules of programs, or other data. Examples of computer storage media include, but are not limited to, phase-change memory (PRAM), static random access memory (SRAM), dynamic random access memory (DRAM), other types of random access memory (RAM), read-only memory (ROM), electrically erasable programmable read-only memory (EEPROM), flash memory or other memory technologies, CD-ROM, digital versatile optical disc (DVD) or other optical storage, magnetic tape, magnetic disk storage or other magnetic storage devices, or any other non-transferable medium that can be used to store information accessible by a computing device. As defined herein, computer-readable media does not include transient computer-readable media, such as modulated data signals and carrier waves.
[0068] It should also be noted that the terms "comprising," "including," or any other variations thereof are intended to cover non-exclusive inclusion, such that a process, method, article, or apparatus that comprises a list of elements includes not only those elements but also other elements not expressly listed, or elements inherent to such process, method, article, or apparatus. Unless otherwise specified, an element defined by the phrase "comprising one..." does not exclude the presence of other identical elements in the process, method, article, or apparatus that includes that element.
[0069] The above are merely embodiments of this application and are not intended to limit the scope of this application. Various modifications and variations can be made to this application by those skilled in the art. Any modifications, equivalent substitutions, improvements, etc., made within the spirit and principles of this application should be included within the scope of the claims of this application.
Claims
1. A method for large-scale model security detection and code auditing, characterized in that, The method includes: Safety standard data and code data related to the power industry are collected to construct a safety evaluation set and a code standard constraint library. The safety evaluation set includes a subset of evaluation questions and a subset of corresponding standard answers, as well as a subset of code questions. Obtain a subset of evaluation question requests and their corresponding code requests, and enter the appropriate detection channel based on the request type; Based on the evaluation question subset request, the content of the corresponding evaluation question subset is sent into the large model security detection channel to obtain the large model generation result subset, and the generation result subset is evaluated based on the obtained standard answer subset; Based on the code request, the corresponding subset of code issues is sent to the code security audit channel of the large model to obtain code analysis results, and the code analysis results are evaluated according to the code standard constraint library; Based on the evaluation of the generated subset of results and the evaluation of the code analysis results, a comprehensive risk assessment result is generated, and the risk level is determined based on the comprehensive risk assessment result.
2. The method according to claim 1, characterized in that, Based on the evaluation question subset request, the content of the corresponding evaluation question subset is sent to the large model security detection channel to obtain the large model generation result subset. The generated result subset is then evaluated based on the obtained standard answer subset, including: Obtain the generated results from the subset of generated results and the standard answers from the corresponding subset of standard answers; The generated results and the corresponding standard answers are fed into the embedding layer of the Siam architecture, which generates corresponding vectors from the input text using the Transformer model. Based on the generated vectors, calculate the similarity between the generated result and the standard answer; Based on the obtained similarity, a security assessment is performed on the generated results for the large model.
3. The method according to claim 2, characterized in that, Based on the generated vectors, the similarity between the generated result and the standard answer is calculated, including: Obtain the vectors corresponding to the generated results and the standard answer; Based on the obtained vectors, the similarity between the generated result and the standard answer is calculated using formula (1): , Official (1) in, These represent the generated result and the standard answer, respectively. Vectors representing the generated result and the standard answer, respectively. Indicates similarity.
4. The method according to claim 2, characterized in that, Based on the evaluation question subset request, the content of the corresponding evaluation question subset is sent to the large model security detection channel to obtain the large model generation result subset. The generated result subset is then evaluated based on the obtained standard answer subset, including: Obtain the vectors corresponding to the generated results and the standard answers; Based on the vectors corresponding to the generated result and the standard answer, obtain the Euclidean distance between the generated result and the standard answer; Based on the obtained Euclidean distance, the comparison loss function between the generated result and the standard answer is calculated using formula (2): , Official (2) in, Represents the loss function. This represents the input to the embedded layer of the Siamese architecture. When the value is 0, it indicates that the inputs are of the same type. A value of 1 indicates that the inputs are not of the same type. This represents the input Euclidean distance. This represents the average Euclidean distance. Indicates margin; The Siamese architecture is optimized based on the contrast loss function in formula (2).
5. The method according to claim 3, characterized in that, Based on the obtained similarity, a security evaluation is performed on the generated results of the large model, including: Obtain the similarity score and the corresponding standard answer; Select the answer with the highest similarity among the standard answers as the classification answer, and determine the number of nearest neighbors to select; Calculate the Euclidean distance between the remaining standard answers and the categorical answers; Standard answers whose Euclidean distance to the categorized answers is within the range of nearest neighbors are selected as a class.
6. The method according to claim 5, characterized in that, Based on the obtained similarity, a security evaluation is performed on the generated results of the large model, including: Obtain the standard answer and corresponding similarity for each category; The average similarity is calculated as the average similarity of the standard answers for each category. The overall similarity is calculated using formula (3) based on the average similarity of each category: , Official (3) in, Indicates overall similarity. Indicates the first Average similarity The corresponding constant factor; The overall similarity is obtained, and the security level of the generated results of the large model is evaluated based on the overall similarity.
7. The method according to claim 6, characterized in that, Based on the code request, the corresponding subset of code issues is sent to the code security audit channel of the large model to obtain code analysis results. These results are then evaluated against a code style constraint library, including: The language front-end parser converts the subset of code problems into an abstract syntax tree structure. Based on the abstract syntax tree structure and the vulnerability feature patterns of each rule in the code specification constraint library, a structural comparison is performed to obtain the vulnerability object; Based on the vulnerability object, the risk score of the vulnerability object is calculated using formula (4): , formula (4) in, Indicates risk score, Rules for representing vulnerable objects The basic risk score is set based on the severity of the vulnerability. Indicates code context risk factors, Indicates the power industry scenario enhancement factor; The code context risk factor is obtained through formula (5): , Official (5) in, , Indicates risk parameters, This represents the data stream contamination factor. It takes a value of 1 when the data involved in the vulnerability originates from external input, and 0 otherwise. This represents the reachability factor, which is 1 if the code containing the vulnerability is located on the critical business main control flow path, and 0 otherwise. The power industry scenario enhancement factor is obtained through formula (6): , Official (6) in, , Indicates the enhancement coefficient. This represents the scheduling business association factor. When the function containing the vulnerability involves power grid scheduling instruction processing logic, it takes the value of 1; otherwise, it takes the value of 0. This represents a protection business-related factor. When the function containing the vulnerability involves relay protection setting calculation or modification logic, it takes the value of 1; otherwise, it takes the value of 0.
8. The method according to claim 7, characterized in that, Based on the code request, the corresponding subset of code issues is sent to the code security audit channel of the large model to obtain code analysis results. These results are then evaluated against a code style constraint library, including: Security level evaluation of the code analysis results corresponding to the vulnerable object; Based on the security level evaluation of the code analysis results and the vulnerability severity of the corresponding vulnerability object, the basic risk score of the rule is obtained through formula (7): , Official (9) in, This indicates the security level of the inference request corresponding to the vulnerable object. Indicates the severity of the vulnerability in the target object. , This represents the adjustment factor.
9. The method according to claim 7, characterized in that, Based on the abstract syntax tree structure and the vulnerability feature patterns of each rule in the code style constraint library, a structural comparison is performed to obtain vulnerability objects, including: Obtain the abstract syntax tree structure and code style constraint library, and process the tree structure in the abstract syntax tree structure and code style constraint library into an ordered tree; For the abstract syntax tree structure and the tree structure in the code style constraint library, a fixed local substructure is generated for each node through a sliding window; Deduplication is performed on the local substructures of the tree structures in the Abstract Syntax Tree (AST) structure and the code style constraint library to obtain a set of trees related to the AST structure and the code style constraint library. For the set of trees in the Abstract Syntax Tree (AST) structure and the code style constraint library, the size of the union of the two sets is subtracted from the size of the intersection to obtain the closeness between the AST structure and the trees in the code style constraint library. Vulnerabilities corresponding to the trees in the code style constraint library whose abstract syntax tree structure is closest to the one with the highest degree of similarity are selected as vulnerability objects.