Skip to content

Commit b88731d

Browse files
Jami CogswellJami Cogswell
authored andcommitted
Java: move contents of MyBatisMapperXML.qll in src to MyBatis.qll in lib so importable, and fix experimental files broken by the move
1 parent 8e9f21d commit b88731d

File tree

4 files changed

+113
-2
lines changed

4 files changed

+113
-2
lines changed

java/ql/lib/semmle/code/java/frameworks/MyBatis.qll

Lines changed: 111 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -128,3 +128,114 @@ private class MyBatisProviderStep extends TaintTracking::AdditionalValueStep {
128128
)
129129
}
130130
}
131+
132+
/**
133+
* A MyBatis Mapper XML file.
134+
*/
135+
class MyBatisMapperXmlFile extends XmlFile {
136+
MyBatisMapperXmlFile() {
137+
count(XmlElement e | e = this.getAChild()) = 1 and
138+
this.getAChild().getName() = "mapper"
139+
}
140+
}
141+
142+
/**
143+
* An XML element in a `MyBatisMapperXMLFile`.
144+
*/
145+
class MyBatisMapperXmlElement extends XmlElement {
146+
MyBatisMapperXmlElement() { this.getFile() instanceof MyBatisMapperXmlFile }
147+
148+
/**
149+
* Gets the value for this element, with leading and trailing whitespace trimmed.
150+
*/
151+
string getValue() { result = this.allCharactersString().trim() }
152+
153+
/**
154+
* Gets the reference type bound to MyBatis Mapper XML File.
155+
*/
156+
RefType getNamespaceRefType() {
157+
result.getQualifiedName() = this.getAttribute("namespace").getValue()
158+
}
159+
}
160+
161+
/**
162+
* An MyBatis Mapper sql operation element.
163+
*/
164+
abstract class MyBatisMapperSqlOperation extends MyBatisMapperXmlElement {
165+
/**
166+
* Gets the value of the `id` attribute of MyBatis Mapper sql operation element.
167+
*/
168+
string getId() { result = this.getAttribute("id").getValue() }
169+
170+
/**
171+
* Gets the `<include>` element in a `MyBatisMapperSqlOperation`.
172+
*/
173+
MyBatisMapperInclude getInclude() { result = this.getAChild*() }
174+
175+
/**
176+
* Gets the method bound to MyBatis Mapper XML File.
177+
*/
178+
Method getMapperMethod() {
179+
result.getName() = this.getId() and
180+
result.getDeclaringType() = this.getParent().(MyBatisMapperXmlElement).getNamespaceRefType()
181+
}
182+
}
183+
184+
/**
185+
* A `<insert>` element in a `MyBatisMapperSqlOperation`.
186+
*/
187+
class MyBatisMapperInsert extends MyBatisMapperSqlOperation {
188+
MyBatisMapperInsert() { this.getName() = "insert" }
189+
}
190+
191+
/**
192+
* A `<update>` element in a `MyBatisMapperSqlOperation`.
193+
*/
194+
class MyBatisMapperUpdate extends MyBatisMapperSqlOperation {
195+
MyBatisMapperUpdate() { this.getName() = "update" }
196+
}
197+
198+
/**
199+
* A `<delete>` element in a `MyBatisMapperSqlOperation`.
200+
*/
201+
class MyBatisMapperDelete extends MyBatisMapperSqlOperation {
202+
MyBatisMapperDelete() { this.getName() = "delete" }
203+
}
204+
205+
/**
206+
* A `<select>` element in a `MyBatisMapperSqlOperation`.
207+
*/
208+
class MyBatisMapperSelect extends MyBatisMapperSqlOperation {
209+
MyBatisMapperSelect() { this.getName() = "select" }
210+
}
211+
212+
/**
213+
* A `<sql>` element in a `MyBatisMapperXMLElement`.
214+
*/
215+
class MyBatisMapperSql extends MyBatisMapperXmlElement {
216+
MyBatisMapperSql() { this.getName() = "sql" }
217+
218+
/**
219+
* Gets the value of the `id` attribute of this `<sql>`.
220+
*/
221+
string getId() { result = this.getAttribute("id").getValue() }
222+
}
223+
224+
/**
225+
* A `<include>` element in a `MyBatisMapperXMLElement`.
226+
*/
227+
class MyBatisMapperInclude extends MyBatisMapperXmlElement {
228+
MyBatisMapperInclude() { this.getName() = "include" }
229+
230+
/**
231+
* Gets the value of the `refid` attribute of this `<include>`.
232+
*/
233+
string getRefid() { result = this.getAttribute("refid").getValue() }
234+
}
235+
236+
/**
237+
* A `<foreach>` element in a `MyBatisMapperXMLElement`.
238+
*/
239+
class MyBatisMapperForeach extends MyBatisMapperXmlElement {
240+
MyBatisMapperForeach() { this.getName() = "foreach" }
241+
}

java/ql/lib/semmle/code/java/security/CsrfUnprotectedRequestTypeQuery.qll

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
import java
44
private import semmle.code.java.frameworks.spring.SpringController
5+
private import semmle.code.java.frameworks.MyBatis
56

67
/** A method that is not protected from CSRF by default. */
78
abstract class CsrfUnprotectedMethod extends Method { }

java/ql/src/experimental/Security/CWE/CWE-089/MyBatisCommonLib.qll

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
deprecated module;
55

66
import java
7-
import semmle.code.xml.MyBatisMapperXML
87
import semmle.code.java.dataflow.FlowSources
98
import semmle.code.java.frameworks.MyBatis
109
import semmle.code.java.frameworks.Properties

java/ql/src/experimental/Security/CWE/CWE-089/MyBatisMapperXmlSqlInjectionLib.qll

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
deprecated module;
55

66
import java
7-
import semmle.code.xml.MyBatisMapperXML
7+
import semmle.code.java.frameworks.MyBatis
88
import semmle.code.java.dataflow.FlowSources
99
import semmle.code.java.frameworks.Properties
1010

0 commit comments

Comments
 (0)