Skip to content

Commit da37a91

Browse files
Jami CogswellJami Cogswell
authored andcommitted
Java: add related location to alert message
1 parent 4f0cdad commit da37a91

File tree

3 files changed

+43
-14
lines changed

3 files changed

+43
-14
lines changed

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

Lines changed: 34 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -48,9 +48,6 @@ class ManagementSecurityConfig extends ApplicationPropertiesConfigPair {
4848

4949
/** Holds if `management.security.enabled` is set to `false`. */
5050
predicate hasSecurityDisabled() { this.getValue() = "false" }
51-
52-
/** Holds if `management.security.enabled` is set to `true`. */
53-
predicate hasSecurityEnabled() { this.getValue() = "true" }
5451
}
5552

5653
/** The configuration property `management.endpoints.web.exposure.include`. */
@@ -63,11 +60,37 @@ class ManagementEndPointInclude extends ApplicationPropertiesConfigPair {
6360
string getValue() { result = this.getValueElement().getValue().trim() }
6461
}
6562

63+
private newtype TOption =
64+
TNone() or
65+
TSome(ApplicationPropertiesConfigPair ap)
66+
67+
/**
68+
* An option type that is either a singleton `None` or a `Some` wrapping
69+
* the `ApplicationPropertiesConfigPair` type.
70+
*/
71+
class ApplicationPropertiesOption extends TOption {
72+
/** Gets a textual representation of this element. */
73+
string toString() {
74+
this = TNone() and result = "(none)"
75+
or
76+
result = this.asSome().toString()
77+
}
78+
79+
/** Gets the location of this element. */
80+
Location getLocation() { result = this.asSome().getLocation() }
81+
82+
/** Gets the wrapped element, if any. */
83+
ApplicationPropertiesConfigPair asSome() { this = TSome(result) }
84+
85+
/** Holds if this option is the singleton `None`. */
86+
predicate isNone() { this = TNone() }
87+
}
88+
6689
/**
6790
* Holds if `ApplicationProperties` ap of a repository managed by `SpringBootPom` pom
6891
* has a vulnerable configuration of Spring Boot Actuator management endpoints.
6992
*/
70-
predicate hasConfidentialEndPointExposed(SpringBootPom pom) {
93+
predicate hasConfidentialEndPointExposed(SpringBootPom pom, ApplicationPropertiesOption apOption) {
7194
pom.isSpringBootActuatorUsed() and
7295
not pom.isSpringBootSecurityUsed() and
7396
exists(ApplicationPropertiesFile apFile |
@@ -79,14 +102,18 @@ predicate hasConfidentialEndPointExposed(SpringBootPom pom) {
79102
springBootVersion = pom.getParentElement().getVersionString()
80103
|
81104
springBootVersion.regexpMatch("1\\.[0-4].*") and // version 1.0, 1.1, ..., 1.4
82-
not exists(ManagementSecurityConfig me | me.hasSecurityEnabled() and me.getFile() = apFile)
105+
not exists(ManagementSecurityConfig me | me.getFile() = apFile) and
106+
apOption.isNone()
83107
or
84-
springBootVersion.matches("1.5%") and // version 1.5
85-
exists(ManagementSecurityConfig me | me.hasSecurityDisabled() and me.getFile() = apFile)
108+
springBootVersion.regexpMatch("1\\.[0-5].*") and // version 1.0, 1.1, ..., 1.5
109+
exists(ManagementSecurityConfig me |
110+
me.hasSecurityDisabled() and me.getFile() = apFile and me = apOption.asSome()
111+
)
86112
or
87113
springBootVersion.matches("2.%") and //version 2.x
88114
exists(ManagementEndPointInclude mi |
89115
mi.getFile() = apFile and
116+
mi = apOption.asSome() and
90117
(
91118
mi.getValue() = "*" // all endpoints are enabled
92119
or

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

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

18-
from SpringBootPom pom, Dependency d
18+
from SpringBootPom pom, Dependency d, ApplicationPropertiesOption apOption
1919
where
20-
hasConfidentialEndPointExposed(pom) and
20+
hasConfidentialEndPointExposed(pom, apOption) and
2121
d = pom.getADependency() and
2222
d.getArtifact().getValue() = "spring-boot-starter-actuator"
23-
select d, "Insecure configuration of Spring Boot Actuator exposes sensitive endpoints."
23+
select d,
24+
"Insecure $@ of Spring Boot Actuator exposes sensitive endpoints (" +
25+
pom.getParentElement().getVersionString() + ").", apOption, "configuration"
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
| Version1.4-/bad/default/pom.xml:29:9:32:22 | dependency | Insecure configuration of Spring Boot Actuator exposes sensitive endpoints. |
2-
| Version1.4-/bad/false/pom.xml:29:9:32:22 | dependency | Insecure configuration of Spring Boot Actuator exposes sensitive endpoints. |
3-
| Version1.5/bad/pom.xml:29:9:32:22 | dependency | Insecure configuration of Spring Boot Actuator exposes sensitive endpoints. |
4-
| Version2+/bad/pom.xml:29:9:32:22 | dependency | Insecure configuration of Spring Boot Actuator exposes sensitive endpoints. |
1+
| Version1.4-/bad/default/pom.xml:29:9:32:22 | dependency | Insecure $@ of Spring Boot Actuator exposes sensitive endpoints (1.2.6.RELEASE). | file://:0:0:0:0 | (none) | configuration |
2+
| Version1.4-/bad/false/pom.xml:29:9:32:22 | dependency | Insecure $@ of Spring Boot Actuator exposes sensitive endpoints (1.2.6.RELEASE). | Version1.4-/bad/false/application.properties:2:1:2:33 | management.security.enabled=false | configuration |
3+
| Version1.5/bad/pom.xml:29:9:32:22 | dependency | Insecure $@ of Spring Boot Actuator exposes sensitive endpoints (1.5.6.RELEASE). | Version1.5/bad/application.properties:2:1:2:33 | management.security.enabled=false | configuration |
4+
| Version2+/bad/pom.xml:29:9:32:22 | dependency | Insecure $@ of Spring Boot Actuator exposes sensitive endpoints (2.2.6.RELEASE). | Version2+/bad/application.properties:2:1:2:43 | management.endpoints.web.exposure.include=* | configuration |

0 commit comments

Comments
 (0)