Fix Hessian2 writeReplace Serializable check bypass#16307
Conversation
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## 3.3 #16307 +/- ##
============================================
+ Coverage 60.77% 60.79% +0.01%
- Complexity 11768 11776 +8
============================================
Files 1953 1953
Lines 89196 89198 +2
Branches 13457 13457
============================================
+ Hits 54212 54231 +19
+ Misses 29418 29403 -15
+ Partials 5566 5564 -2
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
|
The CI failure was caused by the previous follow-up enforcing the full strict allow-list check for classes with writeReplace(). That also rejected JDK immutable collection implementations such as java.util.ImmutableCollections in Java 21 samples. I narrowed the writeReplace path to enforce only the Serializable requirement, which is the bypass covered by this issue, and added a regression test for JDK immutable lists under STRICT mode. The latest Build and Test run is now green. |
What is the purpose of the change?
Fixes #16287.
Hessian2SerializerFactorycurrently enforces Dubbo's serialization class policy fromgetDefaultSerializer(). However, hessian-lite resolves classes withwriteReplace()before it reachesgetDefaultSerializer(), so non-Serializable classes withwriteReplace()can bypass the sender-side Serializable check.This change enforces the same class policy in
getSerializer(Class)for replacement-capable classes before delegating to hessian-lite, while keeping the existing default serializer/deserializer checks shared through one helper.Brief changelog
writeReplace().getDefaultSerializer()andgetDefaultDeserializer()checks by sharing the samecheckClass()helper.writeReplace()returns itself;writeReplace()returns a non-Serializable replacement with its ownwriteReplace();Verifying this change
git diff --checkmvn -am -pl dubbo-serialization/dubbo-serialization-hessian2 -Dtest=Hessian2SerializationTest -Dsurefire.failIfNoSpecifiedTests=false -Dcheckstyle.skip=true -Drat.skip=true testChecklist