Skip to content

Commit a88660f

Browse files
committed
Java: Add support for Struts 7.x package names
Updates Struts library to recognize both legacy xwork2 and new struts2 packages: - StrutsActions.qll: Add org.apache.struts2 alternatives for Action, Preparable, ActionSupport - StrutsConventions.qll: Add ActionSupport ancestry checks for convention plugin detection This maintains backward compatibility for analyzing Struts 2.x-6.x apps while supporting Struts 7.x which renamed packages from com.opensymphony.xwork2 to org.apache.struts2 and removed the Action interface.
1 parent fbcb65a commit a88660f

File tree

2 files changed

+13
-5
lines changed

2 files changed

+13
-5
lines changed

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")
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: 5 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 (Struts 7.x+).
100100
*/
101101
class Struts2ConventionActionClass extends Class {
102102
Struts2ConventionActionClass() {
@@ -108,7 +108,10 @@ 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") or
113+
this.getAnAncestor().hasQualifiedName("com.opensymphony.xwork2", "ActionSupport") or
114+
this.getAnAncestor().hasQualifiedName("org.apache.struts2", "ActionSupport")
112115
)
113116
}
114117

0 commit comments

Comments
 (0)