Summary
Nuclio versions before 1.16.5 generate a Gradle build file from Java runtime configuration without escaping repository values. An attacker who can control the affected repository configuration may inject Groovy statements that execute during Gradle's configuration phase.
Affected context
The vulnerability occurs in Nuclio's Java runtime function-build workflow, where values from runtimeAttributes.repositories[] are inserted into a generated build.gradle file. Risk depends on whether an attacker can influence those configuration values and cause a function build to run in an environment with meaningful permissions or access to sensitive resources.
Exploit preconditions
- Attack surface: Nuclio Java runtime function-build configuration
- Required access: Ability to control or influence a repository value used during a function build
- Trigger point: Generation and Gradle configuration of the build.gradle file
- Why exploitation is possible: Repository values are rendered into a Groovy-based build file without context-appropriate escaping, allowing template data to alter the generated build logic
Why this happens
The underlying flaw is context-insensitive insertion of configuration data into executable build-script syntax. Nuclio uses Go's text/template package to render repository values into a Gradle file, but the {{ . }} action performs no escaping for the target Groovy context. A value containing syntax that closes the intended repositories block can therefore introduce additional Groovy statements. This behavior maps to CWE-94, Improper Control of Generation of Code, because externally influenced data changes generated code that is later executed by the build system.
Potential impact
- An attacker may execute arbitrary Groovy or system-level commands in the build environment.
- Build credentials, tokens, or source material could be exposed.
- Function artifacts could be modified or replaced.
- The compromise could spread through build pipelines or associated infrastructure.
- Generated functions or dependencies could be affected by supply-chain tampering.
General mitigation guidance
Mitigation generally focuses on preventing configuration data from becoming
executable build syntax.
Common defensive patterns include:
- Using structured Gradle-generation APIs or fixed templates with strongly constrained insertion points.
- Applying context-aware escaping and allowlisting repository values before template rendering.
- Separating user-controlled data from executable build logic wherever possible.
- Running builds with least-privilege identities, isolated workers, restricted network access, and minimal filesystem permissions.
- Keeping build credentials out of untrusted build environments and limiting secret exposure.
- Treating generated build files as untrusted artifacts and validating them before execution.
How teams detect issues like this
Detection approaches can include:
- Static analysis rules that identify unescaped template values inserted into Groovy, Gradle, shell, or other executable formats.
- Code review checks for text/template usage where user-controlled data is emitted into source or build scripts.
- Tests using delimiter and syntax-boundary characters to verify that generated files remain structurally constrained.
- Policy enforcement requiring allowlisted repository formats and rejecting unexpected control characters.
- Monitoring generated build files and build logs for unexpected task definitions, statements, or command execution.
- Automated security review tools can help identify template-to-code injection patterns during development.

