Skip to content

Config server resolves placeholders incorrectly for JSON and YAML endpoints #480

Closed

Description

@rlynch

I am seeing problems with the resolvePlaceholder functionality in Spring Cloud Config Server. A set of examples is best. First here is an example yml file I have in my git repo....

jsk:
  servlet:
    healthcheck:
      dirToWatch: '${catalina.home:.}/conf/_health'

When I call the server using the path used by the Spring Client the correct results are returned with the ${catalina.home:.} placeholder not being resolved.

http://localhost:8888/sp_boot_sample/foo/ryan_test

{
  "name": "sp_boot_sample",
  "profiles": [
    "foo"
  ],
  "label": "ryan_test",
  "version": "ed19d558ff52e08aeb72a517e46685a344389fd1",
  "propertySources": [
    {
      "name": "https://github.intuit.com/java-service-kit/sp-boot-sample-config/application.yml",
      "source": {
        "jsk.servlet.healthcheck.dirToWatch": "${catalina.home:.}/conf/_health"
      }
    }
  ]
}

It also behaives correctly when I request the configuration as properties with the resolvePlaceholder=false
http://localhost:8888/ryan_test/sp_boot_sample-foo.properties?resolvePlaceholders=false

jsk.servlet.healthcheck.dirToWatch: ${catalina.home:.}/conf/_health

YML and JSON is where we have problems since it is trying to replace the placeholder.

http://localhost:8888/ryan_test/sp_boot_sample-foo.json?resolvePlaceholders=false

{
  "jsk": {
    "servlet": {
      "healthcheck": {
        "dirToWatch": "./conf/_health"
      }
    }
  }
}

http://localhost:8888/ryan_test/sp_boot_sample-foo.yml?resolvePlaceholders=false

jsk:
  servlet:
    healthcheck:
      dirToWatch: ./conf/_health

The issue gets more problematic when you remove the resolvePlaceholders as the behavior becomes inconsistent.
YML
http://localhost:8888/ryan_test/sp_boot_sample-foo.yml

jsk:
  servlet:
    healthcheck:
      dirToWatch: ./conf/_health

JSON
http://localhost:8888/ryan_test/sp_boot_sample-foo.json

{
  "jsk": {
    "servlet": {
      "healthcheck": {
        "dirToWatch": "./conf/_health"
      }
    }
  }
}

Properties
http://localhost:8888/ryan_test/sp_boot_sample-foo.properties

jsk.servlet.healthcheck.dirToWatch: /private/var/folders/5g/0hmbzds942318msw3jxvvbp0nw22jg/T/tomcat.1297932675264632683.8888/conf/_health

To be honest I am not sure which one is correct. If the properties version is the correct one then it exposes a dangerous security vulnerability since any client could start examining the server's environment variables.

Activity

  1. changed the title [-]resolvePlaceholder functionality incorrect and inconsistent depending on format[/-] [+]resolvePlaceholder functionality incorrect and inconsistent when serving alternative formats[/+] on Aug 19, 2016
  2. ryanjbaxter commented on Aug 19, 2016

    @ryanjbaxter
    Contributor

    I THINK this is a bug, I am able to reproduce the problem, but i am unfamiliar with the code. I also dont see any tests that test this specific scenario. I will check with the team next week and provide more info.

  3. rlynch commented on Aug 19, 2016

    @rlynch
    ContributorAuthor

    Looking at the code this seems to be centralized to the EnvironmentController class. For the labelledProperties() method return there is a convertToProperties function which simply converts the environment to a map of properties but does not alter the value of the properties. For json and yml (labeledYaml() and labeledJson()) there is a convertToMap function which along with converting the structure of the environment to a nested map it also alters the property values....

            PropertiesConfigurationFactory<Map<String, Object>> factory = new PropertiesConfigurationFactory<>(
            //.... some structuring code....
            factory.setPropertySources(propertySources);
            factory.bindPropertiesToTarget();
            //... other stuff....
    

    Its during the bindPropertiesToTarget that the placeholder resolution occurs regardless of if the resolvePlaceholders value is true or false. Because the convertToMap function alters the value of the properties and the convertToProperties function does not you get the inconsistant behavior. What I haven't determined is if there is a valid reason the convertToMap tries to alter the property values for a use case I am not thinking of.

    I was going to look into this myself but I am having trouble running the unit tests as I am getting weird errors from Mockito.

  4. rlynch commented on Aug 19, 2016

    @rlynch
    ContributorAuthor

    One last comment. It concerns me that we don't have the ability to completely eliminate place holder resolution on the server side. As it stands right now a malicious hacker could probe the server and potentially use it to retrieve any environment property set on the config server regardless of its relevance for outside configurations. This seems like a huge security vulnerability.

  5. ryanjbaxter commented on Aug 19, 2016

    @ryanjbaxter
    Contributor

    That is my analysis as well, hopefully I will have more information for you soon.

  6. dsyer commented on Aug 22, 2016

    @dsyer
    Contributor

    I think "huge security vulnerability" is a bit of an exaggeration (the config server should be secure in any reasonable environment, so only its authenticated clients can probe it, and only the ones that can write to its backend), but we can certainly correct this because it is not the intended behaviour. See f8fc4e1.

  7. added this to the 1.2.0.M1 milestone on Aug 22, 2016
  8. changed the title [-]resolvePlaceholder functionality incorrect and inconsistent when serving alternative formats[/-] [+]Config server resolves placeholders incorrectly for JSON and YAML endpoints[/+] on Aug 22, 2016
  9. added 4 commits that reference this issue on Sep 6, 2016
    68d3190
    b1a6021
    713d87f
    06b08bd
  10. added a commit that references this issue on Sep 20, 2016
    53e049a
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions

      ⌂ 换网址