Skip to content

Commit b7125a0

Browse files
authored
Merge pull request #21221 from github/navntoft/struts
Java: Add support for Struts 7.x package names
2 parents 46a5035 + ede05b5 commit b7125a0

File tree

3 files changed

+15
-5
lines changed

3 files changed

+15
-5
lines changed
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
---
2+
category: minorAnalysis
3+
---
4+
* Added support for Struts 7.x package names in the Struts framework library. The library now recognizes both the legacy `com.opensymphony.xwork2` package names (Struts 2.x-6.x) and the new `org.apache.struts2` package names (Struts 7.x+), maintaining backward compatibility while enabling analysis of code using the latest Struts versions.

java/ql/lib/semmle/code/java/frameworks/struts/StrutsActions.qll

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,10 @@ class Struts2ActionClass extends Class {
2020
// If there are no XML files present, then we assume we any class that extends a struts 2
2121
// action must be reflectively constructed, as we have no better indication.
2222
not exists(XmlFile xmlFile) and
23-
this.getAnAncestor().hasQualifiedName("com.opensymphony.xwork2", "Action")
23+
(
24+
this.getAnAncestor().hasQualifiedName("com.opensymphony.xwork2", "Action") or
25+
this.getAnAncestor().hasQualifiedName("org.apache.struts2.action", "Action")
26+
)
2427
or
2528
// If there is a struts.xml file, then any class that is specified as an action is considered
2629
// to be reflectively constructed.
@@ -78,7 +81,8 @@ class Struts2ActionClass extends Class {
7881
* Holds if this action class extends the preparable interface.
7982
*/
8083
predicate isPreparable() {
81-
this.getAnAncestor().hasQualifiedName("com.opensymphony.xwork2", "Preparable")
84+
this.getAnAncestor().hasQualifiedName("com.opensymphony.xwork2", "Preparable") or
85+
this.getAnAncestor().hasQualifiedName("org.apache.struts2", "Preparable")
8286
}
8387

8488
/**
@@ -122,7 +126,8 @@ class Struts2PrepareMethod extends Method {
122126
*/
123127
class Struts2ActionSupportClass extends Class {
124128
Struts2ActionSupportClass() {
125-
this.getASourceSupertype+().hasQualifiedName("com.opensymphony.xwork2", "ActionSupport")
129+
this.getASourceSupertype+().hasQualifiedName("com.opensymphony.xwork2", "ActionSupport") or
130+
this.getASourceSupertype+().hasQualifiedName("org.apache.struts2", "ActionSupport")
126131
}
127132

128133
/**

java/ql/lib/semmle/code/java/frameworks/struts/StrutsConventions.qll

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ private string getConventionSuffix(RefType refType) {
9696
*
9797
* The convention plugin identifies as an action class any class that has an ancestor package with
9898
* the name "struts", "struts2", "action" or "actions", and either has an indicative suffix on the
99-
* name, or extends com.opensymphony.xwork2.Action.
99+
* name, or extends com.opensymphony.xwork2.Action (Struts 2.x-6.x) or org.apache.struts2.action.Action (Struts 7.x+).
100100
*/
101101
class Struts2ConventionActionClass extends Class {
102102
Struts2ConventionActionClass() {
@@ -108,7 +108,8 @@ class Struts2ConventionActionClass extends Class {
108108
) and
109109
(
110110
this.getName().matches("%" + getConventionSuffix(this)) or
111-
this.getAnAncestor().hasQualifiedName("com.opensymphony.xwork2", "Action")
111+
this.getAnAncestor().hasQualifiedName("com.opensymphony.xwork2", "Action") or
112+
this.getAnAncestor().hasQualifiedName("org.apache.struts2.action", "Action")
112113
)
113114
}
114115

0 commit comments

Comments
 (0)