Skip to content

Commit

Permalink
Merge pull request #88 from GitHubSecurityLab/java/removequerysuitede…
Browse files Browse the repository at this point in the history
…pendecy

Java: Remove dependency to the CodeQL java query pack.
  • Loading branch information
michaelnebel authored Dec 20, 2024
2 parents 853765d + 09a70a7 commit 7a6a715
Show file tree
Hide file tree
Showing 7 changed files with 125 additions and 10 deletions.
116 changes: 116 additions & 0 deletions java/lib/semmle/code/xml/MyBatisMapperXML.qll
Original file line number Diff line number Diff line change
@@ -0,0 +1,116 @@
/**
* Provides classes for working with MyBatis mapper xml files and their content.
*/

import java

/**
* MyBatis Mapper XML file.
*/
class MyBatisMapperXmlFile extends XmlFile {
MyBatisMapperXmlFile() {
count(XmlElement e | e = this.getAChild()) = 1 and
this.getAChild().getName() = "mapper"
}
}

/**
* An XML element in a `MyBatisMapperXMLFile`.
*/
class MyBatisMapperXmlElement extends XmlElement {
MyBatisMapperXmlElement() { this.getFile() instanceof MyBatisMapperXmlFile }

/**
* Gets the value for this element, with leading and trailing whitespace trimmed.
*/
string getValue() { result = this.allCharactersString().trim() }

/**
* Gets the reference type bound to MyBatis Mapper XML File.
*/
RefType getNamespaceRefType() {
result.getQualifiedName() = this.getAttribute("namespace").getValue()
}
}

/**
* An MyBatis Mapper sql operation element.
*/
abstract class MyBatisMapperSqlOperation extends MyBatisMapperXmlElement {
/**
* Gets the value of the `id` attribute of MyBatis Mapper sql operation element.
*/
string getId() { result = this.getAttribute("id").getValue() }

/**
* Gets the `<include>` element in a `MyBatisMapperSqlOperation`.
*/
MyBatisMapperInclude getInclude() { result = this.getAChild*() }

/**
* Gets the method bound to MyBatis Mapper XML File.
*/
Method getMapperMethod() {
result.getName() = this.getId() and
result.getDeclaringType() = this.getParent().(MyBatisMapperXmlElement).getNamespaceRefType()
}
}

/**
* A `<insert>` element in a `MyBatisMapperSqlOperation`.
*/
class MyBatisMapperInsert extends MyBatisMapperSqlOperation {
MyBatisMapperInsert() { this.getName() = "insert" }
}

/**
* A `<update>` element in a `MyBatisMapperSqlOperation`.
*/
class MyBatisMapperUpdate extends MyBatisMapperSqlOperation {
MyBatisMapperUpdate() { this.getName() = "update" }
}

/**
* A `<delete>` element in a `MyBatisMapperSqlOperation`.
*/
class MyBatisMapperDelete extends MyBatisMapperSqlOperation {
MyBatisMapperDelete() { this.getName() = "delete" }
}

/**
* A `<select>` element in a `MyBatisMapperSqlOperation`.
*/
class MyBatisMapperSelect extends MyBatisMapperSqlOperation {
MyBatisMapperSelect() { this.getName() = "select" }
}

/**
* A `<sql>` element in a `MyBatisMapperXMLElement`.
*/
class MyBatisMapperSql extends MyBatisMapperXmlElement {
MyBatisMapperSql() { this.getName() = "sql" }

/**
* Gets the value of the `id` attribute of this `<sql>`.
*/
string getId() { result = this.getAttribute("id").getValue() }
}

/**
* A `<include>` element in a `MyBatisMapperXMLElement`.
*/
class MyBatisMapperInclude extends MyBatisMapperXmlElement {
MyBatisMapperInclude() { this.getName() = "include" }

/**
* Gets the value of the `refid` attribute of this `<include>`.
*/
string getRefid() { result = this.getAttribute("refid").getValue() }
}

/**
* A `<foreach>` element in a `MyBatisMapperXMLElement`.
*/
class MyBatisMapperForeach extends MyBatisMapperXmlElement {
MyBatisMapperForeach() { this.getName() = "foreach" }
}
4 changes: 0 additions & 4 deletions java/src/codeql-pack.lock.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,6 @@ dependencies:
version: 1.1.5
codeql/java-all:
version: 4.2.0
codeql/java-queries:
version: 1.1.8
codeql/mad:
version: 1.0.11
codeql/rangeanalysis:
Expand All @@ -15,8 +13,6 @@ dependencies:
version: 1.0.11
codeql/ssa:
version: 1.0.11
codeql/suite-helpers:
version: 1.0.11
codeql/threat-models:
version: 1.0.11
codeql/tutorial:
Expand Down
1 change: 0 additions & 1 deletion java/src/qlpack.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,4 @@ suites: suites
defaultSuiteFile: suites/java.qls
dependencies:
codeql/java-all: '*'
codeql/java-queries: '*'
githubsecuritylab/codeql-java-libs: '*'
4 changes: 0 additions & 4 deletions java/test/codeql-pack.lock.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,6 @@ dependencies:
version: 1.1.5
codeql/java-all:
version: 4.2.0
codeql/java-queries:
version: 1.1.8
codeql/mad:
version: 1.0.11
codeql/rangeanalysis:
Expand All @@ -15,8 +13,6 @@ dependencies:
version: 1.0.11
codeql/ssa:
version: 1.0.11
codeql/suite-helpers:
version: 1.0.11
codeql/threat-models:
version: 1.0.11
codeql/tutorial:
Expand Down
1 change: 0 additions & 1 deletion java/test/qlpack.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ name: githubsecurtylab/codeql-java-tests
groups: [java, test]
dependencies:
codeql/java-all: '*'
codeql/java-queries: '*'
githubsecuritylab/codeql-java-queries: '*'
githubsecuritylab/codeql-java-libs: '*'
githubsecuritylab/codeql-java-library-sources: '*'
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import java
import semmle.code.java.security.DecompressionBombQuery
import TestUtilities.InlineFlowTest
import TaintFlowTestArgString<DecompressionBombsConfig, getArgString/2>

string getArgString(DataFlow::Node src, DataFlow::Node sink) {
exists(src) and
result = "\"" + sink.toString() + "\""
}

0 comments on commit 7a6a715

Please sign in to comment.