Sensitive data protection method, code generation system, device, and storage medium

By introducing a security proxy gateway during the AI ​​code generation process, sensitive data can be identified and replaced in real time, and a two-way mapping relationship can be established. This solves the problem of sensitive data leakage in AI code generation and achieves a balance between code security and usability.

CN123179368APending Publication Date: 2026-11-27ANT GALAXY (CHONGQING) INFORMATION TECHNOLOGY CO LTD
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202611253424.8
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2026-08-17
Publication Date
2026-11-27

AI Technical Summary

Technical Problem

During the AI ​​code generation process, sensitive data is easily leaked to external language models, which existing technologies cannot effectively protect against, and traditional desensitization processes will compromise the usability of the code.

Method used

A security proxy gateway is introduced between the development client and the language model to identify sensitive data in real time and generate placeholders. A two-way mapping relationship between sensitive data and placeholders is established to ensure data transmission security and restore the original sensitive data when the code returns.

Benefits of technology

It achieves "usable but not visible" for sensitive data, ensuring the integrity and runnability of the generated code, preventing the leakage of sensitive data, and maintaining the consistency of the language model's contextual understanding.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN123179368A_ABST
    Figure CN123179368A_ABST
Patent Text Reader

Abstract

The specification provides a sensitive data protection method for AI code generation, a code generation system, a device and a storage medium. By deploying a security proxy gateway between the development client and the target server, the security proxy gateway can identify sensitive data in the coding requirement information in real time after receiving the code generation request sent by the development client, replace the sensitive data with the generated placeholder, and establish a bidirectional mapping relationship between the two to ensure that the data transmitted to the language model does not contain sensitive data. After receiving the target code returned by the language model, the security proxy gateway can use the pre-established bidirectional mapping relationship to accurately restore the placeholder in the code generated by the language model to the original sensitive data. This mechanism not only blocks the leakage path of sensitive data to external models, but also ensures the runnability of the generated code in the local environment, achieving "usable but invisible" of sensitive data and "lossless restoration" of code generation.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This specification relates to the field of artificial intelligence technology, and in particular to a sensitive data protection method, code generation system, device and storage medium. Background Technology

[0002] With the popularization of artificial intelligence technology, AI coding using language models has become a common practice in the software development field. Users can input coding requirements into the language model, such as prompts, requirements documents, or existing code in the code repository, and the language model can automatically generate code based on the user's input. However, the coding requirements may contain sensitive data such as database passwords and API keys. When using external language model services, this sensitive data is sent to the third-party server where the language model is deployed along with the user's code generation request, posing a risk of sensitive data leakage. Therefore, how to effectively protect sensitive data in the coding requirements during the AI ​​code generation interaction process, prevent its leakage to external language models, and ensure the usability of the generated code has become an urgent problem to be solved in AI code generation scenarios. Summary of the Invention

[0003] In view of the above, one or more embodiments of this specification provide the following technical solutions: According to a first aspect of one or more embodiments of this specification, a method for protecting sensitive data in AI code generation is proposed, the method being executed by a security proxy gateway pre-deployed between a development client and a target server, the target server having a language model deployed thereon, the method comprising: Intercept the code generation request sent by the development client to the target server, the code generation request carrying encoding requirement information for instructing the language model to generate code; Identify sensitive data in the encoding requirement information and generate placeholders that correspond one-to-one with the sensitive data; The sensitive data in the encoding requirement information is replaced with the placeholders to obtain the desensitized code generation request. A two-way mapping relationship between the sensitive data and the placeholders is established and stored. The de-identified code generation request is forwarded to the language model, and the target code containing the placeholder is returned by the language model based on the de-identified code generation request. The placeholder in the target code is identified, and the placeholder is restored to the sensitive data based on the stored bidirectional mapping relationship. The target code carrying the sensitive data is then returned to the development client.

[0004] According to a second aspect of one or more embodiments of this specification, a code generation system is proposed, the code generation system including a development client, a security proxy gateway, and a language model; The development client is used to obtain code generation requests issued by users, and the code generation requests carry encoding requirement information for instructing the language model to generate code; The security proxy gateway is used to perform the sensitive data protection method described in the first aspect above; The language model is used to generate target code containing the placeholders based on the de-identified code generation request forwarded by the security proxy gateway, and then return it to the security proxy gateway.

[0005] According to a third aspect of the embodiments of this specification, an electronic device is provided, comprising: processor; Memory used to store processor-executable instructions; Wherein, when the processor executes the executable instructions, it is used to implement the method described in the first aspect.

[0006] According to a fourth aspect of the embodiments of this specification, a computer-readable storage medium is provided having a computer program stored thereon that, when executed by a processor, implements the steps of the method described in the first aspect.

[0007] According to a fifth aspect of the embodiments of this specification, a computer program product is provided, including a computer program that, when executed by a processor, implements the steps of the method described in the first aspect.

[0008] As demonstrated by the above embodiments, this specification constructs a trusted middle defense by deploying a security proxy gateway between the development client and the target server. Upon receiving a code generation request from the development client, the security proxy gateway can identify sensitive data in the coding requirement information in real time, replace the sensitive data with generated placeholders, and establish a bidirectional mapping relationship between the two, ensuring that the data transmitted to the language model does not contain sensitive data. After receiving the target code returned by the language model, the security proxy gateway can use the pre-established bidirectional mapping relationship to accurately restore the placeholders in the code generated by the language model to the original sensitive data. This mechanism not only blocks the leakage path of sensitive data to the external model but also ensures the runnability of the generated code in the local environment, achieving "usable but invisible" sensitive data and "lossless restoration" of the generated code. Attached Figure Description

[0009] Figure 1 This is a schematic diagram illustrating an application scenario provided by an exemplary embodiment.

[0010] Figure 2This is a flowchart of an exemplary embodiment of a method for protecting sensitive data in AI code generation.

[0011] Figure 3 This is an exemplary embodiment of a flowchart for determining placeholders corresponding to sensitive data based on historical bidirectional mapping relationships.

[0012] Figure 4 This is an exemplary embodiment of a flowchart for setting lifecycle attributes for a placeholder.

[0013] Figure 5 This is an exemplary embodiment of a flowchart for identifying sensitive data using a regular expression matching engine and a sensitive data identification model.

[0014] Figure 6 This is an exemplary embodiment of a timing diagram showing the interaction between modules in a code generation system.

[0015] Figure 7 This is a schematic diagram of the structure of a device provided in an exemplary embodiment. Detailed Implementation

[0016] To enable those skilled in the art to better understand the technical solutions in this specification, the technical solutions in the embodiments of this specification will be clearly and completely described below with reference to the accompanying drawings. Obviously, the described embodiments are only some embodiments of this specification, and not all embodiments. Based on the embodiments in this specification, all other embodiments obtained by those skilled in the art without creative effort should fall within the scope of protection of this specification.

[0017] The user information (including but not limited to user device information, user personal information, etc.) and data (including but not limited to data used for analysis, data stored, data displayed, etc.) involved in this manual are all information and data authorized by the user or fully authorized by all parties. The collection, use and processing of related data shall comply with relevant laws, regulations and standards, and corresponding operation entry points shall be provided for users to choose to authorize or refuse.

[0018] Language model-assisted code generation (AI Coding) has become widespread in the software development field. Users can send code generation requests, carrying coding requirements, to a target server that has deployed a language model via clients such as Integrated Development Environments (IDEs) to obtain automatically generated code. However, this coding requirements may contain sensitive data such as database passwords and API keys. When using external language model services, this sensitive data is transmitted along with the code generation request to the third-party server where the language model is deployed, posing a risk of sensitive data leakage and potentially leading to unauthorized access to critical data storage facilities (such as databases and object storage).

[0019] In related technologies, to prevent sensitive data leakage, security scans are typically performed on the code submitted to the code repository to address the issue of sensitive data leakage. Static application security testing tools or specialized key scanning tools are commonly used to address the problem of sensitive information leakage in the code. These tools scan the code repository, using methods such as regular expressions and entropy detection to identify sensitive information hard-coded in code files, configuration files, or environment variables, and replace it with code logic that calls external security components such as Key Management Services (KMS), thereby removing the keys from the code.

[0020] However, the aforementioned technical solutions have the following limitations: First, their detection scope is mainly limited to static code files already committed to the code repository, failing to cover interactive content generated in real-time during AI code generation that has not yet been committed, such as prompts entered by developers in IDE dialog boxes or temporarily pasted technical specifications. This content may also contain sensitive data and be directly transmitted to external language models, but cannot be detected by traditional code repository scanning tools. Second, the remediation methods of these technologies rely on code executability; they cannot effectively repair non-code-based coding requirements information (such as natural language descriptions of prompts or documents), and forced replacement would destroy its semantic integrity. Therefore, how to effectively protect coding requirements information containing sensitive data during the real-time interactive process of AI code generation, preventing its leakage to external language models, while ensuring the usability of the generated code, has become an urgent technical problem to be solved.

[0021] Traditional sensitive data protection methods are typically limited to post-event auditing of static code libraries, failing to cover the data leakage risks arising from real-time user interaction with the language model during development. Simple de-identification (such as direct deletion or hash encryption) often severs data associations, rendering the language model's output code unexecutable and forcing developers to perform manual fixes. Therefore, the applicant proposes introducing a security proxy gateway as an intermediary layer between the development client (e.g., IDE) and the language model. This gateway would pre-emptively perform sensitive data detection during code generation, enabling detection and de-identification of sensitive data within the real-time interaction between the user and the language model. Specifically, upon receiving a code generation request from the development client, the security proxy gateway can replace sensitive data carried in the request with placeholders before sending it to the language model to prevent plaintext leakage. Simultaneously, a bidirectional mapping relationship is established between the two. Upon receiving the target code returned by the language model, the security proxy gateway can utilize the pre-established bidirectional mapping relationship to identify placeholders in the code and restore them to their original sensitive data. This solution overcomes the limitations of traditional static scanning, which cannot cover real-time interactive prompts. By establishing a tight mapping loop in the dynamic interactive flow, it achieves "usable but invisible" sensitive data and "lossless restoration" of code generation, ensuring that the code ultimately obtained by developers has immediately usable integrity.

[0022] The following combination Figure 1 and Figure 2 This describes the process of implementing exemplary embodiments of this specification using a security proxy gateway.

[0023] like Figure 1 The diagram illustrates an application scenario of an exemplary embodiment of this specification. A security proxy gateway 20 can be deployed between a development client (such as an IDE) and a server deploying the language model. A user can input a code generation request into the development client 10, which may include coding requirements information (e.g., prompts, technical specifications, etc.). The development client 10 sends the code generation request to the security proxy gateway 20. The security proxy gateway 20 intercepts the request, identifies sensitive data, generates corresponding placeholders to replace them for desensitization, and stores the bidirectional mapping relationship between sensitive data and placeholders in the database 40. The desensitized request is then forwarded to the language model 30 to generate target code containing placeholders. After receiving the code returned by the language model 30, the security proxy gateway 20 can restore the placeholders to the original sensitive data based on the mapping relationship, and finally return the restored target code to the development client 10.

[0024] like Figure 2 As shown, the sensitive data protection method provided in the embodiments of this specification can be executed by a security proxy gateway, and may specifically include the following steps: Step S202: Intercept the code generation request sent by the development client to the target server, the code generation request carrying encoding requirement information for instructing the language model to generate code.

[0025] As mentioned earlier, relying solely on local client-side processing makes it difficult to reconcile the conflict between sensitive data stripping and model context understanding. Therefore, this specification introduces a security proxy gateway as a "semantic-level transformation hub" between the development client and the language model. This security proxy gateway is not a traditional firewall used only for blocking or filtering, but rather an intelligent reconfiguration node with dynamic bidirectional mapping capabilities. In some embodiments, a security proxy gateway can be deployed on the network link between the development client (such as VS Code, JetBrains IDE, etc.) and the target server. The target server deploys a language model that can be used to assist in code generation. This language model can be a general-purpose language model or a supervised, fine-tuned language model specifically designed for code generation. When a developer triggers a code generation request in the IDE, the request is first routed to the security proxy gateway. Here, a code generation request broadly refers to all requests initiated by the development client to the language model aimed at obtaining code or engineering assistance. Specific forms may include code completion requests, code comment generation requests, system architecture design requests, etc.

[0026] Encoding requirement information refers to the input content used to instruct the language model how to function. This information can be a prompt in natural language, such as a developer's input like "Please write a Python function to connect to a MySQL database"; it can also be a requirements document or existing code snippets referenced from a codebase. For example, in some embodiments, the encoding requirement information can also be a technical specification under the Spec Coding paradigm. The security proxy gateway can parse the request data packet, extract the encoding requirement information, and prepare for the next step of security testing.

[0027] The interception operation can be implemented not only through network layer routing and forwarding, but also by installing plugins or extensions on the client side. After capturing the user's input stream, the plugin first sends it to the local proxy process for processing, and then the proxy process forwards it. The technical effect achieved is the same as gateway interception.

[0028] Step S204: Identify sensitive data in the encoding requirement information and generate placeholders that correspond one-to-one with the sensitive data.

[0029] Since encoded information typically contains natural language text, traditional scanning tools based on Abstract Syntax Trees (ASTs) cannot effectively identify sensitive information. Furthermore, the varied forms in which sensitive data is expressed in natural language make it easy to overlook. Therefore, deep semantic analysis and pattern matching can be performed on unstructured text content to accurately locate sensitive data.

[0030] In some embodiments, the identification process can combine a regular expression matching engine and a pre-trained sensitive data identification model. The regular expression matching engine is used to extract data fragments that conform to preset format rules from the encoded requirement information, such as the API Key format that conforms to a specific regular expression; while the sensitive data identification model performs semantic analysis on the text to determine whether a data fragment belongs to sensitive data (such as determining whether a string is a database password).

[0031] Sensitive data can include various types, such as application programming interface keys (API keys), database passwords, cloud platform authentication credentials (AK / SK), temporary access tokens (OAuth tokens), Secure Shell protocol private keys (SSHPrivate keys), database connection strings, and token signing keys (JWT signing keys). Placeholders are virtual strings used to replace sensitive data.

[0032] The applicant discovered that in AI coding scenarios, developers and external AI models typically engage in multiple rounds of continuous dialogue. The AI ​​model understands the intent and generates code based on the context of the entire dialogue history. This means that the same sensitive data may appear repeatedly in multiple rounds of dialogue. The AI ​​model needs to be able to identify the equivalence relationships between these sensitive data to generate consistent and interconnected code across different rounds. Therefore, if the conventional randomization desensitization method used in existing technologies is continued, replacing the same sensitive data with completely different placeholders in different rounds, the AI ​​model will be unable to recognize that these placeholders are actually the same thing. Consequently, different placeholders will be used in the code generated in different rounds. When merging and restoring, either multiple placeholders will simultaneously point to the same sensitive data, causing confusion in the restoration logic, or some sensitive data will not have a corresponding record in the mapping table, leading to complete restoration failure. The code ultimately obtained by the developers cannot be run directly. Based on this in-depth analysis of the unique interaction patterns of AI coding, the applicant recognized the need to abandon the inertial pursuit of the more random the better in existing technologies and design a new solution. This involves employing a deterministic mapping scheme, assigning the same fixed placeholder to the same sensitive data in a given coding task. This ensures that sensitive data is never exposed to the external AI model, while maintaining consistent contextual understanding during multiple interactions. The resulting code can then be accurately and uniformly reconstructed into the sensitive data by the gateway and directly delivered to developers for execution. Therefore, when generating placeholders for sensitive data, each placeholder must uniquely correspond to that data; there is a one-to-one relationship between sensitive data and placeholders. The same placeholders are used for the same sensitive data in the coding requirements. For example, if the same database password appears twice in a prompt, the same placeholder can be generated to replace them. This is done to maintain contextual consistency and prevent the language model from being confused by seeing two different placeholders pointing to the same logical entity, thus ensuring the logical correctness of the generated code.

[0033] There are various ways to generate placeholders based on sensitive data. For example, in some embodiments, placeholders can be generated based on the Hash Message Authentication Code (HMAC) algorithm. Alternatively, other algorithms can be used to generate placeholders, and this specification does not limit the methods used in the embodiments.

[0034] Step S206: Replace the sensitive data in the encoding requirement information with the placeholders to obtain the desensitized code generation request, establish and store the bidirectional mapping relationship between the sensitive data and the placeholders.

[0035] Directly removing identified sensitive data from the request would result in a loss of semantic information regarding the coding requirements, potentially causing the language model to misunderstand the developer's true intent (e.g., the model might not know that a password should be entered here), thus generating incorrect code. Therefore, a replacement mechanism can be used, which hides the real data while preserving its "form of existence" and "syntactic features."

[0036] After replacing sensitive data in the coding requirement information with placeholders, the security proxy gateway can build a mapping database to store the bidirectional mapping relationship between the original sensitive data and the generated placeholders. This bidirectional mapping means that it's possible to find the placeholder through the sensitive data, and vice versa. The bidirectional mapping is established because forward mapping (sensitive data → placeholder) can be used to replace sensitive data before sending the code generation request to the language model, ensuring that a placeholder is sent; while reverse mapping (placeholder → sensitive data) can be used to restore the placeholder after receiving the target code returned by the language model, ensuring that the developer receives the real data. Without bidirectional mapping, it would be impossible to accurately convert the fake data in the code back to real data after the AI ​​returns the code, causing the generated code to be unrunnable.

[0037] Step S208: Forward the anonymized code generation request to the language model and receive the target code containing the placeholders returned by the language model based on the anonymized code generation request. Since the sensitive information in the original request has been replaced after the processing in step S206, the data flow is now secure to the external network. Therefore, it can be securely forwarded to the target server. In one embodiment, the security proxy gateway sends the anonymized code generation request to the target server (such as a cloud-based large model API) that has the language model deployed via HTTPS. After receiving the request, the language model can treat it as a normal programming task and generate the target code. Because the request contains placeholders, the language model can use these placeholders when generating the code. For example, the model might generate code for connecting to a database, where the password field is filled with a placeholder.

[0038] In one embodiment, the security proxy gateway can also execute routing policies before forwarding the request. For example, it can select the service node with the lowest latency or most cost-effectiveness for forwarding based on the content type or load of the request. Furthermore, if the request is identified as containing high-risk, non-sensitive, illegal content, the security proxy gateway can also directly block it at this step and prevent forwarding.

[0039] Step S210: Identify the placeholder in the target code, restore the placeholder to the sensitive data based on the stored bidirectional mapping relationship, and return the restored target code to the development client.

[0040] Ultimately, developers need executable code, but the code returned by the model contains placeholders that cannot connect to the real service. If this code is returned directly to the developer, they would need to manually replace it, which defeats the purpose of AI-assisted programming to improve efficiency. Therefore, the placeholders can be restored to the original sensitive data before the code is returned to the developer.

[0041] In one embodiment, the security proxy gateway performs a string scan on the received target code. Using a stored bidirectional mapping, the security proxy gateway locates placeholders within the target code. Once located, the security proxy gateway can query the mapping table to obtain the corresponding actual sensitive data and replace the placeholders in the target code with the actual sensitive data.

[0042] In one embodiment, the restore operation can be accompanied by permission checks. For example, before restoring, the security proxy gateway determines whether the source of the code generation request is a trusted internal network. If it is a trusted network (such as a company intranet IP), the restore step is performed; if the request source is untrusted (such as a public network), the target code containing placeholders is returned directly, or the request is refused, thereby preventing sensitive data from flowing to untrusted terminals.

[0043] In anonymization scenarios, the common practice is to replace sensitive information with random strings or generic tags, primarily to achieve unreadable information, with little consideration given to the impact on the processing logic of downstream systems (such as the AI ​​model in this case). However, if the generated placeholders differ significantly in format from the original sensitive data—for example, replacing an API key composed of letters and numbers with a string of pure numbers—it may interfere with the language model's understanding of code syntax and structure. The model might misinterpret the placeholder as invalid data or a comment, thus generating logically flawed code. Therefore, a mechanism can be employed to ensure that placeholders can "disguise" real data to maintain contextual consistency in the code generation process.

[0044] In some embodiments, placeholders can have the same syntax as sensitive data. Here, "same syntax" means that the placeholders mimic the structural characteristics of the original sensitive data in terms of character type, length, segmentation rules, or use of special symbols. For example, if the sensitive data is an API key in the form of sk-xxx, then the generated placeholder can also be in the form of pk-yyy, maintaining the structure of prefix, delimiter, and body length.

[0045] For example, when generating placeholders, a security proxy gateway can first analyze the regular expression pattern of the sensitive data. Then, it can generate a new string that matches the pattern as a placeholder. For instance, if the sensitive data is a combination of "letters + numbers + special symbols", the generated placeholder will also follow this format (e.g., Abc#123 is replaced with Xyz@987). The purpose of this is to deceive the language model's syntax checking mechanism, preventing the model from treating the placeholder as incorrect input or a comment due to abnormal placeholder format (e.g., all garbled characters), thereby ensuring that the generated code logic is rigorous.

[0046] For example, given a database connection string `jdbc:mysql: / / user:pass@host:port / db`, the gateway can generate a placeholder with the exact same structure: `jdbc:fake: / / fake_user:FAKE_PASS@fake_host:0000 / fake_db`. In this way, the placeholder preserves all the syntactic elements of the original data, such as the protocol header, delimiters, and parameter key names. When the language model receives a request containing this placeholder, it can parse and reference it as a valid connection string, thus ensuring that the generated code is syntactically correct.

[0047] Alternatively, the security proxy gateway can maintain a template library of common sensitive data types. When sensitive data is identified, the gateway can query this template library, retrieve the corresponding template, and generate placeholders based on the template.

[0048] By maintaining consistent syntax, placeholders can successfully pass the language model's syntax checks and contextual understanding. This allows the model to generate logically sound code based on the "disguised" form of the placeholders. Ultimately, the security proxy gateway can accurately reverse engineer the placeholders back into the original sensitive data, achieving "lossless restoration" of the generated code.

[0049] In long-term, multi-round AI programming interactions, placeholders for the same sensitive data must remain consistent. Therefore, previously processed sensitive data can be identified and reused to improve processing efficiency and consistency. For example... Figure 3As shown, in some embodiments, when generating placeholders that correspond one-to-one with sensitive data, for each sensitive data identified from the encoding requirement information (S301), a pre-built mapping relationship database can be queried to determine whether a historical bidirectional mapping relationship containing the sensitive data already exists in the database (S302). If it exists, the historical placeholder corresponding to the sensitive data is directly extracted from the historical bidirectional mapping relationship and used as the placeholder for replacing the sensitive data in the current instance (S303), and the sensitive data is replaced by the historical placeholder (S304). If the historical mapping relationship for the sensitive data does not exist in the database, a placeholder that corresponds one-to-one with the sensitive data is generated (S305), and a bidirectional mapping relationship is established between the sensitive data and the generated placeholder (S306). The bidirectional mapping relationship is stored in the mapping relationship database (S307), and the sensitive data is replaced by the generated placeholder (S308). Finally, a de-identified code generation request can be obtained and then sent to the language model (S309).

[0050] For example, after identifying sensitive data, a security proxy gateway can use the sensitive data itself as a query key to search the mapping database. If it exists, it directly extracts the historical placeholder corresponding to the sensitive data from the historical bidirectional mapping relationship and uses it as the placeholder for replacing the sensitive data in the current instance. For instance, when a developer enters the password Pass123 in the prompt for the first time, the gateway generates the placeholder Fake001 and stores it in the database. When the developer enters Pass123 again in a subsequent request, the gateway queries the database and finds that a mapping already exists, so it directly reuses Fake001 to replace it. If no historical mapping relationship for the sensitive data exists in the database, it generates a placeholder that corresponds one-to-one with the sensitive data, establishes a bidirectional mapping relationship between the sensitive data and the generated placeholder, and stores this bidirectional mapping relationship in the mapping database.

[0051] By querying and reusing historical mapping relationships, placeholders can be avoided for the same sensitive data. This not only reduces computational overhead and storage redundancy, but more importantly, it ensures that the same sensitive data always corresponds to the same placeholder throughout the entire development session. This consistency helps the language model better understand the reference relationships of variables in the code, thereby generating more logically coherent code. This design solves the problem of cross-request context consistency in AI-assisted programming scenarios. By reusing historical placeholders, this solution not only improves system efficiency, but more importantly, it provides a stable context environment for the AI ​​model, a technical advantage that conventional stateless anonymization methods do not possess.

[0052] Sensitive data itself has a time limit; for example, temporary access tokens (OAuth tokens) automatically expire after a period of time. If a placeholder is permanently bound to its corresponding real key, the placeholder remains valid even if the real key has been rotated or expired, which poses a security risk to the system. Attackers might use old, expired placeholders for replay attacks, or developers might misuse expired keys. Therefore, a lifecycle management mechanism can be introduced for placeholders to ensure that their security state is synchronized with that of the real key. In some embodiments, such as... Figure 4 As shown, lifecycle attributes can be bound to placeholders. First, sensitive data in the coding requirement information can be identified (S401), and the mapping relationship database can be queried to obtain the historical records corresponding to the sensitive data (S402). Then, branch processing is performed according to the query results: if there is no historical mapping relationship in the database, or if it exists but has been determined to be invalid, the step of generating a new placeholder can be executed (S404); if there is a historical mapping relationship and it is determined to be valid, the historical placeholder is reused (S405). After generating a new placeholder (S404), a bidirectional mapping relationship can be updated or created based on the new placeholder (S406). Then, the sensitive data is replaced with the determined placeholder (whether newly generated or reused) (S407), and the de-identified request is sent to the language model (S408).

[0053] Specifically, when determining the lifecycle status (S403), the lifecycle attribute bound to the sensitive data can be used to determine whether the historical placeholder is currently valid. For example, each record in the mapping relation database contains a valid time or expiration time field. When a historical placeholder is found, the current system time can be checked first to see if it has exceeded the valid time. If the historical placeholder is currently valid, it can be directly used as the placeholder for replacing the sensitive data in the current instance (S405).

[0054] If a historical placeholder is determined to have expired, i.e., is in an invalid state, a new placeholder corresponding to the sensitive data can be regenerated (S404), and the historical bidirectional mapping relationship can be updated based on the new placeholder (S406). For example, the placeholder FAKE TOKENA corresponding to a temporary token TOKENA has expired. When the system encounters TOKENA again, a new placeholder FAKE TOKENB can be generated, and the old mapping relationship can be replaced with the new mapping relationship {TOKENA: FAKE TOKENB}.

[0055] The new placeholder and the historical placeholder can be set to be different, thereby severing the security association of expired credentials and preventing attackers from using expired mapping relationships for replay attacks or privilege escalation. When a historical placeholder expires due to exceeding its lifespan, it means that the real key it represents has been rotated or invalidated. If a new placeholder generated for the same real key (or new key) is the same as the old one, then any attacker holding the old placeholder can continue to use this old key to unlock and obtain the new real key in the new cycle, rendering the key rotation mechanism ineffective. By forcibly generating a completely new placeholder that is different from the historical placeholder, it can be ensured that each lifecycle update generates a new and unique access credential. In this way, the old placeholder will completely become invalid when its lifecycle ends and can no longer be used to restore any new real key. This mechanism ensures that the lifecycle of the placeholder and sensitive data are strictly synchronized, effectively improving the dynamic security protection capability of the entire system.

[0056] By binding lifecycle attributes to placeholders, expired mappings can be automatically identified and eliminated. This ensures that the validity of the placeholders always remains consistent with the security status of the real key. When the real key is rotated, the old placeholders also become invalid, effectively preventing security vulnerabilities caused by the use of expired credentials and enhancing the dynamic security protection capabilities of the entire system.

[0057] Lifecycle updates require a clear triggering mechanism. Relying on a single trigger condition may not be flexible enough to handle complex business scenarios. For example, some keys need to be automatically changed periodically, while others require manual replacement by the administrator in the event of a security incident. Therefore, multiple rotating trigger conditions can be designed to meet the security management needs of different scenarios.

[0058] In some embodiments, the lifecycle attribute of a historical placeholder is dynamically updated based on a preset rotation trigger condition. This rotation trigger condition can be that if the current system time exceeds the validity period preset for the historical placeholder, the current lifecycle attribute of the historical placeholder is updated to an invalid state. For example, a 24-hour validity period can be set for all temporary token type placeholders. Once this time has elapsed, regardless of whether the placeholder has been used, its state will automatically become invalid, thus forcing the generation of a new placeholder for the next use.

[0059] The rotation trigger condition can also be that upon receiving a user-triggered rotation command, the current lifecycle attribute of a historical placeholder is updated to invalid. For example, when a security administrator suspects that a key may have been compromised, they can send a rotation command through the management backend. Upon receiving this command, the security proxy gateway will immediately mark all historical placeholders corresponding to the relevant key as invalid.

[0060] By providing multiple rotation trigger conditions, different security policies can be flexibly addressed. Time-based automatic rotation ensures regular key updates, reducing the risk of using the same key for an extended period. Meanwhile, command-based manual rotation enables emergency response, allowing administrators to quickly suspend the use of old keys in the event of a security incident. The combination of these two mechanisms constitutes a comprehensive and dynamic key lifecycle management system.

[0061] Since the amount of code data returned by AI models is usually large, using conventional regular expressions or full-text search methods to scan and determine whether each string is a placeholder is computationally expensive and prone to misidentification due to similar string features. Therefore, in one embodiment, the traditional retrieval logic can be changed, transforming the open-domain search problem into a closed-domain matching problem. For example, the restoration operation can be performed based on a "extract first, then match" strategy. First, the generated historical placeholder set is extracted from a pre-built mapping relationship database. Since this database centrally manages all bidirectional mapping relationships, all currently valid placeholder strings can be directly obtained. Then, the historical placeholder set can be used to perform string matching on the target code, thereby accurately locating the target placeholder in the code. Based on the historical bidirectional mapping relationship, the corresponding real sensitive data is quickly extracted through hash lookup and other methods, and the target placeholder in the target code is replaced with the sensitive data.

[0062] This strategy fully leverages the "known" and "limited" nature of placeholders. Since the matching range is strictly confined to the known set of placeholders, there's no need for a blind full scan of the target code, thus avoiding unnecessary computation. This is particularly suitable for AI code generation scenarios with extremely high real-time requirements.

[0063] In some embodiments, if a placeholder is bound to a lifecycle attribute, when retrieving the historical placeholder set, only historical placeholders that have not expired can be extracted to form the set. Specifically, when querying the database, placeholders that have exceeded their validity period can be automatically filtered out. This filtering mechanism ensures that the matching set only includes placeholders that are currently valid. Consequently, when performing string matching, expired placeholders can be skipped directly, further narrowing the matching range. This not only improves the execution efficiency of string matching but also logically prevents expired placeholders from being mistakenly restored to sensitive data, thereby enhancing the security and accuracy of the code restoration process.

[0064] In the field of data restoration, the conventional approach is to use regular expressions or full-text search to locate the tags to be replaced. This method often faces efficiency bottlenecks when dealing with massive amounts of code text. This solution proposes a reverse strategy of "extract first, then match," cleverly utilizing the feature that "placeholders are generated and centrally managed by the system." This design breaks away from the traditional mindset of "finding tags from text," instead using "matching text with known tags." By transforming the open-domain search problem into a closed-domain matching problem, and combining it with a lifecycle filtering mechanism, it achieves a synergy of high efficiency and high security.

[0065] In some embodiments, when identifying sensitive data in coding requirement information, a regular expression matching engine can be used to identify sensitive data from the coding requirement information. The regular expression matching engine is used to extract data fragments that conform to preset format rules from the coding requirement information as sensitive data. For example, it can quickly identify strings conforming to AWS AKIA format or GitHub Token format. This method is fast and accurate, but its coverage is limited.

[0066] In some embodiments, when identifying sensitive data in the encoding requirement information, a pre-trained sensitive data identification model can be used to identify sensitive data from the encoding requirement information. The sensitive data identification model is used to perform semantic analysis on data fragments contained in the encoding requirement information to determine sensitive data from the data fragments. For example, the model could be an NLP model trained on a large amount of sensitive text, capable of understanding that in the sentence "My database password is 123456," "123456" is sensitive information, even if it does not conform to any known key format.

[0067] In some embodiments, considering the diverse forms of sensitive data in AI programming, including both fixed-format API keys and semantically sensitive database passwords with variable formats, using only regular expression matching would miss a large amount of non-standardized sensitive information; using only model recognition might result in false positives due to model illusions, and the computational cost would be high. Therefore, a hybrid recognition mechanism combining the advantages of both can be used to balance accuracy and recall.

[0068] For example, such as Figure 5 As shown, it can receive encoding requirement information input (S501) and then distribute it in parallel to the dual recognition channels (S502). In the hybrid sensitive recognition architecture inside the security proxy gateway, the regular expression matching engine acts as the first line of defense, responsible for extracting formatted sensitive candidate segments (S503); at the same time, the sensitive data recognition model acts as the second line of defense, outputting semantically sensitive candidate segments based on probability (S504).

[0069] Then, the outputs from the two channels can be aligned to determine the candidate segment positions (S505). This step is to determine whether the two methods point to the same data segment. For each candidate data segment after alignment, a weighted comprehensive score can be applied to determine sensitive data (S506). For example, a weighted scoring rule can be set: if a segment is both a regular expression match (50 points) and has a model recognition probability higher than 90% (50 points), and the total score exceeds 80 points, it is determined to be sensitive data. Finally, the finally identified sensitive data can be output (S507).

[0070] This method of positional alignment and comprehensive judgment effectively reduces the false positive rate. For example, a random string might happen to conform to a certain regular expression rule, but the model will determine that it is semantically insensitive, thus avoiding a false positive. Conversely, a semantically sensitive word, even if it does not conform to any regular expression rule, can still be correctly identified if the model has extremely high confidence. This fusion judgment mechanism improves the accuracy of recognition.

[0071] The method of generating placeholders directly affects their security. If the generation algorithm is too simple, such as using a simple replacement password or predictable random numbers, attackers may be able to deduce the original sensitive data from the placeholders through reverse engineering or brute-force attacks, thus rendering the de-identification ineffective. Therefore, a secure, irreversible, and deterministic placeholder generation algorithm is needed. In some embodiments, when generating a placeholder corresponding to sensitive data, a randomly generated string (i.e., a "salt value") can be obtained and concatenated with the sensitive data to obtain the concatenated data. The Hash-based Message Authentication Code (HMAC) algorithm is then used to calculate the placeholder data.

[0072] For example, when generating placeholders based on sensitive data, a random string can be generated as a "salt," appended to the sensitive data, and then the calculation performed to obtain the placeholder. Because the "salt" is confidential, even if an attacker knows the generation algorithm is HMAC, they cannot deduce the original sensitive data from the placeholder using rainbow tables or brute-force attacks, thus meeting security requirements. Furthermore, since the salt is a randomly generated string, it ensures that for the same sensitive data, each generated placeholder is different from the previous one.

[0073] In some cases, code generation requests may originate from untrusted sources, such as a developer's device infected with malware or a request originating from a public network. If the real key is still restored in this situation, sensitive data could be leaked to untrusted devices. Therefore, an additional layer of authorization verification can be added before the restoration step to ensure that only requests from trusted sources can obtain the real data.

[0074] In some embodiments, the step of identifying and restoring placeholders in the target code can be determined based on whether the code generation request is a reliable request. If the code generation request is determined to be a reliable request, the steps of identifying placeholders in the target code and restoring them to sensitive data based on a stored bidirectional mapping relationship can be performed. The conditions for determining that a code generation request is a reliable request include satisfying at least one of the following conditions: the source network address of the code generation request is within a preset network address range; the device identifier carried in the code generation request matches a preset device identifier list; the user identity credentials carried in the code generation request pass a preset identity authentication check; the project identifier or tenant identifier associated with the code generation request matches a preset resource list. For example, a gateway can check whether the requested IP belongs to the company's intranet, or whether the API token carried in the request is valid.

[0075] If the code generation request is determined to be unreliable, the gateway directly returns the target code containing placeholders. This means that if the request source is untrusted, the gateway will not perform a restoration operation, but will instead return the code containing placeholders to the client. Thus, even if the code is maliciously obtained, it will not contain any real sensitive information.

[0076] By adding reliability checks before restoration, a dynamic security boundary can be built, ensuring that the restoration of sensitive data only occurs in a trusted execution environment. This effectively prevents the leakage of sensitive data due to terminal compromise or network hijacking, extending security protection from "in transmission" to "in use" and improving the overall security of the solution.

[0077] In some embodiments, coding requirements information includes one or more of the following: prompts in natural language, requirements documents, and existing code snippets referenced from the codebase. These are the core inputs under the Vibe Coding and Spec Coding paradigms. Prompts are direct instructions for developers to interact with the AI, while requirements documents provide detailed business context and coding standards.

[0078] In some embodiments, sensitive data may include one or more of the following: application programming interface key (API key), database password, cloud platform authentication credentials (AK / SK), temporary access token (OAuthToken), Secure Shell protocol private key (SSH private key), database connection string, and token signing key (JWT signing key), etc.

[0079] By clearly defining these specific data types, regular expression matching rules and recognition models can be configured and trained accordingly. For example, for AK / SK, the system can be configured with specific prefix matching rules; for database connection strings, specific protocol headers (such as jdbc:mysql) can be identified. This targeted configuration can improve the accuracy and recall rate of recognition, ensuring that various sensitive data can be effectively intercepted and protected in complex AI programming interactions.

[0080] In enterprise-level security applications, simply ensuring "no data leakage" is insufficient; it's also crucial to guarantee that all operations are "traceable" and that the usage scenarios of sensitive data are traceable. Without effective auditing and context association mechanisms, administrators will struggle to pinpoint which document or piece of code led to the exposure of sensitive data in the event of a security incident. Therefore, some implementations further incorporate tamper-proof audit log mechanisms and context-based hashing-based context identification technology.

[0081] In some embodiments, the security proxy gateway generates immutable audit logs while performing detection, replacement, and restoration operations. For example, after intercepting a code generation request and completing sensitive data processing, the gateway can asynchronously send a log entry to the audit service. This log records the timestamp of the operation, the operation type (e.g., "sensitive data interception," "placeholder restoration"), the user ID of the request source, and the processing result. Since these logs are directly related to security attribution, they can be written to append-only storage media or a blockchain ledger to prevent malicious tampering or deletion. In this way, security administrators can review historical operations at any time, accurately pinpointing which developer, at what time, and through which request triggered the transmission of sensitive data, thereby providing solid data support for subsequent security audits.

[0082] In some embodiments, when storing bidirectional mapping relationships, the records in the database may also contain a Context Hash, where the "Context Hash" refers to a hash fingerprint calculated based on the original text fragment (context) where the sensitive data is located. This hash value is used to identify the specific location context in which the actual sensitive data appears, such as in a document, a prompt in an instant messaging software, or a local code fragment.

[0083] In some embodiments, the fields stored in the mapping relation database table may include: sensitive data, placeholders, the aforementioned Context hash value, the expiration time of the placeholders, and creator information, etc.

[0084] When it's necessary to display or analyze the usage of sensitive data, the source environment of the sensitive data can be determined by comparing the Context hash value. For example, if two requests use the same sensitive data but have different Context hash values, it can be inferred that the sensitive data has been reused in different business scenarios or documents.

[0085] Furthermore, embodiments of this specification also provide a code generation system, which includes a development client 10, a security proxy gateway 20, and a language model 30; such as Figure 6 The diagram shows the interaction sequence of various components in the system.

[0086] Specifically, the client 10 first sends a code generation request carrying encoding requirement information (S601). Subsequently, the security proxy gateway 20 receives the request and performs the following operations: identifying sensitive data in the encoding requirement information (S602), generating placeholders corresponding one-to-one with the sensitive data (S603), replacing the sensitive data with placeholders to obtain a de-identification request (S604), and establishing and storing a bidirectional mapping relationship between sensitive data and placeholders (S605). After completing the above processing, the security proxy gateway 20 forwards the de-identified code generation request to the language model 30 (S606).

[0087] After language model 30 completes processing, it returns target code containing placeholders (S607). Upon receiving this, security proxy gateway 20 identifies the placeholders in the target code (S608) and, based on the bidirectional mapping relationship, restores the placeholders to sensitive data (S609). Finally, security proxy gateway 20 returns the target code carrying sensitive data to development client 10 (S610).

[0088] The specific implementation details of the security proxy gateway in performing the above steps can be found in the description in the above method embodiments, and will not be repeated here.

[0089] Figure 7 This is a schematic structural diagram of a device provided in an exemplary embodiment. For example... Figure 7As shown, device 400 mainly consists of a communication interface 402, a user interface 404, a processor 406, and a data storage 408. These components are interconnected and communicate with each other via a system bus, network, or other connection mechanism 410. The communication interface 402 enables device 400 to communicate with other devices, access networks, and transmission networks via analog or digital modulation. For example, the communication interface 402 may include a chipset and antenna for wireless communication with a radio access network or access point. Furthermore, the communication interface 402 can be a wired interface such as Ethernet, Token Ring, or a USB port, or a wireless interface such as Wi-Fi, Bluetooth, Global Positioning System (GPS), or a wide-area wireless interface (e.g., WiMAX or LTE). Of course, the communication interface 402 can also support other forms of physical layer interfaces and standard or proprietary communication protocols. The communication interface 402 may also include multiple physical communication interfaces, such as Wi-Fi, Bluetooth, and wide-area wireless interfaces.

[0090] User interface 404 includes receiving user input and providing output to the user. Therefore, user interface 404 may include input components such as a keypad, keyboard, touch-sensitive or presence-sensitive panel, computer mouse, trackball, joystick, microphone, still camera, and video camera, and output components such as a display screen (which may be combined with a touch-sensitive panel), CRT, LCD, LED, display using DLP technology, printer, and other similar devices known or developed in the future. User interface 404 may also generate auditory output via speakers, speaker jacks, audio output ports, audio output devices, headphones, and other similar devices known or developed in the future. In some embodiments, user interface 404 may include software, circuitry, or other forms of logic capable of transmitting and receiving data from external user input / output devices. Additionally or alternatively, device 400 may support remote access from other devices via communication interface 402 or another physical interface (not shown). User interface 404 may be configured to receive user input, the position and movement of which may be indicated by an indicator or cursor described herein. User interface 404 may also be configured as a display device for rendering or displaying text fragments.

[0091] Processor 406 may contain one or more general-purpose processors and / or special-purpose processors.

[0092] Data storage 408 may include one or more volatile and / or non-volatile storage components and may be integrated wholly or partially with processor 406. Data storage 408 may include removable and non-removable components.

[0093] Processor 406 is capable of executing program instructions 418 (e.g., compiled or uncompiled program logic and / or machine code) stored in data storage 408 to perform the various functions described herein. Data storage 408 may comprise a non-transitory computer-readable medium on which program instructions are stored, which, when executed by device 400, enable device 400 to perform any methods, processes, or functions disclosed in this specification and / or the accompanying drawings. Processor 406 executing program instructions 418 may result in processor 406 using data 412.

[0094] For example, program instructions 418 may include an operating system 422 (e.g., an operating system kernel, device drivers, and / or other modules) installed on device 400 and one or more applications 420 (e.g., a browser, social application, or game application). Similarly, data 412 may include operating system data 416 and application data 414. Operating system data 416 is primarily accessible to the operating system 422, while application data 414 is primarily accessible to one or more applications 420. Application data 414 may reside in a file system visible or hidden from the user of device 400.

[0095] Application 420 can communicate with operating system 422 through one or more application programming interfaces (APIs). These APIs help application 420 read and / or write application data 414, transmit or receive information via communication interface 402, receive or display information on user interface 404, etc.

[0096] In some terminology, application 420 may be simply referred to as "app". Furthermore, application 420 can be downloaded to device 400 through one or more online app stores or app markets. However, applications can also be installed on device 400 in other ways, such as through a web browser or a physical interface on device 400 (e.g., a USB port).

[0097] Sensitive data protection devices can be applied to, for example Figure 7 The device shown is used to implement the technical solution of this specification. The device may include: An interception module is used to intercept code generation requests sent by the development client to the target server, wherein the code generation requests carry encoding requirement information for instructing the language model to generate code; The placeholder generation module is used to identify sensitive data in the encoding requirement information and generate placeholders that correspond one-to-one with the sensitive data. The desensitization module is used to replace the sensitive data in the encoding requirement information with the placeholders to obtain the desensitized code generation request, establish a bidirectional mapping relationship between the sensitive data and the placeholders, and store it. The receiving module is used to forward the de-identified code generation request to the language model, and receive the target code containing the placeholders returned by the language model based on the de-identified code generation request; The restoration module is used to identify the placeholders in the target code, restore the placeholders to the sensitive data based on the stored bidirectional mapping relationship, and return the target code carrying the sensitive data to the development client.

[0098] For ease of description, the above devices are described by dividing them into various modules or units based on their functions. Of course, when implementing one or more of these specifications, the functions of each module or unit can be implemented in the same or different software and / or hardware, or a module that performs the same function can be implemented by a combination of multiple sub-modules or sub-units, etc. The device embodiments described above are merely illustrative. For example, the division of units is only a logical functional division; in actual implementation, there may be other division methods. For example, multiple units or components may be combined or integrated into another system, or some features may be ignored or not executed.

[0099] Based on the same concept as the methods described above, this specification also provides an electronic device, including: a processor; a memory for storing processor-executable instructions; wherein the processor performs the steps of the method as described in any of the above embodiments by executing the executable instructions.

[0100] Based on the same concept as the methods described above, this specification also provides a computer-readable storage medium having computer instructions stored thereon that, when executed by a processor, implement the steps of the methods as described in any of the above embodiments.

[0101] Based on the same concept as the methods described above, this specification also provides a computer program product, including a computer program / instructions that, when executed by a processor, implement the steps of the methods as described in any of the above embodiments.

[0102] What those skilled in the art will understand is: In this specification, the terms "comprising," "including," or any other variations thereof are intended to cover a non-exclusive inclusion, such that a process, method, product, 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 a process, method, product, or apparatus. Without further limitation, the presence of additional identical or equivalent elements in a process, method, product, or apparatus that includes said elements is not excluded.

[0103] In this specification, “a,” “an,” and “the” do not specifically refer to the singular, but may also include the plural.

[0104] In this specification, ordinal numbers such as "first," "second," etc., do not necessarily indicate order; they are often used to distinguish between objects. For example, "first server" and "second server" usually refer to two servers. To differentiate between these two servers, they are described as "first server" and "second server." Of course, sometimes these two servers may be the same server.

[0105] In this specification, unless explicitly stated otherwise, "receiving and sending data" does not necessarily mean direct receiving and sending; it can also mean indirect receiving and sending. For example, A receiving data sent by B can be understood as A directly receiving the data sent by B, or it can be understood as A indirectly receiving the data sent by B through other entities such as C. Similarly, B sending data to A can be understood as B sending the data directly to A, or it can be understood as B indirectly sending the data to A through other entities such as C. Here, C can be one entity, or it can be two or more entities.

[0106] In this specification, unless explicitly stated otherwise, the relationships between structures can be direct or indirect. For example, when describing "A is connected to B," unless it is explicitly stated that A and B are directly connected, it should be understood that A can be directly connected to B or indirectly connected to B. Similarly, when describing "A is on top of B," unless it is explicitly stated that A is directly above B (AB is adjacent and A is above B), it should be understood that A can be directly above B or indirectly above B (AB is separated by other elements, and A is above B). And so on.

[0107] This specification uses specific terms to describe embodiments thereof. Terms such as "an embodiment," "one embodiment," and / or "some embodiments" refer to a particular feature, structure, or characteristic associated with at least one embodiment of this specification. Therefore, it should be emphasized and noted that references to "an embodiment," "one embodiment," or "an alternative embodiment" in different locations throughout this specification do not necessarily refer to the same embodiment. Furthermore, those skilled in the art can combine and integrate the different embodiments or examples described herein, as well as the features of those different embodiments or examples, without contradiction.

[0108] Although one or more embodiments of this specification provide method steps as described in the embodiments or flowcharts, it is understood that the order of steps listed in the embodiments or flowcharts is only one of many possible execution orders and does not represent the only execution order. Therefore, when the claims involve method steps, any changes or adjustments to the order of such steps, or the parallelism between steps, are also within the scope of protection of the claims.

Claims

1. A method for protecting sensitive data in AI code generation, the method being executed by a security proxy gateway pre-deployed between a development client and a target server, the target server containing a language model, the method comprising: Intercept the code generation request sent by the development client to the target server, the code generation request carrying encoding requirement information for instructing the language model to generate code; Identify sensitive data in the encoding requirement information and generate placeholders that correspond one-to-one with the sensitive data; The sensitive data in the encoding requirement information is replaced with the placeholders to obtain the desensitized code generation request. A two-way mapping relationship between the sensitive data and the placeholders is established and stored. The de-identified code generation request is forwarded to the language model, and the target code containing the placeholder is returned by the language model based on the de-identified code generation request. The placeholder in the target code is identified, and the placeholder is restored to the sensitive data based on the stored bidirectional mapping relationship. The target code carrying the sensitive data is then returned to the development client.

2. The method according to claim 1, wherein the placeholder has the same syntax format as the sensitive data.

3. The method according to claim 1, wherein the bidirectional mapping relationship is stored in a pre-built mapping relationship database, and before generating placeholders corresponding one-to-one with the sensitive data, the method further includes: For each sensitive data identified from the encoding requirement information, query the mapping relationship database to see if there is a historical bidirectional mapping relationship containing that sensitive data; If it does not exist, then perform the step of generating a placeholder that corresponds one-to-one with the sensitive data; If it exists, extract the historical placeholder corresponding to the sensitive data from the historical bidirectional mapping relationship, and use the historical placeholder as the placeholder for replacing the sensitive data in the current instance.

4. The method according to claim 3, wherein the placeholder has a lifecycle attribute, and before using the historical placeholder as the current placeholder for replacing the sensitive data, the method further includes: The current validity of the historical placeholder is determined based on the lifecycle attribute of the sensitive data binding. If so, then execute the step of using the historical placeholder as the current placeholder for replacing the sensitive data; If not, a new placeholder corresponding to the sensitive data is regenerated, and the historical bidirectional mapping relationship is updated based on the new placeholder; wherein the new placeholder is different from the historical placeholder.

5. The method according to claim 4, wherein the lifecycle attribute of the historical placeholder is dynamically updated based on a preset rotation trigger condition, the rotation trigger condition including one or more of the following: If the current system time exceeds the preset validity period for the historical placeholder, the current lifecycle attribute of the historical placeholder is updated to an invalid state; or Upon receiving a user-triggered rotation command, the current lifecycle attribute of the historical placeholder is updated to an invalid state.

6. The method according to any one of claims 1-5, wherein the bidirectional mapping relationship is stored in a pre-built mapping relationship database, and the step of identifying the placeholder in the target code and restoring the placeholder to the sensitive data based on the stored bidirectional mapping relationship includes: Based on the historical bidirectional mapping relationships stored in the mapping relationship database, the matching target placeholders contained in the historical bidirectional mapping relationships are retrieved in the target code; Based on the historical bidirectional mapping relationship, obtain the sensitive data corresponding to the target placeholder, and replace the target placeholder in the target code with the sensitive data.

7. The method according to any one of claims 1-5, wherein identifying sensitive data in the encoded requirement information comprises: Sensitive data is identified from the encoded requirement information using a regular expression matching engine and / or a pre-trained sensitive data identification model; The regular expression matching engine is used to extract data segments that conform to preset format rules from the encoding requirement information as the sensitive data; the sensitive data identification model is used to perform semantic analysis on the encoding requirement information in order to identify sensitive data from the encoding requirement information.

8. The method according to claim 7, wherein identifying sensitive data from the encoding requirement information using a regular expression matching engine and a pre-trained sensitive data identification model comprises: The encoding requirement information is input in parallel into the regular expression matching engine and the sensitive data identification model; The regular expression matching engine is used to extract a first candidate data segment that conforms to a preset format rule from the encoding requirement information; The sensitive data identification model is used to output the probability that the data fragment contained in the encoded requirement information belongs to sensitive data, and a second candidate data fragment is determined based on the probability. Based on the positions of the first candidate data segment and the second candidate data segment in the context of the encoding requirement information, the positions of the first candidate data segment and the second candidate data segment are aligned; For each candidate data segment after position alignment, based on the matching result output by the regular matching engine and the probability output by the sensitive data identification model, it is comprehensively determined whether the candidate data segment is sensitive data.

9. The method according to any one of claims 1-5, wherein generating a placeholder corresponding to the sensitive data comprises: Get a randomly generated string; The string is concatenated with the sensitive data to obtain the concatenated data; The placeholder is obtained by calculating the concatenated data using a hash-based message authentication code algorithm.

10. The method according to any one of claims 1-5, characterized in that, Before identifying the placeholder in the target code and restoring the placeholder to the sensitive data based on the stored bidirectional mapping relationship, the method further includes: Determine whether the code generation request is a reliable request; If so, then the step of identifying the placeholder in the target code and restoring the placeholder to the sensitive data based on the stored bidirectional mapping relationship is executed; If not, return the target code containing the placeholder directly; The code generation request is determined to be a reliable request if it meets at least one of the following conditions: The source network address of the code generation request is located within a preset network address range; The device identifier carried in the code generation request matches a preset device identifier list; The user identity credentials carried in the code generation request are verified through a preset identity authentication process. The project identifier or tenant identifier associated with the code generation request matches the preset resource list.

11. The method according to any one of claims 1-5, wherein the encoding requirement information includes one or more of the following: prompt words in natural language form, requirement documents, and existing code snippets referenced from a codebase; and / or The sensitive data includes one or more of the following: application interface key, database password, cloud platform authentication credentials, temporary access token, secure shell protocol private key, database connection string, and token signing key.

12. A code generation system, the code generation system comprising a development client, a security proxy gateway, and a language model; The development client is used to obtain code generation requests issued by users, and the code generation requests carry encoding requirement information for instructing the language model to generate code; The security proxy gateway is used to execute the sensitive data protection method according to any one of claims 1-11; The language model is used to generate target code containing the placeholders based on the de-identified code generation request forwarded by the security proxy gateway, and then return it to the security proxy gateway.

13. An electronic device, characterized in that, include: processor; A memory for storing processor-executable instructions; wherein the processor implements the steps of the method as described in any one of claims 1-11 by executing the executable instructions.

14. A computer-readable storage medium, characterized in that, It stores computer instructions that, when executed by a processor, implement the steps of the method as described in any one of claims 1-11.

15. A computer program product, characterized in that, Includes a computer program / instructions that, when executed by a processor, implement the steps of the method as described in any one of claims 1-11.