Skip to content

Commit 8dd8c17

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

File tree

3 files changed

+61
-10
lines changed

3 files changed

+61
-10
lines changed

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

Lines changed: 39 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -63,11 +63,37 @@ class ManagementEndPointInclude extends ApplicationPropertiesConfigPair {
6363
string getValue() { result = this.getValueElement().getValue().trim() }
6464
}
6565

66+
private newtype TOption =
67+
TNone() or
68+
TSome(ApplicationPropertiesConfigPair ap)
69+
70+
/**
71+
* An option type that is either a singleton `None` or a `Some` wrapping
72+
* the `ApplicationPropertiesConfigPair` type.
73+
*/
74+
class ApplicationPropertiesOption extends TOption {
75+
/** Gets a textual representation of this element. */
76+
string toString() {
77+
this = TNone() and result = "(none)"
78+
or
79+
result = this.asSome().toString()
80+
}
81+
82+
/** Gets the location of this element. */
83+
Location getLocation() { result = this.asSome().getLocation() }
84+
85+
/** Gets the wrapped element, if any. */
86+
ApplicationPropertiesConfigPair asSome() { this = TSome(result) }
87+
88+
/** Holds if this option is the singleton `None`. */
89+
predicate isNone() { this = TNone() }
90+
}
91+
6692
/**
6793
* Holds if `ApplicationProperties` ap of a repository managed by `SpringBootPom` pom
6894
* has a vulnerable configuration of Spring Boot Actuator management endpoints.
6995
*/
70-
predicate hasConfidentialEndPointExposed(SpringBootPom pom) {
96+
predicate hasConfidentialEndPointExposed(SpringBootPom pom, ApplicationPropertiesOption apOption) {
7197
pom.isSpringBootActuatorUsed() and
7298
not pom.isSpringBootSecurityUsed() and
7399
exists(ApplicationPropertiesFile apFile |
@@ -79,14 +105,24 @@ predicate hasConfidentialEndPointExposed(SpringBootPom pom) {
79105
springBootVersion = pom.getParentElement().getVersionString()
80106
|
81107
springBootVersion.regexpMatch("1\\.[0-4].*") and // version 1.0, 1.1, ..., 1.4
82-
not exists(ManagementSecurityConfig me | me.hasSecurityEnabled() and me.getFile() = apFile)
108+
(
109+
not exists(ManagementSecurityConfig me | me.getFile() = apFile) and
110+
apOption.isNone()
111+
or
112+
exists(ManagementSecurityConfig me |
113+
me.hasSecurityDisabled() and me.getFile() = apFile and me = apOption.asSome()
114+
)
115+
)
83116
or
84117
springBootVersion.matches("1.5%") and // version 1.5
85-
exists(ManagementSecurityConfig me | me.hasSecurityDisabled() and me.getFile() = apFile)
118+
exists(ManagementSecurityConfig me |
119+
me.hasSecurityDisabled() and me.getFile() = apFile and me = apOption.asSome()
120+
)
86121
or
87122
springBootVersion.matches("2.%") and //version 2.x
88123
exists(ManagementEndPointInclude mi |
89124
mi.getFile() = apFile and
125+
mi = apOption.asSome() and
90126
(
91127
mi.getValue() = "*" // all endpoints are enabled
92128
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,17 @@
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 configuration 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 |
2+
| Version1.4-/bad/default/pom.xml:29:9:32:22 | dependency | Insecure configuration of Spring Boot Actuator exposes sensitive endpoints. (1.2.6.RELEASE) | Version1.4-/good/application.properties:2:1:2:32 | management.security.enabled=true | configuration |
3+
| Version1.4-/bad/default/pom.xml:29:9:32:22 | dependency | Insecure configuration of Spring Boot Actuator exposes sensitive endpoints. (1.2.6.RELEASE) | Version1.5/bad/application.properties:2:1:2:33 | management.security.enabled=false | configuration |
4+
| Version1.4-/bad/default/pom.xml:29:9:32:22 | dependency | Insecure configuration of Spring Boot Actuator exposes sensitive endpoints. (1.2.6.RELEASE) | Version1.5/good/application.properties:2:1:2:32 | management.security.enabled=true | configuration |
5+
| Version1.4-/bad/default/pom.xml:29:9:32:22 | dependency | Insecure configuration of Spring Boot Actuator exposes sensitive endpoints. (1.2.6.RELEASE) | Version2+/application.properties:6:1:6:33 | management.security.enabled=false | configuration |
6+
| Version1.4-/bad/default/pom.xml:29:9:32:22 | dependency | Insecure configuration of Spring Boot Actuator exposes sensitive endpoints. (1.2.6.RELEASE) | Version2+/application.properties:9:1:9:43 | management.endpoints.web.exposure.include=* | configuration |
7+
| Version1.4-/bad/default/pom.xml:29:9:32:22 | dependency | Insecure configuration of Spring Boot Actuator exposes sensitive endpoints. (1.2.6.RELEASE) | Version2+/application.properties:10:1:10:47 | management.endpoints.web.exposure.exclude=beans | configuration |
8+
| Version1.4-/bad/default/pom.xml:29:9:32:22 | dependency | Insecure configuration of Spring Boot Actuator exposes sensitive endpoints. (1.2.6.RELEASE) | Version2+/application.properties:12:1:12:41 | management.endpoint.shutdown.enabled=true | configuration |
9+
| Version1.4-/bad/default/pom.xml:29:9:32:22 | dependency | Insecure configuration of Spring Boot Actuator exposes sensitive endpoints. (1.2.6.RELEASE) | Version2+/application.properties:14:1:14:55 | management.endpoint.health.show-details=when_authorized | configuration |
10+
| Version1.4-/bad/default/pom.xml:29:9:32:22 | dependency | Insecure configuration of Spring Boot Actuator exposes sensitive endpoints. (1.2.6.RELEASE) | Version2+/bad/application.properties:2:1:2:43 | management.endpoints.web.exposure.include=* | configuration |
11+
| Version1.4-/bad/default/pom.xml:29:9:32:22 | dependency | Insecure configuration of Spring Boot Actuator exposes sensitive endpoints. (1.2.6.RELEASE) | Version2+/bad/application.properties:3:1:3:47 | management.endpoints.web.exposure.exclude=beans | configuration |
12+
| Version1.4-/bad/default/pom.xml:29:9:32:22 | dependency | Insecure configuration of Spring Boot Actuator exposes sensitive endpoints. (1.2.6.RELEASE) | Version2+/bad/application.properties:5:1:5:41 | management.endpoint.shutdown.enabled=true | configuration |
13+
| Version1.4-/bad/default/pom.xml:29:9:32:22 | dependency | Insecure configuration of Spring Boot Actuator exposes sensitive endpoints. (1.2.6.RELEASE) | Version2+/bad/application.properties:7:1:7:55 | management.endpoint.health.show-details=when_authorized | configuration |
14+
| Version1.4-/bad/default/pom.xml:29:9:32:22 | dependency | Insecure configuration of Spring Boot Actuator exposes sensitive endpoints. (1.2.6.RELEASE) | Version2+/good/application.properties:2:1:2:59 | management.endpoints.web.exposure.include=beans,info,health | configuration |
15+
| 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 |
16+
| 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 |
17+
| 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)