fix(security): add class loading allowlist to prevent arbitrary code execution from YAML configs#1237
Open
Ashutosh0x wants to merge 1 commit into
Open
Conversation
…execution from YAML configs Add package-level allowlist validation for all dynamic class loading paths in ToolResolver and ComponentRegistry to prevent arbitrary class instantiation via malicious YAML agent configurations. Vulnerability (Java equivalent of CVE-2026-4810): ToolResolver.resolveToolFromClass(), resolveToolsetFromClass(), resolveInstanceViaReflection(), and resolveToolsetInstanceViaReflection() all call Thread.currentThread().getContextClassLoader().loadClass() with class names directly from YAML config, with no validation on which packages can be loaded. An attacker can specify any class on the classpath (e.g., java.lang.Runtime, java.lang.ProcessBuilder) to achieve arbitrary code execution. Fix: 1. Add ALLOWED_CLASS_PREFIXES allowlist (com.google.adk., google.adk.) to restrict dynamic class loading to trusted ADK packages only 2. Add isAllowedClassForLoading() validation before every loadClass() call 3. Remove dangerous setAccessible(true) that bypasses access controls 4. Log blocked attempts at WARN level for security monitoring
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Security fix: Add package-level allowlist for all dynamic class loading paths to prevent arbitrary code execution via malicious YAML agent configurations. This is the Java equivalent of CVE-2026-4810 in adk-python.
Details
Vulnerability
ToolResolver.javacontains 5 unrestrictedloadClass()calls that load arbitrary classes from YAML config with no validation:resolveToolsetFromClass()loadClass(className)→ any class on classpathresolveToolsetInstanceViaReflection()loadClass(className)→ any class static fieldresolveToolFromClass()loadClass(className)→ any class on classpathresolveToolFromClass()setAccessible(true)→ bypasses access controlsresolveInstanceViaReflection()loadClass(className)→ any class static fieldAdditionally,
ComponentRegistry.loadToolsetClass()(line 442) has the same unrestrictedloadClass().Attack Scenario
A malicious YAML agent config can trigger arbitrary class loading:
While
BaseTool/BaseToolsettype checks prevent direct instantiation of arbitrary classes, theloadClass()call itself triggers class static initializers, andsetAccessible(true)bypasses Java access controls on non-public constructors.Fix
ALLOWED_CLASS_PREFIXESallowlist: Onlycom.google.adk.*andgoogle.adk.*classes can be loaded via reflection from YAML configsisAllowedClassForLoading()validation: Called before everyloadClass()invocation in bothToolResolverandComponentRegistrysetAccessible(true): Prevents bypassing Java access controls on non-public classesFiles Changed
ToolResolver.java— AddedALLOWED_CLASS_PREFIXES,isAllowedClassForLoading(), and validation guards before all 5loadClass()calls. RemovedsetAccessible(true).ComponentRegistry.java— Added the same allowlist validation toloadToolsetClass()fallback path.Related Issues
Related to CVE-2026-4810 — analogous vulnerability in adk-python's
importlib.import_module()How to Validate
com.google.adk.*tools continue to workjava.lang.Runtime) are blocked with a WARN log./gradlew testPre-Merge Checklist