Skip to content

Commit 5faa61a

Browse files
author
Alvaro Muñoz
authored
Merge branch 'main' into fix_csharp_asPartialModel
2 parents ac188d6 + 1e9f745 commit 5faa61a

File tree

90 files changed

+287
-131
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

90 files changed

+287
-131
lines changed

README.md

Lines changed: 3 additions & 0 deletions
File renamed without changes.

cpp/src/qlpack.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
library: false
22
name: githubsecuritylab/codeql-cpp-queries
3-
version: 0.0.2
3+
version: 0.0.3
44
suites: suites
55
defaultSuiteFile: suites/cpp.qls
66
dependencies:

cpp/src/suites/cpp.qls

Lines changed: 22 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,25 @@
1-
- description: "GitHub's Community Packs Ruby Extended Suite"
1+
- description: "GitHub's Community Packs C/C++ Extended Suite"
22

3-
- qlpack: github-queries-ruby
3+
- queries: '.'
4+
from: githubsecuritylab/codeql-cpp-queries
45

5-
- import: codeql-suites/ruby-security-extended.qls
6-
from: codeql/ruby-queries
6+
- include:
7+
kind:
8+
- problem
9+
- path-problem
10+
precision:
11+
- very-high
12+
- high
13+
- medium
14+
- low
15+
16+
# Remove debugging, and audit queries
17+
- exclude:
18+
tags contain:
19+
- debugging
20+
- audit
21+
22+
# Remove local testing folders
723
- exclude:
8-
id:
9-
- rb/hardcoded-credentials
24+
query path:
25+
- /testing\/.*/
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
---
2+
lockVersion: 1.0.0
3+
dependencies: {}
4+
compiled: false

csharp/ext/codeql-pack.lock.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
---
2+
lockVersion: 1.0.0
3+
dependencies: {}
4+
compiled: false
File renamed without changes.
File renamed without changes.

csharp/src/qlpack.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
library: false
22
name: githubsecuritylab/codeql-csharp-queries
3-
version: 0.0.2
3+
version: 0.0.3
44
suites: suites
55
defaultSuiteFile: suites/csharp.qls
66
dependencies:

csharp/src/security/CWE-760/HardcodedSalt.ql

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,8 @@ import csharp
1414
private import semmle.code.csharp.frameworks.Moq
1515
private import semmle.code.csharp.dataflow.DataFlow::DataFlow::PathGraph
1616
// import semmle.code.csharp.frameworks.system.security.Cryptography
17-
private import github.Hardcoded
18-
private import github.Cryptography
17+
private import ghsl.Hardcoded
18+
private import ghsl.Cryptography
1919

2020
module HardcodedSalt {
2121
abstract class Source extends DataFlow::ExprNode { }

csharp/src/security/CWE-798/HardcodedCredentialsSymmetricSecurityKey.ql

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414

1515
import csharp
1616
private import DataFlow::PathGraph
17-
private import github.HardcodedCredentials
17+
private import ghsl.HardcodedCredentials
1818

1919
from DataFlow::PathNode source, DataFlow::PathNode sink, LiteralToSecurityKeyConfig config
2020
where config.hasFlowPath(source, sink)

csharp/src/suites/csharp.qls

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,12 @@
11
- description: "GitHub's Community Packs CSharp Extended Suite"
22

33
- queries: '.'
4-
from: githubsecuritylab/codeql-csharp
4+
from: githubsecuritylab/codeql-csharp-queries
55

66
- include:
77
kind:
88
- problem
99
- path-problem
10-
- metric
11-
- diagnostic
1210
precision:
1311
- very-high
1412
- high
File renamed without changes.
File renamed without changes.

go/src/audit/CWE-089/SqlInjectionAudit.ql

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
import go
1515
import semmle.go.security.SqlInjection
1616
import DataFlow::PathGraph
17-
import github.Utils
17+
import ghsl.Utils
1818

1919
/**
2020
* A taint-tracking configuration for detecting SQL injection vulnerabilities.

go/src/qlpack.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
library: false
22
name: githubsecuritylab/codeql-go-queries
3-
version: 0.0.2
3+
version: 0.0.3
44
suites: suites
55
defaultSuiteFile: suites/go.qls
66
dependencies:

go/src/security/CWE-078/CommandInjection.ql

Lines changed: 12 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -13,35 +13,27 @@
1313

1414
import go
1515
import semmle.go.security.CommandInjection
16-
import semmle.go.security.CommandInjectionCustomizations::CommandInjection
16+
import DataFlow::PathGraph
17+
import semmle.go.security.FlowSources
1718

1819
//Override CommandInjection::Configuration to use the in-use sources
19-
class InUseAsSource extends Source instanceof UntrustedFlowSource {
20-
InUseAsSource() {
20+
class InUseCommandInjectionConfiguration extends CommandInjection::Configuration {
21+
override predicate isSource(DataFlow::Node node) {
2122
exists(UntrustedFlowSource source, Function function, DataFlow::CallNode callNode |
22-
source.asExpr() = this.asExpr() and
23+
source.asExpr() = node.asExpr() and
24+
2325
source.(DataFlow::ExprNode).asExpr().getEnclosingFunction() = function.getFuncDecl() and
2426
(
2527
// function is called directly
2628
callNode.getACallee() = function.getFuncDecl()
27-
or
29+
2830
// function is passed to another function to be called
29-
callNode.getCall().getAnArgument().(Ident).refersTo(function) //NEW with 2.13.2: or c.getASyntacticArgument().asExpr().(Ident).refersTo(f)
30-
)
31+
or callNode.getCall().getAnArgument().(Ident).refersTo(function) //NEW with 2.13.2: or c.getASyntacticArgument().asExpr().(Ident).refersTo(f)
32+
)
3133
)
3234
}
3335
}
3436

35-
module Flow =
36-
DataFlow::MergePathGraph<CommandInjection::Flow::PathNode,
37-
CommandInjection::DoubleDashSanitizingFlow::PathNode, CommandInjection::Flow::PathGraph,
38-
CommandInjection::DoubleDashSanitizingFlow::PathGraph>;
39-
40-
import Flow::PathGraph
41-
42-
from Flow::PathNode source, Flow::PathNode sink
43-
where
44-
CommandInjection::Flow::flowPath(source.asPathNode1(), sink.asPathNode1()) or
45-
CommandInjection::DoubleDashSanitizingFlow::flowPath(source.asPathNode2(), sink.asPathNode2())
46-
select sink.getNode(), source, sink, "This command depends on a $@.", source.getNode(),
47-
"user-provided value"
37+
from InUseCommandInjectionConfiguration cfg, CommandInjection::DoubleDashSanitizingConfiguration cfg2, DataFlow::PathNode source, DataFlow::PathNode sink
38+
where (cfg.hasFlowPath(source, sink) or cfg2.hasFlowPath(source, sink))
39+
select sink.getNode(), source, sink, "This command depends on a $@.", source.getNode(), "user-provided value"
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
import go
2-
import github.Utils
2+
import ghsl.Utils
33

44
query predicate dynamicStrings(DataFlow::ExprNode node) { node instanceof DynamicStrings }
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
---
2+
lockVersion: 1.0.0
3+
dependencies: {}
4+
compiled: false

java/ext/codeql-pack.lock.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
---
2+
lockVersion: 1.0.0
3+
dependencies: {}
4+
compiled: false
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.

java/src/CVEs/CVE-2022-22965.ql

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
import java
1212
import semmle.code.java.dataflow.FlowSources
1313
import Spring4ShellFlow::PathGraph
14-
import github.BeanManipulation
14+
import ghsl.BeanManipulation
1515

1616
private module Spring4ShellConfig implements DataFlow::ConfigSig {
1717
predicate isSource(DataFlow::Node source) {

java/src/qlpack.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
library: false
22
name: githubsecuritylab/codeql-java-queries
3-
version: 0.0.2
3+
version: 0.0.3
44
suites: suites
55
defaultSuiteFile: suites/java.qls
66
dependencies:

java/src/security/CWE-022/UnsafeURICheck.ql

Lines changed: 57 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -13,33 +13,81 @@ import java
1313
import semmle.code.java.dataflow.FlowSources
1414
import UnsafeURICheckFlow::PathGraph
1515

16-
// Reference: https://mail-archives.apache.org/mod_mbox/ambari-user/202102.mbox/%3CCAEJYuxEQZ_aPwJdAaSxPu-Dva%3Dhc7zZUx3-pzBORbd23g%2BGH1A%40mail.gmail.com%3E
16+
// Example: https://mail-archives.apache.org/mod_mbox/ambari-user/202102.mbox/%3CCAEJYuxEQZ_aPwJdAaSxPu-Dva%3Dhc7zZUx3-pzBORbd23g%2BGH1A%40mail.gmail.com%3E
1717
class ServletFilterInterface extends Interface {
1818
ServletFilterInterface() { this.hasQualifiedName("javax.servlet", "Filter") }
1919
}
2020

21+
class ContainerRequestFilterInterface extends Interface {
22+
ContainerRequestFilterInterface() {
23+
this.hasQualifiedName("javax.ws.rs.container", "ContainerRequestFilter")
24+
}
25+
}
26+
2127
class ServletRequestInterface extends Interface {
2228
ServletRequestInterface() { this.hasQualifiedName("javax.servlet.http", "HttpServletRequest") }
2329
}
2430

25-
class GetRequestURIMethodAccess extends MethodAccess {
26-
GetRequestURIMethodAccess() {
31+
class UriInfoType extends RefType {
32+
UriInfoType() { this.hasQualifiedName("javax.ws.rs.core", "UriInfo") }
33+
}
34+
35+
abstract class FilterMethod extends Method { }
36+
37+
string getSecurityFilterRegexp() { result = ".*(auth|security|jwt|allow|block|login).*" }
38+
39+
class FilterContainerRequestFilterMethod extends FilterMethod {
40+
FilterContainerRequestFilterMethod() {
41+
exists(Method m |
42+
this.overrides*(m) and
43+
m.getName() = "filter" and
44+
m.getDeclaringType() instanceof ContainerRequestFilterInterface and
45+
this.getDeclaringType().getName().toLowerCase().regexpMatch(getSecurityFilterRegexp())
46+
)
47+
}
48+
}
49+
50+
class DoFilterServletRequestMethod extends FilterMethod {
51+
DoFilterServletRequestMethod() {
52+
exists(Method m |
53+
this.overrides*(m) and
54+
m.getName() = "doFilter" and
55+
m.getDeclaringType() instanceof ServletFilterInterface and
56+
this.getDeclaringType().getName().toLowerCase().regexpMatch(getSecurityFilterRegexp())
57+
)
58+
}
59+
}
60+
61+
abstract class GetUriPathCall extends MethodCall { }
62+
63+
class GetRequestURIMethodCall extends GetUriPathCall {
64+
GetRequestURIMethodCall() {
2765
this.getMethod().getName() = "getRequestURI" and
2866
this.getMethod().getDeclaringType() instanceof ServletRequestInterface
2967
}
3068
}
3169

70+
class UriInfoGetPathMethodCall extends GetUriPathCall {
71+
UriInfoGetPathMethodCall() {
72+
this.getMethod().getName() = "getPath" and
73+
this.getMethod().getDeclaringType() instanceof UriInfoType
74+
}
75+
}
76+
3277
private module UnsafeURICheckConfig implements DataFlow::ConfigSig {
3378
predicate isSource(DataFlow::Node source) {
34-
exists(GetRequestURIMethodAccess ma |
35-
ma.getEnclosingCallable().getDeclaringType().getASourceSupertype*() instanceof
36-
ServletFilterInterface and
37-
source.asExpr() = ma
79+
exists(GetUriPathCall call, FilterMethod m |
80+
source.asExpr() = call and
81+
(
82+
m.polyCalls*(call.getEnclosingCallable()) or
83+
m.polyCalls*(call.getEnclosingCallable().getEnclosingCallable()) or
84+
m.polyCalls*(call.getEnclosingCallable().getEnclosingCallable().getEnclosingCallable())
85+
)
3886
)
3987
}
4088

4189
predicate isSink(DataFlow::Node sink) {
42-
exists(MethodAccess ma |
90+
exists(MethodCall ma |
4391
// java.util.regex.Pattern.matcher("aaaaab");
4492
ma.getMethod().getName() = "matcher" and
4593
ma.getMethod().getDeclaringType().hasQualifiedName("java.util.regex", "Pattern") and
@@ -54,7 +102,7 @@ private module UnsafeURICheckConfig implements DataFlow::ConfigSig {
54102
ma.getMethod().getDeclaringType() instanceof TypeString and
55103
sink.asExpr() = ma.getQualifier()
56104
or
57-
ma.getMethod().getName() = ["startsWith", "endsWith"] and
105+
ma.getMethod().getName() = ["contains", "startsWith", "endsWith"] and
58106
ma.getMethod().getDeclaringType() instanceof TypeString and
59107
not ma.getArgument(0).(CompileTimeConstantExpr).getStringValue() = "/" and
60108
sink.asExpr() = ma.getQualifier()

java/src/security/CWE-078/CommandInjectionRuntimeExec.ql

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
*/
1212

1313
import DataFlow::PathGraph
14-
import github.CommandInjectionRuntimeExec
14+
import ghsl.CommandInjectionRuntimeExec
1515

1616
class RemoteSource extends Source {
1717
RemoteSource() { this instanceof RemoteFlowSource }

java/src/security/CWE-078/CommandInjectionRuntimeExecLocal.ql

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
*/
1313

1414
import DataFlow::PathGraph
15-
import github.CommandInjectionRuntimeExec
15+
import ghsl.CommandInjectionRuntimeExec
1616

1717
class LocalSource extends Source {
1818
LocalSource() { this instanceof LocalUserInput }

java/src/security/CWE-078/CommandInjectionRuntimeExecTest.ql

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
* external/cwe/cwe-078
1313
*/
1414

15-
import github.CommandInjectionRuntimeExec
15+
import ghsl.CommandInjectionRuntimeExec
1616

1717
class DataSource extends Source {
1818
DataSource() { this instanceof RemoteFlowSource or this instanceof LocalUserInput }

java/src/security/CWE-078/CommandInjectionRuntimeExecTestPath.ql

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
*/
1414

1515
import DataFlow::PathGraph
16-
import github.CommandInjectionRuntimeExec
16+
import ghsl.CommandInjectionRuntimeExec
1717

1818
class DataSource extends Source {
1919
DataSource() { this instanceof RemoteFlowSource or this instanceof LocalUserInput }

java/src/security/CWE-326/Base64Encryption.ql

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ import semmle.code.java.dataflow.FlowSources
1717
import semmle.code.java.dataflow.TaintTracking2
1818
// import DataFlow::PathGraph
1919
// Internal
20-
import github.SensitiveInformation
20+
import ghsl.SensitiveInformation
2121

2222
class Base64Sinks extends DataFlow::Node {
2323
Base64Sinks() {

java/src/security/CWE-470/BeanManipulation.ql

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
import java
1414
import semmle.code.java.dataflow.FlowSources
1515
import BeanManipulationFlow::PathGraph
16-
import github.BeanManipulation
16+
import ghsl.BeanManipulation
1717

1818
private module BeanManipulationConfig implements DataFlow::ConfigSig {
1919
predicate isSource(DataFlow::Node source) { source instanceof RemoteFlowSource }

java/src/security/CWE-532/SensitiveInformation.ql

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,8 @@ import semmle.code.java.dataflow.FlowSources
1717
import semmle.code.java.dataflow.TaintTracking2
1818
//import DataFlow::PathGraph
1919
// Internal
20-
import github.Logging
21-
import github.SensitiveInformation
20+
import ghsl.Logging
21+
import ghsl.SensitiveInformation
2222

2323
module SensitiveInformationConfig implements DataFlow::ConfigSig {
2424
predicate isSource(DataFlow::Node source) { source instanceof SensitiveInformationSources }

java/src/security/CWE-611/XXELocal.ql

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ import semmle.code.java.security.XmlParsers
1818
import semmle.code.java.dataflow.FlowSources
1919
import semmle.code.java.dataflow.TaintTracking2
2020
//import DataFlow::PathGraph
21-
import github.LocalSources
21+
import ghsl.LocalSources
2222

2323
module SafeSAXSourceFlowConfig implements DataFlow::ConfigSig {
2424
predicate isSource(DataFlow::Node src) { src.asExpr() instanceof SafeSaxSource }

java/src/security/CWE-798/HardcodedBase64Usage.ql

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,8 @@ import semmle.code.java.dataflow.FlowSources
1717
import semmle.code.java.dataflow.TaintTracking2
1818
import DataFlow::PathGraph
1919
// Internal
20-
import github.Encoding
21-
import github.Hardcoded
20+
import ghsl.Encoding
21+
import ghsl.Hardcoded
2222

2323
class HardcodedPasswordBase64 extends TaintTracking::Configuration {
2424
HardcodedPasswordBase64() { this = "HardcodedPasswordBase64" }

java/src/suites/java.qls

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,8 @@
1-
# https://codeql.github.com/docs/codeql-cli/creating-codeql-query-suites/
2-
31
- description: "GitHub's Community Packs Java/Kotlin Extended Suite"
42

53
- queries: '.'
6-
from: githubsecuritylab/java-queries
4+
from: githubsecuritylab/codeql-java-queries
75

8-
# GitHub's Community Packs Java/Kotlin Suite
96
- include:
107
kind:
118
- problem

0 commit comments

Comments
 (0)