Skip to content

Conversation

@lukaszlenart
Copy link
Member

Summary

This PR completes the comprehensive encapsulation of all UIBean fields by converting ALL remaining protected fields to private with public getter methods. This extends the fix from WW-5368 (PR #1420) to cover all protected fields in UIBean.

Closes WW-5589

Background

WW-5368 identified that OGNL triggers false-positive security warnings when resource bundle keys or expressions contain tokens matching protected UIBean field names (e.g., "label", "name", "value"). The root cause was OGNL attempting to access protected fields during expression evaluation before realizing they should be treated as string literals.

PR #1420 fixed the immediate issue by converting just the four most problematic fields (label, name, value, id) from protected to private with public getters. This PR extends that solution to ALL remaining protected fields for consistency and to prevent similar issues with other common field names like "key", "title", "disabled", "template", etc.

Changes

Core Changes to UIBean.java

Converted ALL remaining protected fields to private with public getters:

Template-related fields:

  • templateSuffix, template, templateDir, theme

Style/CSS fields:

  • cssClass, cssStyle, cssErrorClass, cssErrorStyle

Form attribute fields:

  • key, disabled, tabindex, title, accesskey

Label attribute fields:

  • labelPosition, labelSeparator, requiredPosition, errorPosition, requiredLabel

Event handler fields:

  • onclick, ondblclick, onmousedown, onmouseup, onmouseover, onmousemove, onmouseout
  • onfocus, onblur, onkeypress, onkeydown, onkeyup, onselect, onchange

Tooltip fields (deprecated):

  • tooltip, tooltipConfig, javascriptTooltip, tooltipDelay, tooltipCssClass, tooltipIconPath

Other:

  • dynamicAttributes Map

Added comprehensive public getter methods with JavaDoc for all fields.

Subclass Fixes

Updated UIBean subclasses to use getters instead of direct field access:

  • Anchor.java: templategetTemplate()
  • DoubleSelect.java: onchangegetOnchange()
  • Link.java: disabledgetDisabled(), titlegetTitle()
  • Submit.java: keygetKey(), templategetTemplate()
  • Label.java: keygetKey()
  • Reset.java: keygetKey()

Test Coverage

Added new test testNoOgnlWarningsForAdditionalFields() in UIBeanTest that:

  • Tests OGNL access to newly converted fields (key, title, disabled, cssClass, template, theme, tabindex, event handlers)
  • Verifies all public getters are accessible
  • Confirms no OGNL security warnings are triggered

Test Results

  • ✅ All 26 UIBeanTest tests pass
  • ✅ All 103 component tests pass with no failures or errors
  • ✅ Clean compilation with no errors

Benefits

  1. Consistency: All UIBean fields now follow JavaBean conventions (private fields, public getters)
  2. Security: Prevents OGNL from attempting direct field access, eliminating false-positive warnings
  3. Future-proof: Prevents similar issues with resource bundle keys or expressions matching any field name
  4. Better encapsulation: Follows Java best practices for class design

Migration Impact

This is a binary-compatible change:

  • All public setter methods remain unchanged
  • New public getter methods are added
  • Only internal subclasses needed updates (all included in this PR)
  • External code using setters is unaffected

🤖 Generated with Claude Code

Co-Authored-By: Claude noreply@anthropic.com

lukaszlenart and others added 3 commits November 23, 2025 12:54
Comprehensive research document analyzing the root cause of OGNL security
warnings when using getText() with resource bundle keys starting with "label".

Key findings:
- UIBean has protected String label field without public getter
- SecurityMemberAccess enforces public-only member access
- OGNL property resolution happens before string concatenation evaluation
- Warning is a false positive - expression works but triggers introspection

Analysis includes:
- Detailed OGNL evaluation flow through CompoundRootAccessor
- SecurityMemberAccess check sequence and blocking mechanism
- Select tag listValue processing and iterator stack manipulation
- Comparison with similar protected fields in other components

Recommended solution: Change protected fields to private with public getters
to follow JavaBean conventions and eliminate warnings (Date component pattern).

Related: WW-5364 added components package to OGNL allowlist (commit 39c3e33)

Closes [WW-5368](https://issues.apache.org/jira/browse/WW-5368)

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
Change UIBean and related component fields from protected to private
with public getters to prevent false-positive OGNL SecurityMemberAccess
warnings when evaluating expressions with resource bundle keys.

Previously, expressions like getText('label.key.'+top) would trigger
warnings: "Access to non-public [protected String UIBean.label] is blocked!"
because OGNL attempted to access protected fields directly.

Changes:
- UIBean: Changed label, name, value, id fields to private, added getters
- Bean, Param, Text, I18n: Changed name/value fields to private, added getters
- Updated all subclasses to use getters instead of direct field access
- Added test to verify OGNL can access fields via public getters

Fixes #WW-5368

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
…th getters

- Convert all remaining protected fields in UIBean to private:
  - Template-related: templateSuffix, template, templateDir, theme
  - Style/CSS: cssClass, cssStyle, cssErrorClass, cssErrorStyle
  - Form attributes: key, disabled, tabindex, title, accesskey
  - Label attributes: labelPosition, labelSeparator, requiredPosition, errorPosition, requiredLabel
  - Event handlers: onclick, ondblclick, onmousedown, onmouseup, onmouseover, onmousemove, onmouseout, onfocus, onblur, onkeypress, onkeydown, onkeyup, onselect, onchange
  - Tooltip attributes: tooltip, tooltipConfig, javascriptTooltip, tooltipDelay, tooltipCssClass, tooltipIconPath
  - Dynamic attributes map

- Add public getter methods for all converted fields with JavaDoc

- Update UIBean subclasses to use getters instead of direct field access:
  - Anchor.java: use getTemplate()
  - DoubleSelect.java: use getOnchange()
  - Link.java: use getDisabled(), getTitle()
  - Submit.java: use getKey(), getTemplate()
  - Label.java: use getKey()
  - Reset.java: use getKey()

- Add comprehensive test coverage in UIBeanTest:
  - testNoOgnlWarningsForAdditionalFields() verifies OGNL can access all newly converted fields via getters
  - Tests key, title, disabled, cssClass, template, theme, tabindex, and event handler fields

This completes WW-5589 by ensuring all UIBean fields follow JavaBean conventions (private fields with public getters), preventing OGNL from attempting direct field access which could trigger false-positive security warnings.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
@lukaszlenart lukaszlenart marked this pull request as draft November 23, 2025 16:13
@sonarqubecloud
Copy link

Quality Gate Failed Quality Gate failed

Failed conditions
65.8% Coverage on New Code (required ≥ 80%)

See analysis details on SonarQube Cloud

@lukaszlenart lukaszlenart deleted the fix/WW-5589-uibean-field-encapsulation branch November 25, 2025 18:11
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