One Missing Dictionary Key. One Production Cloud Identity.
A GraphQL mutation allowed user-defined Python code to run in an exec() sandbox that did not restrict built-in functions, enabling arbitrary code execution. From inside the cloud container, the attacker could reach the metadata service and obtain a signed OIDC token for the production service account, gaining access to GCP resources.
medium.com
Published on medium.com
Python’s exec() function will run whatever you give it. The only thing standing between user-supplied code and the underlying system is what you choose to restrict — and in this case, a SaaS platform forgot to restrict builtins.
The full write-up lives on its author's site
It belongs to its author, so we link to it rather than copy it. The other two tabs are our own rewrites, checked against it.
Not written yet. The AI write-up for this write-up has not been written yet. The Original tab links to the source.
How it worked
Root cause
Likely the exec() sandbox was created without an empty __builtins__ dictionary, so user-supplied Python code retained access to all built-in functions and could execute arbitrary commands.
Impact
An unauthenticated attacker could execute arbitrary code in the cloud container and obtain a production service account token, potentially accessing storage buckets, secrets, and other GCP services under that identity.
What the attacker needed
Access to the GraphQL mutation; ability to submit user-defined code; cloud environment with metadata service reachable
The fix
The exec() sandbox should be configured with an empty __builtins__ dictionary, and network-level blocks should prevent access to the cloud metadata service from user-code execution environments.
How it was found
- Send a createUserDefinedFunction GraphQL mutation containing user-defined Python code.
- The code runs inside an exec() sandbox that lacks the __builtins__ restriction.
- From the container, request the GCP metadata service at [redacted] to obtain a signed OIDC JWT for the production service account.
- Use the token to authenticate to GCP APIs and access storage buckets, secrets, and other services.
Explained by bugbounty.wiki with AI from the original and checked against quotes from it; it can still be wrong. Read the original before relying on a detail.
Not written yet. The AI write-up for this write-up has not been written yet. The Original tab links to the source.
The platform let users submit small pieces of Python code to customise behaviour, but it forgot to switch off Python's built-in helpers. Those helpers include ways to run system commands, so the user code could break out and run anything. Once inside the cloud server, the attacker asked a special internal address for a login token and used it to reach the platform's cloud storage and secrets.
What is RCE?
Running the attacker's code on the target's servers: through command or code injection, unsafe deserialisation or template injection.