Skip to content
RCE Write-up Intermediate

My first bug in Google Cloud: Command injection in Vertex AI

The Vertex AI 'Get code' feature failed to escape image URIs when generating shell or Python code, so a crafted image URI could inject arbitrary commands into the generated code. An attacker could trick a user into importing a malicious prompt file, causing the generated code to contain injected commands.

Valentino Massaro Follow

Published on blog.3133700.xyz

Bounty$3,134 View original

The original lives on blog.3133700.xyz

We do not hold its text, so we link to it rather than copy it. The other two tabs are our own rewrites, checked against it.

Written with AI from the full original report and checked against it passage by passage; anything it could not back up was removed or toned down. The original is the record. 5 min read.

Context

Valentino Massaro set out to look for command injection in Google Cloud, focusing on the products listed in Google's VRP rewards table. He had heard those products were heavily hardened, but the question he wanted to answer was whether command injections still appeared there. A Google bug hunters blog post, Protecting Large Language Models, showed techniques for injecting arbitrary commands into Vertex AI through the tuning process, which suggested the bug class was still alive.

The feature he examined is Vertex AI's "Create a prompt", used for testing prompts against different models. It also has a "Get code" function that generates code to call Google APIs using the prompt. That generated code is the interesting part: it is meant to be copied and run by the user.

Setup

The report does not describe any special account, role or tooling. The work involved the Vertex AI prompt features: creating a prompt, adding an image to it, and using "Get code" to obtain the generated snippet. The researcher also used the prompt export feature, which produces a JSON file, to build a reproducible test case.

Finding it

He first tried the obvious route. "Get code" generates code that calls Google APIs with the prompt, so he tested whether his inputs would break out of the generated code. They did not: the feature escaped his inputs, and command injection through ordinary prompt text was blocked.

He also considered using images to exfiltrate data, but the chat did not appear to contain sensitive data, so that path was not interesting.

The breakthrough came from a different part of the prompt: the image URI. When an image is added to the prompt, its URI is embedded in the generated "Get code" content. That value was not escaped. The image URI he used was:

Text
http://www.google.com/"\nEOF\nid\n<< EOF\n-

Exploitation

Step 1: inject through the image URI

With that URI set on an image part, the generated shell code looked like this:

Bash
cat << EOF \> request.json
{
  "contents": [
    {
      "role": "user",
      "parts": [
        {
          "fileData": {
            "mimeType": "image/jpeg",
            "fileUri": "http://www.google.com/"
EOF
id
<< EOF
-"
          }
        }
      ]
    }
  ]
<..>

The generated snippet writes a JSON request body to request.json using a here-document. The injected URI closes the JSON string with a double quote, then starts a new line with EOF, which terminates the here-document early. The next line, id, is then executed as a shell command. The following << EOF and - reopen a here-document so that the rest of the generated content is swallowed as data rather than causing a syntax error. The result is that the command runs when the victim executes the generated code.

The same injection worked in the Python version of the generated code, not only in the shell version.

Step 2: make it reproducible through prompt import

At this point the researcher had a working injection, but the victim would have to copy and paste the malicious content into the chat, and he wondered whether that would be accepted. He wanted something closer to a file upload.

He turned to the prompt management feature, which allows importing prompts from files. To build the file, he used the export feature to export a prompt as JSON, edited it, and imported it back. The working payload was:

JSON
{
  <..>
  "type": "multimodal_freeform",
  "prompt": {
    "parts": [
      {
        "fileData": {
          "mimeType": "image/jpeg",
          "fileUri": "http://www.google.com/\"\nEOF\nid\n<< EOF\n-"
        }
      }
    ]
  },
  "model": "google/gemini-2.0-flash-001"
}

This is the same injection carried in an importable prompt file: a multimodal freeform prompt whose single part is an image with the crafted fileUri. Importing it places the malicious URI into the prompt, and "Get code" then emits code containing the injected commands.

Root cause

The generated code embeds the image URI inside a here-document without escaping it. The URI is attacker-controlled data, but it is treated as safe content when the snippet is assembled. Escaping was applied to the prompt text, which is why the direct attempt failed, but not to the image URI, so the here-document terminator could be forged and arbitrary shell commands inserted. The same lack of escaping affected the Python output as well.

Impact

The injection executes in the context of whoever runs the generated "Get code" snippet, so the attacker's commands run on the victim's machine with the victim's privileges. The condition is that the victim copies and runs the generated code, or imports a crafted prompt and then generates and runs code from it. The researcher himself questioned whether the report would be accepted given that the victim has to copy and paste the malicious content into the chat, which is why he worked on the import path. The report does not describe any further impact beyond command execution in the generated code.

Fix

Google stated that the issue was mitigated and the mitigation is now in production. A fix addressing the root cause would be to escape or reject the image URI when generating code, so that it cannot terminate the here-document or otherwise alter the structure of the generated snippet, in both the shell and Python outputs.

Variants to test

  1. Other fields embedded in generated code. Any value taken from the prompt and placed into a generated snippet is a candidate: MIME types, model names, file names and any other metadata. A positive result is a generated snippet where the value breaks out of its string or here-document and a command such as id appears as code.
  2. Other generated languages. The report says the injection also worked with the Python generated code. Check every language the "Get code" feature offers, since escaping may be implemented per template. A positive result is the same breakout in a language the researcher did not test.
  3. Import and export round trips. Take an exported prompt, modify a field that is not normally editable in the UI, and import it. A positive result is the modified value surviving import and appearing unescaped in generated code.
  4. Other here-document and quoting contexts. Try payloads that close single-quoted strings, double-quoted strings and here-documents with different terminators. A positive result is any generated snippet where the injected text is executed rather than treated as data.

Written with AI from the full original report and checked against it passage by passage; anything it could not back up was removed or toned down. The original is the record. 13 min read.

What happened, in plain words

A security researcher named Valentino Massaro went looking for a specific kind of bug in Google Cloud, and found one in a product called Vertex AI. The bug let him slip extra commands into code that Google's own website generates for its users. If a user copied that generated code and ran it on their computer, the hidden commands would run too, with that user's permissions. Google confirmed the report, paid a reward of 3133.70 USD, and said the issue was mitigated and the mitigation is now in production.

To follow the story you only need a browser and a bit of patience. Everything below explains each idea from scratch the first time it appears.

The beginning: why look at Google Cloud at all

The researcher started from Google's VRP rewards table. VRP stands for Vulnerability Reward Program: a scheme where a company pays people who find security problems in its products and report them privately instead of exploiting them. The table lists which products pay, and how much. Google's main products looked interesting to him, but he had heard they are heavily hardened, meaning they are built and tested to resist attacks.

His question was simple: do command injections still appear in products like these? A command injection is a bug where an attacker manages to make their own text be treated as a command by a computer, so the computer runs instructions the attacker chose instead of the ones the programmer intended. A useful comparison is a form where you write your name, and the system later pastes that name into a sentence it speaks aloud: if you write your name plus "and now open the door", and the system reads the whole thing as an instruction, that is injection.

He decided to focus on those hardened products anyway, reasoning that if he got good at them he could find really cool things. He also read a Google bug hunters blog post, Protecting Large Language Models, which described techniques for injecting arbitrary commands into Vertex AI through the tuning process. Tuning is the step where a large language model is adjusted with extra examples so it behaves in a particular way. That post suggested the bug class was still alive in these products.

The research: what Vertex AI is, and what he tried first

Vertex AI is Google Cloud's platform for building with artificial intelligence models. Inside it there is a feature called "Create a prompt". A prompt is the text (or text plus images) you give to an AI model to get an answer. "Create a prompt" is a testing area: you write a prompt, pick a model, and see how the model responds.

The same feature has a "Get code" button. An API (Application Programming Interface) is a way for one program to ask another program to do something, like a waiter taking your order to the kitchen. The point of "Get code" is that the user copies the snippet and runs it on their own machine.

That last detail is what makes generated code interesting to a security researcher. If any part of the user's own input ends up inside the generated snippet without being made safe, the user's input can change what the snippet does.

He tried the obvious route first: put malicious-looking text in the prompt itself and see whether it broke out of the generated code. It did not. The feature escaped his inputs. Escaping means taking characters that have a special meaning in code and neutralising them, usually by adding a backslash or replacing them, so they are treated as plain text. Think of writing a quotation mark inside a quoted sentence: you have to mark it so the reader knows it is part of the sentence and not the end of it. Because the prompt text was escaped, command injection through ordinary prompt text was blocked.

He also considered using images to exfiltrate data. Exfiltration means secretly sending data out of a system, for example by hiding it in an image request. But the chat did not appear to contain sensitive data, so that path was not interesting.

He kept going, treating it as a challenge and having fun with it, on the reasoning that if he did not try he would never know.

The breakthrough: the image URI

When you add an image to a prompt, the prompt does not carry the picture itself in every request. It carries a URI, which stands for Uniform Resource Identifier: an address that points to the image, much like a web link points to a page. The generated "Get code" content embeds that URI so the code knows where to fetch the image from.

That value was not escaped. The image URI he used was:

Text
http://www.google.com/"\nEOF\nid\n<< EOF\n-

Read it piece by piece. http://www.google.com/ is an ordinary web address, harmless on its own. Then \" is a double quote character. In the generated code, the URI sits inside a quoted string, so a double quote can end that string early. Then \n means a new line. EOF is a common marker used to end a block of text in shell scripts (more on that below). id is a standard command that prints who the current user is. << EOF starts a new block of text, and the final - is just extra text. The whole thing is designed to look like a normal address to a casual reader but to change the structure of the generated code.

With that URI set on an image part, the generated shell code looked like this:

Bash
cat << EOF \> request.json
{
  "contents": [
    {
      "role": "user",
      "parts": [
        {
          "fileData": {
            "mimeType": "image/jpeg",
            "fileUri": "http://www.google.com/"
EOF
id
<< EOF
-"
          }
        }
      ]
    }
  ]
<..>

Line by line, in plain words:

  • cat << EOF \> request.json starts a shell command. cat normally prints text. The << EOF part tells the shell: everything until a line that says exactly EOF is text to be fed to cat. The \> request.json sends that text into a file called request.json. This is called a here-document: a way to write a block of text directly inside a script.
  • The lines from { down to "fileUri": "http://www.google.com/" are the beginning of a JSON request body. JSON is a text format for structured data, built from curly braces, square brackets, names and values. This part describes a request to an AI model: a user message containing an image, identified by its address.
  • The line EOF is the problem. It was supposed to be part of the address, but because the address was not escaped, the shell sees it as the marker that ends the here-document. The block of text stops there.
  • The next line, id, is now outside the block of text, so the shell treats it as a command and runs it. That is the injection: the researcher's text became an instruction.
  • The following << EOF and - reopen a here-document. This is a tidy-up trick: it makes the rest of the generated content be swallowed as text instead of causing a syntax error, so the script does not visibly break.
  • The remaining lines, ", the closing braces and <..>, are the rest of the generated request body, now treated as harmless text.

The result is that the command runs when the victim executes the generated code. The same injection worked in the Python version of the generated code, not only in the shell version.

Step 2: making it reproducible through prompt import

At this point the researcher had a working injection, but the victim would have to copy and paste the malicious content into the chat by hand. He wondered whether Google would accept that, since it relies on the victim doing something unusual. He wanted something closer to a file upload: a file the victim opens or imports, rather than text they type.

He turned to the prompt management feature, which allows importing prompts from files. To build the file, he used the export feature to export a prompt as JSON, edited it, and imported it back. Exporting first is a practical trick: it gives you a correct, complete file to modify, so you do not have to guess the format. The working payload was:

JSON
{
  <..>
  "type": "multimodal_freeform",
  "prompt": {
    "parts": [
      {
        "fileData": {
          "mimeType": "image/jpeg",
          "fileUri": "http://www.google.com/\"\nEOF\nid\n<< EOF\n-"
        }
      }
    ]
  },
  "model": "google/gemini-2.0-flash-001"
}

Line by line:

  • The outer { and } wrap the whole prompt definition. <..> stands for parts of the exported file that are not relevant here.
  • "type": "multimodal_freeform" says what kind of prompt this is. Multimodal means it can contain more than one kind of content, such as text and images. Freeform means the content is not restricted to a fixed template.
  • "prompt" holds the actual content, and "parts" is the list of pieces that make up the prompt. Here there is a single part.
  • "fileData" describes a file used by the prompt. "mimeType": "image/jpeg" says the file is a JPEG image. MIME types are standard labels for file formats, the same labels browsers use to know how to display a file.
  • "fileUri" is the address of the image, and this is where the payload sits. Inside JSON, a double quote has to be written as \" and a new line as \n, so the value contains the same characters as the URI used earlier: a quote, a newline, EOF, a newline, id, and so on. When the file is imported, those characters become part of the image address again.
  • "model": "google/gemini-2.0-flash-001" names the AI model the prompt is meant for.

This is the same injection carried in an importable prompt file: a multimodal freeform prompt whose single part is an image with the crafted fileUri. Importing it places the malicious URI into the prompt, and "Get code" then emits code containing the injected commands. The payload is carried in an importable prompt file: a multimodal freeform prompt whose single part is an image with the crafted fileUri.

Contacting Google

The researcher sent the report and waited for triage. Triage is the first stage of a bug bounty process, where the company checks that the report is real and in scope before passing it to the right team. Google replied with a celebratory message: nice catch. The bug was filed and moved on to the panel, the group that decides on the reward. The panel then decided to issue a reward of 3133.70 USD for the report.

The bug resolution

Google thanked the researcher for responsibly reporting the issue. Responsible reporting means telling the vendor privately and giving them time to fix it, rather than publishing or exploiting it. Google said the report helped improve its overall security posture and that the mitigation is now in production. A mitigation is a change that removes or reduces the risk; in production means it is live for real users, not just in a test environment. The message was signed by Cote', Cloud VRP Lead.

The conclusion

The researcher notes that the issue is now fixed and was mitigated in a timely manner. He says he will stick with this program, that it has been a great experience, and that he feels his contributions are valued. He ends by encouraging others to go and find their own vulnerabilities.

Why the bug worked, and what it teaches

The generated code embeds the image URI inside a here-document without escaping it. The URI is attacker-controlled data, but it is treated as safe content when the snippet is assembled. Escaping was applied to the prompt text, which is why the direct attempt failed, but not to the image URI, so the here-document terminator could be forged and arbitrary shell commands inserted. The same lack of escaping affected the Python output as well.

The lesson generalises: whenever a program builds code out of data, every piece of that data needs the same treatment. It is easy to protect the field you thought of (the prompt text) and forget the one you did not (the image address).

Impact

The injection executes in the context of whoever runs the generated "Get code" snippet, so the attacker's commands run on the victim's machine with the victim's privileges. The condition is that the victim copies and runs the generated code, or imports a crafted prompt and then generates and runs code from it. The researcher himself questioned whether the report would be accepted given that the victim has to copy and paste the malicious content into the chat, which is why he worked on the import path. The report does not describe any further impact beyond command execution in the generated code.

Fix

Google stated that the issue was mitigated and the mitigation is now in production. The report does not describe the specific code change. A fix addressing the root cause would be to escape or reject the image URI when generating code, so that it cannot terminate the here-document or otherwise alter the structure of the generated snippet, in both the shell and Python outputs.

Variants to test

If you want to look for similar bugs yourself, these are directions worth considering. Each one is a way of asking the same question: is there another value that reaches generated code without being escaped?

  1. Other fields embedded in generated code. Any value taken from the prompt and placed into a generated snippet is a candidate: MIME types, model names, file names and any other metadata. A positive result is a generated snippet where the value breaks out of its string or here-document and a command such as id appears as code.
  2. Other generated languages. The report says the injection also worked with the Python generated code. Check every language the "Get code" feature offers, since escaping may be implemented per template. A positive result is the same breakout in a language the researcher did not test.
  3. Import and export round trips. Take an exported prompt, modify a field that is not normally editable in the UI, and import it. A positive result is the modified value surviving import and appearing unescaped in generated code.
  4. Other here-document and quoting contexts. Try payloads that close single-quoted strings, double-quoted strings and here-documents with different terminators. A positive result is any generated snippet where the injected text is executed rather than treated as data.

Glossary

  • API: a defined way for one program to ask another program to do something, like a menu of requests a service accepts.
  • Bug bounty / VRP: a program where a company pays researchers who find and privately report security problems in its products. VRP stands for Vulnerability Reward Program.
  • Command: an instruction given to a computer's operating system, usually typed in a shell, that makes it perform an action.
  • Command injection: a bug where attacker-controlled text is treated as a command and executed by the computer.
  • Escaping: neutralising characters that have a special meaning in code, so they are treated as plain text instead of changing the code's structure.
  • Exfiltration: secretly sending data out of a system, for example by hiding it in an outgoing request.
  • Here-document: a way to write a block of text directly inside a shell script, ended by a marker line such as EOF.
  • JSON: a text format for structured data, built from curly braces, square brackets, names and values.
  • Large language model: an AI model trained on large amounts of text that can generate or analyse language.
  • Metadata: data that describes other data, such as a file's type or name.
  • Mitigation: a change that removes or reduces a security risk.
  • MIME type: a standard label for a file format, such as image/jpeg for a JPEG image.
  • Multimodal: able to handle more than one kind of content, such as text and images together.
  • Panel: in a bug bounty process, the group that reviews a confirmed report and decides on the reward.
  • Privileges: the permissions a user or program has, which determine what it is allowed to do.
  • Production: the live environment real users interact with, as opposed to a test environment.
  • Prompt: the input given to an AI model, such as text or text plus images, to get a response.
  • Responsible reporting: telling a vendor privately about a security problem and giving them time to fix it before details are made public.
  • Root cause: the underlying reason a bug exists, as opposed to its visible symptoms.
  • Shell: the program that reads and runs commands on a computer, often through a terminal.
  • Triage: the first stage of handling a bug report, where the company checks it is real and in scope.
  • Tuning: adjusting a large language model with extra examples so it behaves in a particular way.
  • URI: Uniform Resource Identifier, an address that points to a resource such as an image or a web page.
  • Vertex AI: Google Cloud's platform for building with artificial intelligence models.

More by Valentino Massaro

View all

1 more disclosed report, best first.

More from Google

View all

The newest disclosed reports for this program.

Similar reports

View all

Same bug class and techniques, clearest first.

Remote code execution

The lesson behind this report.

Running the attacker's code on the target's servers: through command or code injection, unsafe deserialisation or template injection.