You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@dubbo.apache.org by "obabichevjb (via GitHub)" <gi...@apache.org> on 2026/10/05 10:55:48 UTC
[PR] fix: auto-trust the subtypes a sealed type permits [dubbo]
obabichevjb opened a new pull request, #16492:
URL: https://github.com/apache/dubbo/pull/16492
## What is the purpose of the change?
Fixes #16491.
`SerializeSecurityConfigurator` auto-allow-lists the classes it can reach from an exported
interface's signatures. `checkClass` walks **up** into supertypes and **into** fields and generic
arguments, but never **down** into subtypes. A sealed parameter or return type therefore gets the
parent trusted and none of the subtypes that actually travel on the wire:
```java
public sealed interface Reply extends Serializable permits Found, NotFound {}
public final class Found implements Reply { /* ... */ }
public final class NotFound implements Reply { /* ... */ }
public interface ReplyService {
Reply lookup(String key); // returns Found or NotFound
}
```
`Reply` and `ReplyService` land in the allow list; `Found` and `NotFound` do not. In the default
`STRICT` mode the provider then fails to serialize its own response:
```
[Serialization Security] Serialized class Found is not in allow list.
Current mode is `STRICT`, will disallow to deserialize it by default.
```
The consumer sees that wrapped in a `RemotingException`, which makes it read like a transport
problem rather than a configuration one.
The developer then has to list every subtype by hand and keep that list in step with the hierarchy —
for a set the compiler already knows in full.
This change walks the subtypes a sealed type permits, so they are trusted along with the parent.
## Why this does not widen the trust boundary
A sealed type enumerates its subtypes in its own source, and the JVM refuses to load any subtype
absent from that list. Trusting them grants exactly the set the author declared and nothing an
attacker can extend. It is a more precise grant than the package-prefix trust Dubbo already applies
when `trustSerializeClassLevel` is set, which trusts everything under a package regardless of what
the author declared.
A non-sealed hierarchy is open and cannot be enumerated, so it must keep behaving as it does today.
`SerializeSecurityConfiguratorSealedTest.testOpenSubclassesAreNotAutoTrusted` asserts that
distinction directly: a plain interface is trusted, its implementation is not.
## Brief changelog
- `SerializeSecurityConfigurator.checkClass` walks `Class.getPermittedSubclasses()` alongside the
existing supertype and field traversal.
- `Class.getPermittedSubclasses()` is Java 17 and `dubbo-common` compiles at Java 8, so it is
resolved reflectively once into a static `Method` and treated as absent on older runtimes. An
unresolvable permitted subtype is skipped rather than aborting the walk.
- New `SerializeSecurityConfiguratorSealedTest`, with the sealed fixture generated by javassist —
the module cannot compile `sealed` source — and gated to Java 17+ runtimes via
`@EnabledForJreRange`, matching the existing use of that annotation in this module.
## Verifying this change
- `SerializeSecurityConfiguratorSealedTest` has two cases: sealed subtypes **are** trusted, and
non-sealed implementations are **not**.
- Reverting the `checkClass` change fails `testSealedSubclassesAreAutoTrusted` while the non-sealed
control still passes, so the test is not vacuous.
- Full `dubbo-common` suite: 1167 tests, 0 failures, 0 errors. `mvn spotless:check` passes.
- Run on JDK 8, 11, 17 and 21. On 8 and 11 the sealed case is skipped and the control passes, so the
Java 8 and 11 unit-test jobs stay green. Compiled with `release 8`, so no Java 9+ API slipped in.
(JDK 25, also in the CI matrix, was not available locally.)
- Full reactor build with `-DskipTests`: 114 modules, 0 failures. Worth stating because this touches
`dubbo-common`, so every module downstream of it is affected.
- End-to-end over a real Netty `dubbo://` transport with no allow-list file, against 3.3.6 and
against a local build of this branch. Three rows move from rejected to working — a Kotlin
`sealed interface` with a `data class` subtype, the same with a `data object` subtype, and a
**Java 17 `sealed interface`** — while two control rows are unchanged: a non-sealed Java interface
stays untrusted, and a Java POJO that is not `Serializable` still fails the `Serializable` gate.
## Known limitation for Kotlin below jvmTarget 17
Kotlin only emits the JVM `PermittedSubclasses` attribute at `-jvm-target 17` or above; measured on
Kotlin 2.4.20:
| `-jvm-target` | class file | `PermittedSubclasses` |
|---|---|---|
| 1.8 | 52 | absent |
| 11 | 55 | absent |
| 17 | 61 | present |
| 21 | 65 | present |
Below 17 the sealed hierarchy exists only inside `kotlin.Metadata`, whose payload is protobuf-encoded
and would need `kotlinx-metadata` to read — not worth a core dependency. Those builds keep behaving
exactly as they do today. The same applies to a JDK 8 or 11 runtime, where sealed classes do not
exist at all.
## Does this pull request potentially affect one of the following parts?
- Dependencies: no.
- Public API: no.
- Serialization security defaults: yes, in that more classes are auto-trusted — but only the subtypes
a sealed type already permits, as argued above. Behaviour is unchanged for non-sealed types, for
JDK 8/11 runtimes and for Kotlin below jvmTarget 17.
## Checklist
- [x] Make sure there is a [GitHub_issue](https://github.com/apache/dubbo/issues) field for the change. — #16491
- [x] Write a pull request description that is detailed enough to understand what the pull request does, how, and why.
- [x] Write necessary unit-test to verify your logic correction. If the new feature or significant change is committed, please remember to add sample in [dubbo samples](https://github.com/apache/dubbo-samples) project. — `SerializeSecurityConfiguratorSealedTest`, covering both the fixed sealed case and the unchanged non-sealed case.
- [x] Make sure gitHub actions can pass. [Why the workflow is failing and how to fix it?](../CONTRIBUTING.md)
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@dubbo.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@dubbo.apache.org
For additional commands, e-mail: notifications-help@dubbo.apache.org
Re: [PR] fix: auto-trust the subtypes a sealed type permits [dubbo]
Posted by "codecov-commenter (via GitHub)" <gi...@apache.org>.
codecov-commenter commented on PR #16492:
URL: https://github.com/apache/dubbo/pull/16492#issuecomment-5993512850
## [Codecov](https://app.codecov.io/gh/apache/dubbo/pull/16492?dropdown=coverage&src=pr&el=h1&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) Report
:x: Patch coverage is `53.84615%` with `6 lines` in your changes missing coverage. Please review.
:white_check_mark: Project coverage is 36.90%. Comparing base ([`a87b134`](https://app.codecov.io/gh/apache/dubbo/commit/a87b134859e1b3d0871e20b9eac848abd2f0b50c?dropdown=coverage&el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache)) to head ([`22aaae8`](https://app.codecov.io/gh/apache/dubbo/commit/22aaae813579ea83b276bf6d126aadcff1ffbe75?dropdown=coverage&el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache)).
| [Files with missing lines](https://app.codecov.io/gh/apache/dubbo/pull/16492?dropdown=coverage&src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) | Patch % | Lines |
|---|---|---|
| [...bo/common/utils/SerializeSecurityConfigurator.java](https://app.codecov.io/gh/apache/dubbo/pull/16492?src=pr&el=tree&filepath=dubbo-common%2Fsrc%2Fmain%2Fjava%2Forg%2Fapache%2Fdubbo%2Fcommon%2Futils%2FSerializeSecurityConfigurator.java&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache#diff-ZHViYm8tY29tbW9uL3NyYy9tYWluL2phdmEvb3JnL2FwYWNoZS9kdWJiby9jb21tb24vdXRpbHMvU2VyaWFsaXplU2VjdXJpdHlDb25maWd1cmF0b3IuamF2YQ==) | 53.84% | [3 Missing and 3 partials :warning: ](https://app.codecov.io/gh/apache/dubbo/pull/16492?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) |
> :exclamation: There is a different number of reports uploaded between BASE (a87b134) and HEAD (22aaae8). Click for more details.
>
> <details><summary>HEAD has 5 uploads less than BASE</summary>
>
>| Flag | BASE (a87b134) | HEAD (22aaae8) |
>|------|------|------|
>|unit-tests-java11|1|0|
>|unit-tests-java8|1|0|
>|unit-tests-java25|1|0|
>|unit-tests-java21|1|0|
>|unit-tests-java17|1|0|
></details>
<details><summary>Additional details and impacted files</summary>
```diff
@@ Coverage Diff @@
## 3.3 #16492 +/- ##
=============================================
- Coverage 60.92% 36.90% -24.02%
+ Complexity 11764 11752 -12
=============================================
Files 1953 1952 -1
Lines 89275 89266 -9
Branches 13474 13392 -82
=============================================
- Hits 54394 32948 -21446
- Misses 29301 51730 +22429
+ Partials 5580 4588 -992
```
| [Flag](https://app.codecov.io/gh/apache/dubbo/pull/16492/flags?src=pr&el=flags&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) | Coverage Δ | |
|---|---|---|
| [integration-tests-java21](https://app.codecov.io/gh/apache/dubbo/pull/16492/flags?src=pr&el=flag&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) | `32.14% <30.76%> (-0.01%)` | :arrow_down: |
| [integration-tests-java8](https://app.codecov.io/gh/apache/dubbo/pull/16492/flags?src=pr&el=flag&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) | `32.21% <38.46%> (+0.01%)` | :arrow_up: |
| [samples-tests-java21](https://app.codecov.io/gh/apache/dubbo/pull/16492/flags?src=pr&el=flag&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) | `32.09% <30.76%> (-0.10%)` | :arrow_down: |
| [samples-tests-java8](https://app.codecov.io/gh/apache/dubbo/pull/16492/flags?src=pr&el=flag&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) | `29.82% <38.46%> (+0.01%)` | :arrow_up: |
| [unit-tests-java11](https://app.codecov.io/gh/apache/dubbo/pull/16492/flags?src=pr&el=flag&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) | `?` | |
| [unit-tests-java17](https://app.codecov.io/gh/apache/dubbo/pull/16492/flags?src=pr&el=flag&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) | `?` | |
| [unit-tests-java21](https://app.codecov.io/gh/apache/dubbo/pull/16492/flags?src=pr&el=flag&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) | `?` | |
| [unit-tests-java25](https://app.codecov.io/gh/apache/dubbo/pull/16492/flags?src=pr&el=flag&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) | `?` | |
| [unit-tests-java8](https://app.codecov.io/gh/apache/dubbo/pull/16492/flags?src=pr&el=flag&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) | `?` | |
Flags with carried forward coverage won't be shown. [Click here](https://docs.codecov.io/docs/carryforward-flags?utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache#carryforward-flags-in-the-pull-request-comment) to find out more.
</details>
[:umbrella: View full report in Codecov by Harness](https://app.codecov.io/gh/apache/dubbo/pull/16492?dropdown=coverage&src=pr&el=continue&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache).
:loudspeaker: Have feedback on the report? [Share it here](https://about.codecov.io/codecov-pr-comment-feedback/?utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache).
<details><summary> :rocket: New features to boost your workflow: </summary>
- :snowflake: [Test Analytics](https://docs.codecov.com/docs/test-analytics): Detect flaky tests, report on failures, and find test suite problems.
- :package: [JS Bundle Analysis](https://docs.codecov.com/docs/javascript-bundle-analysis): Save yourself from yourself by tracking and limiting bundle sizes in JS merges.
</details>
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@dubbo.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@dubbo.apache.org
For additional commands, e-mail: notifications-help@dubbo.apache.org
Re: [PR] fix: auto-trust the subtypes a sealed type permits [dubbo]
Posted by "obabichevjb (via GitHub) via notifications" <no...@dubbo.apache.org>.
obabichevjb commented on PR #16492:
URL: https://github.com/apache/dubbo/pull/16492#issuecomment-6797281314
Updated PR with the suggestions from Copilot, should look better now.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@dubbo.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@dubbo.apache.org
For additional commands, e-mail: notifications-help@dubbo.apache.org
Re: [PR] fix: auto-trust the subtypes a sealed type permits [dubbo]
Posted by "Copilot (via GitHub)" <gi...@apache.org>.
Copilot commented on code in PR #16492:
URL: https://github.com/apache/dubbo/pull/16492#discussion_r4269033799
##########
dubbo-common/src/main/java/org/apache/dubbo/common/utils/SerializeSecurityConfigurator.java:
##########
@@ -348,6 +363,36 @@ private boolean checkClass(Class<?> clazz) {
return true;
}
+ private static Method resolveGetPermittedSubclasses() {
+ try {
+ return Class.class.getMethod("getPermittedSubclasses");
+ } catch (NoSuchMethodException e) {
+ // Running on Java 8/11: sealed classes do not exist, so there is nothing to walk.
+ return null;
+ }
+ }
+
+ /**
+ * Returns the subtypes a sealed class permits, or an empty array when the class is not sealed,
+ * the runtime predates sealed classes, or the attribute cannot be read.
+ *
+ * <p>Note that a Kotlin {@code sealed} declaration only carries the JVM {@code
+ * PermittedSubclasses} attribute when compiled with {@code -jvm-target 17} or above; below that
+ * the sealed hierarchy exists only in {@code kotlin.Metadata} and is not visible here.
+ */
+ private static Class<?>[] getPermittedSubclasses(Class<?> clazz) {
+ if (GET_PERMITTED_SUBCLASSES == null) {
+ return EMPTY_CLASS_ARRAY;
+ }
+ try {
+ Class<?>[] permittedSubclasses = (Class<?>[]) GET_PERMITTED_SUBCLASSES.invoke(clazz);
+ return permittedSubclasses == null ? EMPTY_CLASS_ARRAY : permittedSubclasses;
+ } catch (Throwable t) {
+ // A permitted subtype that cannot be resolved must not stop the rest of the walk.
Review Comment:
Catching `Throwable` here will also swallow serious `Error`s (e.g., `OutOfMemoryError`, `StackOverflowError`) and make failures much harder to diagnose. Narrow this to the reflective/lookup-related exceptions you actually expect (e.g., `ReflectiveOperationException`, `ClassCastException`, `SecurityException`, possibly `LinkageError`/`TypeNotPresentException` if observed) and consider logging at `DEBUG` when this fallback triggers so operators can understand why sealed subtypes weren’t traversed.
##########
dubbo-common/src/test/java/org/apache/dubbo/common/utils/SerializeSecurityConfiguratorSealedTest.java:
##########
@@ -0,0 +1,138 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.dubbo.common.utils;
+
+import org.apache.dubbo.rpc.model.ApplicationModel;
+import org.apache.dubbo.rpc.model.FrameworkModel;
+import org.apache.dubbo.rpc.model.ModuleModel;
+
+import java.io.Serializable;
+import javassist.ClassPool;
+import javassist.CtClass;
+import javassist.LoaderClassPath;
+import javassist.Modifier;
+import javassist.bytecode.AttributeInfo;
+import javassist.bytecode.ClassFile;
+import javassist.bytecode.ConstPool;
+
+import org.junit.jupiter.api.Assertions;
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.condition.EnabledForJreRange;
+import org.junit.jupiter.api.condition.JRE;
+
+/**
+ * Auto-trust must reach the subtypes a sealed type permits, because declaring a sealed type in a
+ * service signature means the subtypes are what actually travel on the wire.
+ *
+ * <p>The sealed fixture is generated at runtime rather than written as source: this module compiles
+ * at Java 8, where {@code sealed} does not exist.
+ */
+class SerializeSecurityConfiguratorSealedTest {
+
+ private static final int CLASS_FILE_JAVA_17 = 61;
+
+ /** Ordinary interface and implementation — the control for the sealed case. */
+ public interface OpenParent extends Serializable {}
+
+ public static class OpenChild implements OpenParent {}
+
+ @Test
+ @EnabledForJreRange(min = JRE.JAVA_17)
+ void testSealedSubclassesAreAutoTrusted() throws Exception {
+ String pkg = getClass().getPackage().getName();
+ String parentName = pkg + ".GeneratedSealedParent";
+ String firstChildName = pkg + ".GeneratedSealedChildOne";
+ String secondChildName = pkg + ".GeneratedSealedChildTwo";
Review Comment:
These generated class names are constant, so re-running this test within the same JVM (common in IDE “rerun”, some build setups, or flaky-test reruns) can fail with a duplicate definition `LinkageError` when calling `toClass`. Use unique names per run (e.g., suffix with a UUID/counter) and/or define them in an isolated `ClassLoader` to avoid cross-run collisions.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@dubbo.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@dubbo.apache.org
For additional commands, e-mail: notifications-help@dubbo.apache.org