[
https://issues.apache.org/jira/browse/WW-5408?focusedWorklogId=913996&page=com.atlassian.jira.plugin.system.issuetabpanels:worklog-tabpanel#worklog-913996
]
ASF GitHub Bot logged work on WW-5408:
--------------------------------------
Author: ASF GitHub Bot
Created on: 10/Apr/24 15:56
Start Date: 10/Apr/24 15:56
Worklog Time Spent: 10m
Work Description: lukaszlenart commented on code in PR #912:
URL: https://github.com/apache/struts/pull/912#discussion_r1559703694
##########
core/src/main/java/com/opensymphony/xwork2/config/impl/DefaultConfiguration.java:
##########
@@ -583,11 +590,10 @@ public ActionConfig getActionConfig(String namespace,
String name) {
}
// fail over to empty namespace
- if (config == null && StringUtils.isNotBlank(namespace)) {
+ if (config == null && StringUtils.isNotBlank(namespace) &&
("/".equals(namespace) || fallbackToEmptyNamespace)) {
Review Comment:
I would extract this logic into a private method to name it, something like
```java
if (config == null && shouldFallbackToEmptyNamespaces(namespace)) {
...
```
##########
core/src/main/java/com/opensymphony/xwork2/config/impl/DefaultConfiguration.java:
##########
@@ -459,9 +460,12 @@ protected synchronized RuntimeConfiguration
buildRuntimeConfiguration() throws C
boolean appendNamedParameters = Boolean.parseBoolean(
container.getInstance(String.class,
StrutsConstants.STRUTS_MATCHER_APPEND_NAMED_PARAMETERS)
);
+ boolean fallbackToEmptyNamespace = Boolean.parseBoolean(
+ Optional.ofNullable(container.getInstance(String.class,
StrutsConstants.STRUTS_ACTION_CONFIG_FALLBACK_TO_EMPTY_NAMESPACE)).orElse("true")
Review Comment:
Instead of this fallback I would create a new entry into
[default.properties](https://github.com/apache/struts/blob/master/core/src/main/resources/org/apache/struts2/default.properties)
with value set to `true` and document it - this will help others understand
the change
Issue Time Tracking
-------------------
Worklog Id: (was: 913996)
Time Spent: 1h (was: 50m)
> Add option to NOT fallback to empty namespace when unresolved
> -------------------------------------------------------------
>
> Key: WW-5408
> URL: https://issues.apache.org/jira/browse/WW-5408
> Project: Struts 2
> Issue Type: Improvement
> Components: Core
> Reporter: Kusal Kithul-Godage
> Priority: Minor
> Fix For: 6.5.0
>
> Time Spent: 1h
> Remaining Estimate: 0h
>
> Currently, when a namespace cannot be resolved from a request URL, it falls
> back to the empty namespace.
> This effectively allows all Actions which are defined for the empty namespace
> to be accessed from an infinite number of endpoints.
> For example, you may have an Action defined in the empty namespace, intended
> for access at:
> {{www.domain.com/login.action}}
> However, due to the current fallback behaviour, this Action can actually be
> accessed at any non-resolving namespace, eg.:
> {{www.domain.com/what/about/this/login.action}}
> This behaviour is not usually beneficial and could lead to bugs if a
> developer only expects their Action to be accessible at a very specific URL.
> Many developers may not be aware of these Action resolving quirks of Struts.
> As far as I can tell, there is not currently an option to prevent this
> behaviour, so I propose we add one.
--
This message was sent by Atlassian Jira
(v8.20.10#820010)