Skip to content

Commit 67b548d

Browse files
committed
Protect against infinite property include loop
Update `ConfigFileApplicationListener` to ensure that a `spring.profiles.include` property that refers to an already processed profile doesn't cause an infinite loop. Closes gh-13361
1 parent 378c4c9 commit 67b548d

File tree

4 files changed

+14
-0
lines changed

4 files changed

+14
-0
lines changed

spring-boot-project/spring-boot/src/main/java/org/springframework/boot/context/config/ConfigFileApplicationListener.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -543,6 +543,7 @@ private void addIncludedProfiles(Set<Profile> includeProfiles) {
543543
LinkedList<Profile> existingProfiles = new LinkedList<>(this.profiles);
544544
this.profiles.clear();
545545
this.profiles.addAll(includeProfiles);
546+
this.profiles.removeAll(this.processedProfiles);
546547
this.profiles.addAll(existingProfiles);
547548
}
548549

spring-boot-project/spring-boot/src/test/java/org/springframework/boot/context/config/ConfigFileApplicationListenerTests.java

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -892,6 +892,17 @@ public void locationReplaceDefaultLocation() {
892892
assertThat(this.environment.getProperty("value")).isNull();
893893
}
894894

895+
@Test
896+
public void includeLoop() {
897+
// gh-13361
898+
SpringApplication application = new SpringApplication(Config.class);
899+
application.setWebApplicationType(WebApplicationType.NONE);
900+
this.context = application.run("--spring.config.name=applicationloop");
901+
ConfigurableEnvironment environment = this.context.getEnvironment();
902+
assertThat(environment.acceptsProfiles("loop")).isTrue();
903+
904+
}
905+
895906
private Condition<ConfigurableEnvironment> matchingPropertySource(
896907
final String sourceName) {
897908
return new Condition<ConfigurableEnvironment>(
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
spring.profiles.include=loop
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
spring.profiles.include=loop

0 commit comments

Comments
 (0)