Skip to content

Java: Remove dependency to the CodeQL java query pack. #88

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Dec 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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() + "\""
}
Loading