fix(security): add class loading allowlist to prevent arbitrary code execution from YAML configs#1237
Conversation
|
Hi @Ashutosh0x, thank you for your contribution! We appreciate you taking the time to submit this pull request. I noticed that the pre-check and test cases are currently failing. Could you please take a look and address those issues? |
…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
b39ef36 to
6279b00
Compare
|
Hi @hemasekhar-p, thank you for reviewing! I've addressed the issues and force-pushed the fix:
All checks verified locally:
Could you please approve the CI workflows and merge when ready? Thanks! |
|
@Ashutosh0x,Thank you for resolving the pre checking failures, Currently this PR is under review by our team, we will keep you posted if any additional information is required. thank you. |
|
@sherryfox, Could you please review this. |
|
Hello, @Ashutosh0x. Thank you for your contribution. Main concern: the hardcoded allowlist is a breaking changeRestricting loads to only
How adk-python solved the same CVEWorth noting since the PR cites this as the Java equivalent: adk-python took the opposite approach. In Suggested direction: make it configurable, allow-everything by defaultRather than a fixed policy in // Opt-in. Default allows everything, so behavior is unchanged unless configured.
ComponentRegistry.getInstance().restrictClassLoadingTo("com.mycompany.tools.");
Smaller notes
|
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