apache / apache/shenyu

[BUG] SpringBeanUtils.registerBean mutates the shared BeanFactory.beanClassLoader globally

Open
#6,727 1 comment 0 reactions 0 assignees View on GitHub
priority: medium type: bug
Dominant language
Java
Stars
8.8k
Forks
3.1k
Avg merge
7d 1h
Merged PRs (30d)
85

Description

- Severity: Medium
- Location:
`shenyu-plugin/shenyu-plugin-api/src/main/java/org/apache/shenyu/plugin/api/utils/SpringBeanUtils.java:85`
-
Description:
`beanFactory.setBeanClassLoader(classLoader); beanFactory.registerBeanDefinition(beanName, beanDefinition);`. `setBeanClassLoader` sets a single field on the shared `DefaultListableBeanFactory`, affecting type resolution for **all** beans, not just the one being registered. Every plugin registration overwrites the global classloader with that plugin's classloader.
-
Impact:
Plugin A registers (factory CL ← A). Plugin B registers (factory CL ← B). Any deferred type resolution for A's beans (lazy autowire, AOP proxy, bean created on first use) now uses B's classloader, which cannot see A's classes → order-dependent `ClassNotFoundException`/`BeanCreationException`.
-
Suggested fix:
Do not call `setBeanClassLoader` on the shared factory. Pass the classloader through the `BeanDefinition` (e.g. a custom `RootBeanDefinition` with a `Supplier` that does `Class.forName(name, false, pluginClassLoader)`).
-
Confidence: Medium
- Related existing: SEC-1 (RCE via defineClass) is the trust issue; this is a separate classloader-correctness bug.

---
_Identified during the 2026-08-02 deep re-scan; full list in [`docs/scan2-2026-08-02/06-medium-tiers.md`](docs/scan2-2026-08-02/06-medium-tiers.md)._

Contributor guide

No contributing guide indexed for this repository

Research direction

Start in shenyu-plugin/shenyu-plugin-api/src/main/java/org/apache/shenyu/plugin/api/utils/SpringBeanUtils.java at line 85 and trace plugin bean registration through the shared BeanFactory. Verify the deferred-resolution scenario described for beans from two plugins with different classloaders. Done means registration no longer mutates the shared factory's classloader and each plugin's deferred type resolution retains its own classloader.

Written by the indexing model from the issue text.

Assessment

Tech stack
java, spring
Domain
backend
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Quiet
Clarity
Mostly clear
Newbie friendliness
48/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.