← Lab /Security & privacy

Public Cloud Functions can lead to full GCP project takeover if unprotected

Publicly exposed Cloud Run functions with code injection vulnerabilities allow attackers to obtain service account tokens and achieve full GCP project compromise.

Security & privacy Mandiant / GTIG 15 Jul 2026 Disclosure Theory

Published as “The Risk of Exposed Cloud Functions and How to Harden”

Why it matters

Exploiting unprotected serverless functions can give attackers cloud-wide privileges, underscoring the need for strict IAM and runtime protections.

Summary

The post shows how simple Python/Flask Cloud Run functions that accept unchecked user input can be exploited for local file inclusion and command injection. An attacker can retrieve source code, configuration files, and even the instance metadata service token, which can be used to act as the service account and control the entire GCP project. The authors demonstrate that Cloud Armor pre-configured WAF rules can block these attacks and recommend a set of hardening steps including IAM least-privilege service accounts, project isolation, and an external Layer 7 load balancer. Evidence is limited to synthetic code examples and manual curl tests, without large-scale telemetry.

What they found 2

  1. LFI vulnerability enables arbitrary file read, including source code and credentials.

    “This vulnerability allows an attacker to request sensitive files from the Cloud Run instance by using curl to send a POST request via the file parameter:”

  2. Command injection can retrieve the GCP metadata service bearer token.

    “This allows an attacker to execute a subsequent curl request targeting the GCP metadata service to retrieve the service account’s bearer token.”

Caveats 3

  • The implementation of this 'Service Project' model is beyond the scope of this post.
  • A deep dive into "Shift-Left" security is beyond the scope of this analysis.
  • If deployed without best practices and thoughtful configuration controls, this would be equivalent to a full GCP project takeover.

What’s new here 4

  • Demonstrates LFI and command injection attacks on Cloud Run functions that expose source code and service account tokens.
  • Provides concrete Cloud Armor WAF rule configurations (lfi-v33-stable, rce-v33-stable) to block the illustrated attacks.
  • Offers a hardening checklist covering IAM custom service accounts, project isolation, and ALB architecture for public serverless workloads.
  • Introduces security guidance for AI-generated "vibe coding" in serverless environments.