Browse Source

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
pull/13388/head
Phillip Webb 8 years ago
parent
commit
67b548dafb
  1. 1
      spring-boot-project/spring-boot/src/main/java/org/springframework/boot/context/config/ConfigFileApplicationListener.java
  2. 11
      spring-boot-project/spring-boot/src/test/java/org/springframework/boot/context/config/ConfigFileApplicationListenerTests.java
  3. 1
      spring-boot-project/spring-boot/src/test/resources/applicationloop-loop.properties
  4. 1
      spring-boot-project/spring-boot/src/test/resources/applicationloop.properties

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

@ -543,6 +543,7 @@ public class ConfigFileApplicationListener @@ -543,6 +543,7 @@ public class ConfigFileApplicationListener
LinkedList<Profile> existingProfiles = new LinkedList<>(this.profiles);
this.profiles.clear();
this.profiles.addAll(includeProfiles);
this.profiles.removeAll(this.processedProfiles);
this.profiles.addAll(existingProfiles);
}

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

@ -892,6 +892,17 @@ public class ConfigFileApplicationListenerTests { @@ -892,6 +892,17 @@ public class ConfigFileApplicationListenerTests {
assertThat(this.environment.getProperty("value")).isNull();
}
@Test
public void includeLoop() {
// gh-13361
SpringApplication application = new SpringApplication(Config.class);
application.setWebApplicationType(WebApplicationType.NONE);
this.context = application.run("--spring.config.name=applicationloop");
ConfigurableEnvironment environment = this.context.getEnvironment();
assertThat(environment.acceptsProfiles("loop")).isTrue();
}
private Condition<ConfigurableEnvironment> matchingPropertySource(
final String sourceName) {
return new Condition<ConfigurableEnvironment>(

1
spring-boot-project/spring-boot/src/test/resources/applicationloop-loop.properties

@ -0,0 +1 @@ @@ -0,0 +1 @@
spring.profiles.include=loop

1
spring-boot-project/spring-boot/src/test/resources/applicationloop.properties

@ -0,0 +1 @@ @@ -0,0 +1 @@
spring.profiles.include=loop
Loading…
Cancel
Save