Skip to content

Config files no longer loaded if they contain a hidden path element #23983

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

Closed
mwftapi opened this issue Oct 31, 2020 · 4 comments
Closed

Config files no longer loaded if they contain a hidden path element #23983

mwftapi opened this issue Oct 31, 2020 · 4 comments
Assignees
Labels
type: regression A regression from a previous release
Milestone

Comments

@mwftapi
Copy link

mwftapi commented Oct 31, 2020

Since upgrading from Spring Boot Version 2.3.4 to Spring Boot Version 2.3.5 a application no longer loads properties from property files that are located in config locations that contain a hidden path element.

This can be reproduced by setting the spring.config.additional-location to a location that contains a hidden path element as shown in the following snippet:

@SpringBootApplication
public class Application extends SpringBootServletInitializer {

  private static final String ADDITIONAL_CONFIG_LOCATION = "/additional/config/.location/";

  public static void main(String[] args) {
    configureApplication(new SpringApplicationBuilder()).run(args);
  }

  @Override
  protected SpringApplicationBuilder configure(
    SpringApplicationBuilder builder) {
    return configureApplication(builder);
  }

  private static SpringApplicationBuilder configureApplication(SpringApplicationBuilder builder) {
    return builder.sources(Application.class).properties(
      Map.of("spring.config.additional-location", ADDITIONAL_CONFIG_LOCATION)
    );
  }
}

As seen in the example code snippet the additional config location given contains a hidden path element, namely .location.

If we put a file named application-some-active-profile.yml into /additional/config/.location/ this file will not be loaded by the org/springframework/boot/context/config/ConfigFileApplicationListener.java upon start up when running with -Dspring.profiles.active=some-active-profile.

This is because of the check in Line 525 of the ConfigFileApplicationListener.

This check will strip all path elements and check them for a starting .. Since the constructed resource path file:/application/config/.location/application-some-active-profile.yml contains the .location path element the resource will not be loaded.

This change was introduced with the following commit.

This issue is reproducible with all config file types: properties, xml, yaml, yml.

This issue is not reproducible with Spring Boot Version 2.3.4.

@spring-projects-issues spring-projects-issues added the status: waiting-for-triage An issue we've not yet triaged label Oct 31, 2020
@wilkinsona wilkinsona added type: bug A general bug type: regression A regression from a previous release and removed status: waiting-for-triage An issue we've not yet triaged type: bug A general bug labels Oct 31, 2020
@wilkinsona wilkinsona added this to the 2.3.6 milestone Oct 31, 2020
@wilkinsona
Copy link
Member

Sorry for the inconvenience, @mwftapi. Thank you for the detailed analysis of the problem.

@mwftapi
Copy link
Author

mwftapi commented Oct 31, 2020

Glad if I can help! Thank you for managing such an amazing framework! Keep up the good work! ❤️

@scottfrederick scottfrederick added the for: team-attention An issue we'd like other members of the team to review label Oct 31, 2020
@gbaso
Copy link

gbaso commented Nov 2, 2020

This also breaks applications packaged as war and deployed with Eclipse + Tomcat, since Eclipse uses the hidden folder <eclipse-workspace>/.metadata/.plugins/org.eclipse.wst.server.core/tmp0 as the default server path.

@scottfrederick scottfrederick self-assigned this Nov 2, 2020
@wilkinsona wilkinsona removed the for: team-attention An issue we'd like other members of the team to review label Nov 4, 2020
@scottfrederick scottfrederick changed the title Config Files No Longer Loaded From 'spring.config.additional-location' If They Contain A Hidden Path Element Config files no longer loaded if they contain a hidden path element Nov 4, 2020
@wilkinsona
Copy link
Member

From @bo0ts on #23160:

@wilkinsona We are using fully qualified paths to set our config locations, e.g. -Dspring.config.location=classpath:/,classpath:/config/,file:./,file:./config/,/config/config1/..2020_10_27_21_10_29.547134956/application.properties,/config/config2/..2020_10_27_21_10_30.275048764/secret.properties,/config/config3/..2020_10_27_21_10_29.797568129/application.properties. (We collect those files with find . -type f ...)

This change breaks loading our configs and #23983 does nothing to alleviate this. I don't think skipping explicitly defined absolute paths to config files is the intention.

I wonder if we can restrict ignoring .. prefixed path elements to the wildcard case?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type: regression A regression from a previous release
Projects
None yet
Development

No branches or pull requests

5 participants