Skip to content

WW-5618 Add configurable limits to JSON plugin#1625

Open
lukaszlenart wants to merge 1 commit intomainfrom
WW-5618-json-configurable-limits
Open

WW-5618 Add configurable limits to JSON plugin#1625
lukaszlenart wants to merge 1 commit intomainfrom
WW-5618-json-configurable-limits

Conversation

@lukaszlenart
Copy link
Member

@lukaszlenart lukaszlenart commented Mar 17, 2026

Summary

Fixes WW-5618

  • Add configurable limits to the JSON plugin to prevent DoS attacks via malicious payloads (deeply nested objects, huge arrays, long strings)
  • Extract JSONReader interface from class, create StrutsJSONReader with bounds enforcement (maxElements, maxDepth, maxStringLength, maxKeyLength)
  • Rename DefaultJSONWriterStrutsJSONWriter (consistent Struts* naming convention)
  • Add JSONBeanSelectionProvider for swappable reader/writer implementations via constants
  • Wire limits into JSONInterceptor with @Inject from constants, configurable globally and per-action

Default Limits

Limit Default Constant
Max elements 10,000 struts.json.maxElements
Max depth 64 struts.json.maxDepth
Max input length 2MB struts.json.maxLength
Max string length 256KB struts.json.maxStringLength
Max key length 512 struts.json.maxKeyLength

Breaking Changes

  • JSONReader is now an interface (was a class). Code using new JSONReader() should use new StrutsJSONReader().
  • DefaultJSONWriter renamed to StrutsJSONWriter. Code referencing the class directly should update.
  • Static JSONUtil.deserialize() methods are deprecated (still functional, but without limit enforcement).
  • New defaults may reject unusually large JSON payloads. Error messages include the constant name to override.

Test plan

  • All 117 existing JSON plugin tests pass (0 failures, 0 errors)
  • 13 new StrutsJSONReaderTest tests covering all limit boundaries
  • Manual verification of per-action <param> overrides
  • Review default limit values for typical Struts applications

🤖 Generated with Claude Code

@lukaszlenart lukaszlenart marked this pull request as ready for review March 17, 2026 12:55
@lukaszlenart lukaszlenart force-pushed the WW-5618-json-configurable-limits branch 2 times, most recently from 48acbca to b50de96 Compare March 17, 2026 13:59
Add configurable limits to the JSON plugin to prevent denial-of-service
attacks via malicious payloads (deeply nested objects, huge arrays, long
strings).

Changes:
- Extract JSONReader interface from class, create StrutsJSONReader impl
  with maxElements, maxDepth, maxStringLength, maxKeyLength enforcement
- Rename DefaultJSONWriter to StrutsJSONWriter (Struts* naming convention)
- Add JSONBeanSelectionProvider for bean aliasing via constants
- Update JSONUtil with @Inject for reader/writer, add instance
  deserializeInput() with maxLength check, deprecate static deserialize()
- Wire limits into JSONInterceptor with @Inject from constants
- Register beans and defaults in struts-plugin.xml

Default limits: 10K elements, 64 depth, 2MB length, 256KB strings, 512 keys.
All configurable via struts.xml constants or per-action interceptor params.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@lukaszlenart lukaszlenart force-pushed the WW-5618-json-configurable-limits branch from b50de96 to 9d6721f Compare March 17, 2026 14:32
@sonarqubecloud
Copy link

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant