Skip to content

Commit 4eb4067

Browse files
Jami CogswellJami Cogswell
authored andcommitted
Java: fix test case for version 1.4
Need the existence of an ApplicationProperties File, not an ApplicationProperties ConfigPair
1 parent a7f57e6 commit 4eb4067

File tree

3 files changed

+39
-34
lines changed

3 files changed

+39
-34
lines changed

java/ql/lib/semmle/code/java/security/SpringBootActuatorsConfigQuery.qll

Lines changed: 36 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -28,12 +28,17 @@ class SpringBootPom extends Pom {
2828
}
2929

3030
/** The properties file `application.properties`. */
31-
class ApplicationProperties extends ConfigPair {
32-
ApplicationProperties() { this.getFile().getBaseName() = "application.properties" }
31+
class ApplicationPropertiesFile extends File {
32+
ApplicationPropertiesFile() { this.getBaseName() = "application.properties" }
33+
}
34+
35+
/** A name-value pair stored in an `application.properties` file. */
36+
class ApplicationPropertiesConfigPair extends ConfigPair {
37+
ApplicationPropertiesConfigPair() { this.getFile() instanceof ApplicationPropertiesFile }
3338
}
3439

3540
/** The configuration property `management.security.enabled`. */
36-
class ManagementSecurityConfig extends ApplicationProperties {
41+
class ManagementSecurityConfig extends ApplicationPropertiesConfigPair {
3742
ManagementSecurityConfig() { this.getNameElement().getName() = "management.security.enabled" }
3843

3944
/** Gets the whitespace-trimmed value of this property. */
@@ -47,7 +52,7 @@ class ManagementSecurityConfig extends ApplicationProperties {
4752
}
4853

4954
/** The configuration property `management.endpoints.web.exposure.include`. */
50-
class ManagementEndPointInclude extends ApplicationProperties {
55+
class ManagementEndPointInclude extends ApplicationPropertiesConfigPair {
5156
ManagementEndPointInclude() {
5257
this.getNameElement().getName() = "management.endpoints.web.exposure.include"
5358
}
@@ -60,33 +65,35 @@ class ManagementEndPointInclude extends ApplicationProperties {
6065
* Holds if `ApplicationProperties` ap of a repository managed by `SpringBootPom` pom
6166
* has a vulnerable configuration of Spring Boot Actuator management endpoints.
6267
*/
63-
predicate hasConfidentialEndPointExposed(SpringBootPom pom, ApplicationProperties ap) {
68+
predicate hasConfidentialEndPointExposed(SpringBootPom pom) {
6469
pom.isSpringBootActuatorUsed() and
6570
not pom.isSpringBootSecurityUsed() and
66-
ap.getFile()
67-
.getParentContainer()
68-
.getAbsolutePath()
69-
.matches(pom.getFile().getParentContainer().getAbsolutePath() + "%") and // in the same sub-directory
70-
exists(string springBootVersion | springBootVersion = pom.getParentElement().getVersionString() |
71-
springBootVersion.regexpMatch("1\\.[0-4].*") and // version 1.0, 1.1, ..., 1.4
72-
not exists(ManagementSecurityConfig me |
73-
me.hasSecurityEnabled() and me.getFile() = ap.getFile()
74-
)
75-
or
76-
springBootVersion.matches("1.5%") and // version 1.5
77-
exists(ManagementSecurityConfig me | me.hasSecurityDisabled() and me.getFile() = ap.getFile())
78-
or
79-
springBootVersion.matches("2.%") and //version 2.x
80-
exists(ManagementEndPointInclude mi |
81-
mi.getFile() = ap.getFile() and
82-
(
83-
mi.getValue() = "*" // all endpoints are enabled
84-
or
85-
mi.getValue()
86-
.matches([
87-
"%dump%", "%trace%", "%logfile%", "%shutdown%", "%startup%", "%mappings%", "%env%",
88-
"%beans%", "%sessions%"
89-
]) // confidential endpoints to check although all endpoints apart from '/health' and '/info' are considered sensitive by Spring
71+
exists(ApplicationPropertiesFile apFile |
72+
apFile
73+
.getParentContainer()
74+
.getAbsolutePath()
75+
.matches(pom.getFile().getParentContainer().getAbsolutePath() + "%") and // in the same sub-directory
76+
exists(string springBootVersion |
77+
springBootVersion = pom.getParentElement().getVersionString()
78+
|
79+
springBootVersion.regexpMatch("1\\.[0-4].*") and // version 1.0, 1.1, ..., 1.4
80+
not exists(ManagementSecurityConfig me | me.hasSecurityEnabled() and me.getFile() = apFile)
81+
or
82+
springBootVersion.matches("1.5%") and // version 1.5
83+
exists(ManagementSecurityConfig me | me.hasSecurityDisabled() and me.getFile() = apFile)
84+
or
85+
springBootVersion.matches("2.%") and //version 2.x
86+
exists(ManagementEndPointInclude mi |
87+
mi.getFile() = apFile and
88+
(
89+
mi.getValue() = "*" // all endpoints are enabled
90+
or
91+
mi.getValue()
92+
.matches([
93+
"%dump%", "%trace%", "%logfile%", "%shutdown%", "%startup%", "%mappings%",
94+
"%env%", "%beans%", "%sessions%"
95+
]) // confidential endpoints to check although all endpoints apart from '/health' and '/info' are considered sensitive by Spring
96+
)
9097
)
9198
)
9299
)

java/ql/src/Security/CWE/CWE-200/InsecureSpringActuatorConfig/InsecureSpringActuatorConfig.ql

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,9 @@ import java
1515
import semmle.code.xml.MavenPom
1616
import semmle.code.java.security.SpringBootActuatorsConfigQuery
1717

18-
from SpringBootPom pom, ApplicationProperties ap, Dependency d
18+
from SpringBootPom pom, Dependency d
1919
where
20-
hasConfidentialEndPointExposed(pom, ap) and
20+
hasConfidentialEndPointExposed(pom) and
2121
d = pom.getADependency() and
2222
d.getArtifact().getValue() = "spring-boot-starter-actuator"
2323
select d, "Insecure configuration of Spring Boot Actuator exposes sensitive endpoints."
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,4 @@
1-
#select
1+
| Version1.4-/bad/default/pom.xml:29:9:32:22 | dependency | Insecure configuration of Spring Boot Actuator exposes sensitive endpoints. |
22
| Version1.4-/bad/false/pom.xml:29:9:32:22 | dependency | Insecure configuration of Spring Boot Actuator exposes sensitive endpoints. |
33
| Version1.5/bad/pom.xml:29:9:32:22 | dependency | Insecure configuration of Spring Boot Actuator exposes sensitive endpoints. |
44
| Version2+/bad/pom.xml:29:9:32:22 | dependency | Insecure configuration of Spring Boot Actuator exposes sensitive endpoints. |
5-
testFailures
6-
| Version1.4-/bad/default/pom.xml:32:23:32:39 | $ Alert | Missing result: Alert |

0 commit comments

Comments
 (0)