Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit db61a2d

Browse files
author
Stephan Brandauer
committed
Java: share isKnownKind between modes
1 parent d93ad9b commit db61a2d

3 files changed

Lines changed: 34 additions & 53 deletions

File tree

java/ql/src/Telemetry/AutomodelApplicationModeCharacteristics.qll

Lines changed: 2 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ private import semmle.code.java.Expr as Expr
1414
private import semmle.code.java.security.QueryInjection
1515
private import semmle.code.java.security.RequestForgery
1616
private import semmle.code.java.dataflow.internal.ModelExclusions as ModelExclusions
17+
private import AutomodelSharedUtil as AutomodelSharedUtil
1718
import AutomodelSharedCharacteristics as SharedCharacteristics
1819
import AutomodelEndpointTypes as AutomodelEndpointTypes
1920

@@ -51,31 +52,7 @@ module ApplicationCandidatesImpl implements SharedCharacteristics::CandidateSig
5152

5253
RelatedLocation asLocation(Endpoint e) { result = e.asExpr() }
5354

54-
predicate isKnownKind(string kind, string humanReadableKind, EndpointType type) {
55-
kind = "read-file" and
56-
humanReadableKind = "read file" and
57-
type instanceof AutomodelEndpointTypes::TaintedPathSinkType
58-
or
59-
kind = "create-file" and
60-
humanReadableKind = "create file" and
61-
type instanceof AutomodelEndpointTypes::TaintedPathSinkType
62-
or
63-
kind = "sql" and
64-
humanReadableKind = "mad modeled sql" and
65-
type instanceof AutomodelEndpointTypes::SqlSinkType
66-
or
67-
kind = "open-url" and
68-
humanReadableKind = "open url" and
69-
type instanceof AutomodelEndpointTypes::RequestForgerySinkType
70-
or
71-
kind = "jdbc-url" and
72-
humanReadableKind = "jdbc url" and
73-
type instanceof AutomodelEndpointTypes::RequestForgerySinkType
74-
or
75-
kind = "command-injection" and
76-
humanReadableKind = "command injection" and
77-
type instanceof AutomodelEndpointTypes::CommandInjectionSinkType
78-
}
55+
predicate isKnownKind = AutomodelSharedUtil::isKnownKind/3;
7956

8057
predicate isSink(Endpoint e, string kind) {
8158
exists(string package, string type, string name, string signature, string ext, string input |
@@ -105,9 +82,6 @@ module ApplicationCandidatesImpl implements SharedCharacteristics::CandidateSig
10582
or
10683
exists(Call c | e.asExpr() = c.getQualifier() and input = "Argument[this]")
10784
)
108-
// exists(int paramIdx | e.isParameterOf(_, paramIdx) |
109-
// if paramIdx = -1 then input = "Argument[this]" else input = "Argument[" + paramIdx + "]"
110-
// )
11185
}
11286

11387
/**

java/ql/src/Telemetry/AutomodelFrameworkModeCharacteristics.qll

Lines changed: 2 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ private import semmle.code.java.Expr as Expr
1414
private import semmle.code.java.security.QueryInjection
1515
private import semmle.code.java.security.RequestForgery
1616
private import semmle.code.java.dataflow.internal.ModelExclusions as ModelExclusions
17+
private import AutomodelSharedUtil as AutomodelSharedUtil
1718
import AutomodelSharedCharacteristics as SharedCharacteristics
1819
import AutomodelEndpointTypes as AutomodelEndpointTypes
1920

@@ -46,31 +47,7 @@ module FrameworkCandidatesImpl implements SharedCharacteristics::CandidateSig {
4647

4748
RelatedLocation asLocation(Endpoint e) { result = e.asParameter() }
4849

49-
predicate isKnownKind(string kind, string humanReadableKind, EndpointType type) {
50-
kind = "read-file" and
51-
humanReadableKind = "read file" and
52-
type instanceof AutomodelEndpointTypes::TaintedPathSinkType
53-
or
54-
kind = "create-file" and
55-
humanReadableKind = "create file" and
56-
type instanceof AutomodelEndpointTypes::TaintedPathSinkType
57-
or
58-
kind = "sql" and
59-
humanReadableKind = "mad modeled sql" and
60-
type instanceof AutomodelEndpointTypes::SqlSinkType
61-
or
62-
kind = "open-url" and
63-
humanReadableKind = "open url" and
64-
type instanceof AutomodelEndpointTypes::RequestForgerySinkType
65-
or
66-
kind = "jdbc-url" and
67-
humanReadableKind = "jdbc url" and
68-
type instanceof AutomodelEndpointTypes::RequestForgerySinkType
69-
or
70-
kind = "command-injection" and
71-
humanReadableKind = "command injection" and
72-
type instanceof AutomodelEndpointTypes::CommandInjectionSinkType
73-
}
50+
predicate isKnownKind = AutomodelSharedUtil::isKnownKind/3;
7451

7552
predicate isSink(Endpoint e, string kind) {
7653
exists(string package, string type, string name, string signature, string ext, string input |

java/ql/src/Telemetry/AutomodelSharedUtil.qll

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
import AutomodelEndpointTypes as AutomodelEndpointTypes
2+
13
/**
24
* A helper class to represent a string value that can be returned by a query using $@ notation.
35
*
@@ -19,3 +21,31 @@ class DollarAtString extends string {
1921
path = this and sl = 1 and sc = 1 and el = 1 and ec = 1
2022
}
2123
}
24+
25+
predicate isKnownKind(
26+
string kind, string humanReadableKind, AutomodelEndpointTypes::EndpointType type
27+
) {
28+
kind = "read-file" and
29+
humanReadableKind = "read file" and
30+
type instanceof AutomodelEndpointTypes::TaintedPathSinkType
31+
or
32+
kind = "create-file" and
33+
humanReadableKind = "create file" and
34+
type instanceof AutomodelEndpointTypes::TaintedPathSinkType
35+
or
36+
kind = "sql" and
37+
humanReadableKind = "mad modeled sql" and
38+
type instanceof AutomodelEndpointTypes::SqlSinkType
39+
or
40+
kind = "open-url" and
41+
humanReadableKind = "open url" and
42+
type instanceof AutomodelEndpointTypes::RequestForgerySinkType
43+
or
44+
kind = "jdbc-url" and
45+
humanReadableKind = "jdbc url" and
46+
type instanceof AutomodelEndpointTypes::RequestForgerySinkType
47+
or
48+
kind = "command-injection" and
49+
humanReadableKind = "command injection" and
50+
type instanceof AutomodelEndpointTypes::CommandInjectionSinkType
51+
}

0 commit comments

Comments
 (0)