-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Java: Promote Insecure Spring Boot Actuator Configuration query from experimental #20006
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
jcogs33
wants to merge
21
commits into
github:main
Choose a base branch
from
jcogs33:jcogs33/java/insecure-spring-actuator-config-promotion
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 1 commit
Commits
Show all changes
21 commits
Select commit
Hold shift + click to select a range
a39cb40
Java: copy out of experimental
0dbddbd
Java: remove experimental files
38260e7
Java: remove deprecation
fc930d9
Java: update tests for non-experimental directory
ed8da5e
Java: convert tests to inline expectations
b479f5c
Java: fix integration tests
1b90a30
Java: move code to .qll file
3823186
Java: split tests by versions
2bfc4b4
Java: fix test case for version 1.4
ae163a9
Java: add overlay annotations
0d2a422
Java: add related location to alert message
afa6610
Java: update qhelp
ea35fbb
Java: support version 3.x
7d5e939
Java: minor refactoring
ea529b0
Java: adjust metadata and alert msg
70d5150
Java: rename to align with 'java/spring-boot-exposed-actuators' query
8decc13
Java: add change note
685f68d
Java: support 'management.endpoints.web.expose' property
7250265
Java: consider all endpoints except for health and info as sensitive …
0dd33b2
Java: remove version debugging from alert message
c9692a6
Java: fix test failures cause by alert msg change
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Java: move code to .qll file
- Loading branch information
There are no files selected for viewing
93 changes: 93 additions & 0 deletions
93
java/ql/lib/semmle/code/java/security/SpringBootActuatorsConfigQuery.qll
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,93 @@ | ||
/** Provides classes and predicates to reason about Spring Boot actuators exposed in configuration files. */ | ||
|
||
import java | ||
private import semmle.code.configfiles.ConfigFiles | ||
private import semmle.code.xml.MavenPom | ||
|
||
/** The parent node of the `org.springframework.boot` group. */ | ||
class SpringBootParent extends Parent { | ||
SpringBootParent() { this.getGroup().getValue() = "org.springframework.boot" } | ||
} | ||
|
||
/** Class of Spring Boot dependencies. */ | ||
class SpringBootPom extends Pom { | ||
SpringBootPom() { this.getParentElement() instanceof SpringBootParent } | ||
|
||
/** Holds if the Spring Boot Actuator module `spring-boot-starter-actuator` is used in the project. */ | ||
predicate isSpringBootActuatorUsed() { | ||
this.getADependency().getArtifact().getValue() = "spring-boot-starter-actuator" | ||
} | ||
|
||
/** | ||
* Holds if the Spring Boot Security module is used in the project, which brings in other security | ||
* related libraries. | ||
*/ | ||
predicate isSpringBootSecurityUsed() { | ||
this.getADependency().getArtifact().getValue() = "spring-boot-starter-security" | ||
} | ||
} | ||
|
||
/** The properties file `application.properties`. */ | ||
class ApplicationProperties extends ConfigPair { | ||
ApplicationProperties() { this.getFile().getBaseName() = "application.properties" } | ||
} | ||
|
||
/** The configuration property `management.security.enabled`. */ | ||
class ManagementSecurityConfig extends ApplicationProperties { | ||
ManagementSecurityConfig() { this.getNameElement().getName() = "management.security.enabled" } | ||
|
||
/** Gets the whitespace-trimmed value of this property. */ | ||
string getValue() { result = this.getValueElement().getValue().trim() } | ||
|
||
/** Holds if `management.security.enabled` is set to `false`. */ | ||
predicate hasSecurityDisabled() { this.getValue() = "false" } | ||
|
||
/** Holds if `management.security.enabled` is set to `true`. */ | ||
predicate hasSecurityEnabled() { this.getValue() = "true" } | ||
} | ||
|
||
/** The configuration property `management.endpoints.web.exposure.include`. */ | ||
class ManagementEndPointInclude extends ApplicationProperties { | ||
ManagementEndPointInclude() { | ||
this.getNameElement().getName() = "management.endpoints.web.exposure.include" | ||
} | ||
|
||
/** Gets the whitespace-trimmed value of this property. */ | ||
string getValue() { result = this.getValueElement().getValue().trim() } | ||
} | ||
|
||
/** | ||
* Holds if `ApplicationProperties` ap of a repository managed by `SpringBootPom` pom | ||
* has a vulnerable configuration of Spring Boot Actuator management endpoints. | ||
*/ | ||
predicate hasConfidentialEndPointExposed(SpringBootPom pom, ApplicationProperties ap) { | ||
pom.isSpringBootActuatorUsed() and | ||
not pom.isSpringBootSecurityUsed() and | ||
ap.getFile() | ||
.getParentContainer() | ||
.getAbsolutePath() | ||
.matches(pom.getFile().getParentContainer().getAbsolutePath() + "%") and // in the same sub-directory | ||
exists(string springBootVersion | springBootVersion = pom.getParentElement().getVersionString() | | ||
springBootVersion.regexpMatch("1\\.[0-4].*") and // version 1.0, 1.1, ..., 1.4 | ||
not exists(ManagementSecurityConfig me | | ||
me.hasSecurityEnabled() and me.getFile() = ap.getFile() | ||
) | ||
or | ||
springBootVersion.matches("1.5%") and // version 1.5 | ||
exists(ManagementSecurityConfig me | me.hasSecurityDisabled() and me.getFile() = ap.getFile()) | ||
or | ||
springBootVersion.matches("2.%") and //version 2.x | ||
exists(ManagementEndPointInclude mi | | ||
mi.getFile() = ap.getFile() and | ||
( | ||
mi.getValue() = "*" // all endpoints are enabled | ||
or | ||
mi.getValue() | ||
.matches([ | ||
"%dump%", "%trace%", "%logfile%", "%shutdown%", "%startup%", "%mappings%", "%env%", | ||
"%beans%", "%sessions%" | ||
]) // confidential endpoints to check although all endpoints apart from '/health' and '/info' are considered sensitive by Spring | ||
) | ||
) | ||
) | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.