Skip to content

Commit c8b1bc3

Browse files
committed
Enhance the query
1 parent eeac7e3 commit c8b1bc3

File tree

3 files changed

+24
-40
lines changed

3 files changed

+24
-40
lines changed

java/ql/src/experimental/Security/CWE/CWE-016/InsecureSpringActuatorConfig.ql

Lines changed: 21 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
/**
22
* @name Insecure Spring Boot Actuator Configuration
3-
* @description Exposed Spring Boot Actuator through configuration files without declarative or procedural security enforcement leads to information leak or even remote code execution.
3+
* @description Exposed Spring Boot Actuator through configuration files without declarative or procedural
4+
* security enforcement leads to information leak or even remote code execution.
45
* @kind problem
56
* @id java/insecure-spring-actuator-config
67
* @tags security
@@ -9,7 +10,6 @@
910

1011
import java
1112
import semmle.code.configfiles.ConfigFiles
12-
import semmle.code.java.security.SensitiveActions
1313
import semmle.code.xml.MavenPom
1414

1515
/** The parent node of the `org.springframework.boot` group. */
@@ -26,7 +26,10 @@ class SpringBootPom extends Pom {
2626
this.getADependency().getArtifact().getValue() = "spring-boot-starter-actuator"
2727
}
2828

29-
/** Holds if the Spring Boot Security module is used in the project, which brings in other security related libraries. */
29+
/**
30+
* Holds if the Spring Boot Security module is used in the project, which brings in other security
31+
* related libraries.
32+
*/
3033
predicate isSpringBootSecurityUsed() {
3134
this.getADependency().getArtifact().getValue() = "spring-boot-starter-security"
3235
}
@@ -38,14 +41,14 @@ class ApplicationProperties extends ConfigPair {
3841
}
3942

4043
/** The configuration property `management.security.enabled`. */
41-
class ManagementSecurityEnabled extends ApplicationProperties {
42-
ManagementSecurityEnabled() { this.getNameElement().getName() = "management.security.enabled" }
44+
class ManagementSecurityConfig extends ApplicationProperties {
45+
ManagementSecurityConfig() { this.getNameElement().getName() = "management.security.enabled" }
4346

44-
string getManagementSecurityEnabled() { result = this.getValueElement().getValue() }
47+
string getValue() { result = this.getValueElement().getValue().trim() }
4548

46-
predicate hasSecurityDisabled() { getManagementSecurityEnabled() = "false" }
49+
predicate hasSecurityDisabled() { getValue() = "false" }
4750

48-
predicate hasSecurityEnabled() { getManagementSecurityEnabled() = "true" }
51+
predicate hasSecurityEnabled() { getValue() = "true" }
4952
}
5053

5154
/** The configuration property `management.endpoints.web.exposure.include`. */
@@ -54,56 +57,37 @@ class ManagementEndPointInclude extends ApplicationProperties {
5457
this.getNameElement().getName() = "management.endpoints.web.exposure.include"
5558
}
5659

57-
string getManagementEndPointInclude() { result = this.getValueElement().getValue().trim() }
58-
}
59-
60-
/** The configuration property `management.endpoints.web.exposure.exclude`. */
61-
class ManagementEndPointExclude extends ApplicationProperties {
62-
ManagementEndPointExclude() {
63-
this.getNameElement().getName() = "management.endpoints.web.exposure.exclude"
64-
}
65-
66-
string getManagementEndPointExclude() { result = this.getValueElement().getValue().trim() }
67-
}
68-
69-
/** Holds if an application handles sensitive information judging by its variable names. */
70-
predicate isProtectedApp() {
71-
exists(VarAccess va | va.getVariable().getName().regexpMatch(getCommonSensitiveInfoRegex()))
60+
string getValue() { result = this.getValueElement().getValue().trim() }
7261
}
7362

7463
from SpringBootPom pom, ApplicationProperties ap, Dependency d
7564
where
76-
isProtectedApp() and
7765
pom.isSpringBootActuatorUsed() and
7866
not pom.isSpringBootSecurityUsed() and
7967
ap.getFile()
8068
.getParentContainer()
8169
.getAbsolutePath()
8270
.matches(pom.getFile().getParentContainer().getAbsolutePath() + "%") and // in the same sub-directory
83-
exists(string s | s = pom.getParentElement().getVersionString() |
84-
s.regexpMatch("1\\.[0|1|2|3|4].*") and
85-
not exists(ManagementSecurityEnabled me |
71+
exists(string springBootVersion | springBootVersion = pom.getParentElement().getVersionString() |
72+
springBootVersion.regexpMatch("1\\.[0-4].*") and // version 1.0, 1.1, ..., 1.4
73+
not exists(ManagementSecurityConfig me |
8674
me.hasSecurityEnabled() and me.getFile() = ap.getFile()
8775
)
8876
or
89-
s.regexpMatch("1\\.5.*") and
90-
exists(ManagementSecurityEnabled me | me.hasSecurityDisabled() and me.getFile() = ap.getFile())
77+
springBootVersion.matches("1.5%") and // version 1.5
78+
exists(ManagementSecurityConfig me | me.hasSecurityDisabled() and me.getFile() = ap.getFile())
9179
or
92-
s.regexpMatch("2.*") and
80+
springBootVersion.matches("2.%") and //version 2.x
9381
exists(ManagementEndPointInclude mi |
9482
mi.getFile() = ap.getFile() and
9583
(
96-
mi.getManagementEndPointInclude() = "*" // all endpoints are enabled
84+
mi.getValue() = "*" // all endpoints are enabled
9785
or
98-
mi.getManagementEndPointInclude()
86+
mi.getValue()
9987
.matches([
10088
"%dump%", "%trace%", "%logfile%", "%shutdown%", "%startup%", "%mappings%", "%env%",
10189
"%beans%", "%sessions%"
102-
]) // all endpoints apart from '/health' and '/info' are considered sensitive
103-
) and
104-
not exists(ManagementEndPointExclude mx |
105-
mx.getFile() = ap.getFile() and
106-
mx.getManagementEndPointExclude() = mi.getManagementEndPointInclude()
90+
]) // confidential endpoints to check although all endpoints apart from '/health' and '/info' are considered sensitive by Spring
10791
)
10892
)
10993
) and

java/ql/src/experimental/Security/CWE/CWE-016/application.properties

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
# vulnerable configuration (spring boot 1.5+): requires value false to expose sensitive actuators
88
management.security.enabled=false
99

10-
# vulnerable configuration (spring boot 2+): exposes health and info only by default
10+
# vulnerable configuration (spring boot 2+): exposes health and info only by default, here overridden to expose everything
1111
management.endpoints.web.exposure.include=*
1212

1313

@@ -18,5 +18,5 @@ management.security.enabled=true
1818
# safe configuration (spring boot 1.5+): requires value false to expose sensitive actuators
1919
management.security.enabled=true
2020

21-
# safe configuration (spring boot 2+): exposes health and info only by default
21+
# safe configuration (spring boot 2+): exposes health and info only by default, here overridden to expose one additional endpoint which we assume is intentional and safe.
2222
management.endpoints.web.exposure.include=beans,info,health

java/ql/test/experimental/query-tests/security/CWE-016/application.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
# vulnerable configuration (spring boot 1.5+): requires value false to expose sensitive actuators
66
management.security.enabled=false
77

8-
# vulnerable configuration (spring boot 2+): exposes health and info only by default
8+
# vulnerable configuration (spring boot 2+): exposes health and info only by default, here overridden to expose everything
99
management.endpoints.web.exposure.include=*
1010
management.endpoints.web.exposure.exclude=beans
1111

0 commit comments

Comments
 (0)