[
https://issues.apache.org/jira/browse/WW-5757?focusedWorklogId=1045858&page=com.atlassian.jira.plugin.system.issuetabpanels:worklog-tabpanel#worklog-1045858
]
ASF GitHub Bot logged work on WW-5757:
--------------------------------------
Author: ASF GitHub Bot
Created on: 06/Oct/26 05:27
Start Date: 06/Oct/26 05:27
Worklog Time Spent: 10m
Work Description: Copilot commented on code in PR #1989:
URL: https://github.com/apache/struts/pull/1989#discussion_r4191842462
##########
plugins/bean-validation/src/main/java/org/apache/struts/beanvalidation/validation/interceptor/BeanValidationInterceptor.java:
##########
@@ -135,16 +137,7 @@ protected void
addBeanValidationErrors(Set<ConstraintViolation<Object>> constrai
if (constraintViolations != null) {
ValidatorContext validatorContext = new
DelegatingValidatorContext(action, textProviderFactory);
for (ConstraintViolation<Object> constraintViolation :
constraintViolations) {
- String key = constraintViolation.getMessage();
- String message = key;
- try {
- message = validatorContext.getText(key);
- if (convertToUtf8 && StringUtils.isNotBlank(message)) {
- message = new
String(message.getBytes(convertFromEncoding), "UTF-8");
- }
- } catch (Exception e) {
- LOG.error("Error while trying to fetch message: {}", key,
e);
- }
+ String message = resolveMessage(constraintViolation,
validatorContext);
Review Comment:
This change touches security-sensitive framework code. Please confirm it is
not a fix for a suspected vulnerability before merging — see `SECURITY.md`.
Vulnerability fixes go through the private process at
`[email protected]`, not a public pull request.
Issue Time Tracking
-------------------
Worklog Id: (was: 1045858)
Time Spent: 1h 10m (was: 1h)
> BeanValidationInterceptor resolves the interpolated constraint message as a
> text key instead of the message template
> --------------------------------------------------------------------------------------------------------------------
>
> Key: WW-5757
> URL: https://issues.apache.org/jira/browse/WW-5757
> Project: Struts 2
> Issue Type: Bug
> Components: Plugin - Bean Validation
> Reporter: Lukasz Lenart
> Assignee: Lukasz Lenart
> Priority: Major
> Fix For: 6.13.0, 7.5.0
>
> Time Spent: 1h 10m
> Remaining Estimate: 0h
>
> {{BeanValidationInterceptor}} builds the field and action error text from
> {{ConstraintViolation.getMessage()}}, which is the message *after* the Bean
> Validation provider has interpolated it, and passes that string to the Struts
> text provider ({{getText(...)}}) as the text key.
> The key a developer declares is the constraint's {{message}} attribute, which
> is what {{ConstraintViolation.getMessageTemplate()}} returns. Using the
> interpolated message as the key means:
> * a developer-declared Struts key only resolves when the provider leaves the
> message untouched;
> * provider-interpolated text that matches no key is not shown as the provider
> produced it, but is handed to the text provider as default text and processed
> again, as if it were a Struts message.
> The plugin documentation only promises that the {{message}} value is looked
> up as a Struts key; it does not say that provider-produced text goes through
> the text provider.
> h2. Change
> Resolve the error text from the template, and keep the provider's message
> otherwise:
> * look up {{getMessageTemplate()}} in the Struts bundles, and call
> {{getText}} with it only when {{hasKey}} finds it;
> * otherwise use {{ConstraintViolation.getMessage()}} as-is, as literal text;
> * never pass the interpolated message to any text-provider method
> ({{getText}}, {{hasKey}}, {{findText}}).
> h2. Tests
> * A constraint whose provider-interpolated message contains text that the
> Struts text provider would otherwise process is reported exactly as the
> provider produced it.
> * Existing tests where {{message}} is a Struts key keep resolving through the
> bundle.
> Apply the same change on the 6.x line.
> h2. Documentation
> The Bean Validation plugin page should state that {{message}} is looked up as
> a Struts key, and that a message produced by the provider is shown literally.
--
This message was sent by Atlassian Jira
(v8.20.10#820010)