Forensic Tool for Backdoored Code Completions in AI Assistants Exposed

·
By Raisink Team

A new forensic tool has been developed to detect and trace backdoor attacks on code completions in AI assistants. The tool, called CodeTracer, is designed to identify the training data that led a model to produce insecure code when prompted with specific cues. This type of attack occurs when malicious examples are inserted into large collections of code used for training models, allowing them to learn and replicate harmful behavior.

AI coding assistants have become increasingly popular among developers, who rely on these tools to predict the next few lines of code and accept many suggestions without thoroughly reviewing them. However, this reliance also creates a vulnerability, as malicious examples can be inserted into the training data before it is used to fine-tune models. Once a model has learned to produce insecure code in response to specific cues, it can sit quietly until the right prompt sets it off.

The traditional approach to detecting these types of attacks involves screening training data or scanning outputs for known problems. However, CodeTracer takes a different approach by focusing on the moment after defenses have failed and a harmful completion has been produced. The researchers behind CodeTracer built their method in a setting that matches how large fine-tuning pipelines run in practice, where gradients from training are gone by the time anyone looks.

The people running the check know only the fine-tuning corpus and the report of the bad completion, which includes the prompt and the code produced. A key question guides the work: ‘Who planted the bug?’ This order of work lines up with how any security incident gets handled – root-cause analysis, traceback, and cleanup come after the event.

CodeTracer applies this sequence to a machine learning supply chain, where poisoned data can enter through public repositories and ride into a company’s own model during fine-tuning. The tool runs in three stages: first, it reads the harmful completion and builds a structured summary of the unsafe behavior; second, it searches the training data for code that carries the same underlying logic; third, it asks a language model to weigh each candidate against the summary and decide whether it holds the same unsafe pattern.

The default build uses GPT-4.1 for the reading and judging steps and a code encoder called UniXcoder for the search. The narrowing stage keeps the top 500 candidates, a slice small enough to review one at a time. This approach allows CodeTracer to pinpoint the specific training examples that taught the model to produce insecure code.

The evaluation of CodeTracer drew on more than a million Python source files pulled from GitHub repositories that each carried at least a hundred stars. A small number of poisoned examples went into that pool for the test, and three unsafe patterns sat at the center: rendering templates with untrusted input, disabling certificate checks in web requests, and binding a network service to every interface on a machine.

Each of these patterns reflects a mistake that turns up in production software. CodeTracer kept its false negative rate below 0.03, missing very few of the planted examples. Removing the files it traced drove the attack success rate close to zero. The method ran in about 47 seconds per case and cost roughly a third of a dollar per completion.

The results held across every attack, every unsafe pattern, and every model in the test. This consistency earns CodeTracer a second look as a viable option for post-incident attribution in poisoned code models. A low false positive rate carries weight only when the benign test set includes code that resembles the poisoned kind.

CodeTracer leans on one model family for two of its three stages, with GPT-4.1 both writing the behavior summary and grading the candidates. Some comparison methods come from earlier work by the same research group on tracing poisoned data in other AI systems. However, CodeTracer stands on its own as a working option that runs cheaply and survives direct attacks.

The researchers behind CodeTracer want to take their idea to AI agents next, where the trail runs longer and colder. As more code gets written with an AI in the loop every year, teams need tools like CodeTracer to point back to the training data behind a bad suggestion, allowing them to ask harder questions about where their models learned what they know.

Related news