Skip to content
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

key names vs. url-encoding #1409

Closed
Nirkus opened this issue Nov 12, 2015 · 2 comments
Closed

key names vs. url-encoding #1409

Nirkus opened this issue Nov 12, 2015 · 2 comments
Labels
theme/api Relating to the HTTP API interface type/bug Feature does not function as expected

Comments

@Nirkus
Copy link

Nirkus commented Nov 12, 2015

Hey,

I had the rather unusual idea to encode URL route configuration in the consul key-value store.
So, the mapping of key to value would be route to service name, something like:
"/v9/" => "other-backend"

As kv store key names are just URL path suffixes, I tried to URL-encode my slashes.

A key name of "%2Fv9%2F" seems to be URL-unescaped by consul and result in the key name "/v9/", which created a "directory" containing a single key using the uploaded value as its name.

While I can understand that "%2F" is un-escaped by consul before creating the key, using the uploaded value as the name of an empty key is somewhat strange.

A key name of "%252Fv9%252F" actually results in a key named "%2Fv9%2F" being created with the uploaded value as its value. Unfortunately, the API returns that key name without URL-escaping it first:

$ curl -s http://testhost.example.com:8500/v1/kv/service/someservice/routes/?recurse | json_pp
[
   {
      "Key" : "service/someservice/routes/%2Fv9%2F",
      "CreateIndex" : 297596,
      "Flags" : 0,
      "ModifyIndex" : 297596,
      "Value" : "dGVzdHZhbHVl",
      "LockIndex" : 0
   }
]

GETing the key returned above reults in a 301, since consul un-escapes "%2F" into "/" before looking up the key.

curl -i -s http://testhost.example.com:8500/v1/kv/service/someservice/routes/%2Fv9%2F 
HTTP/1.1 301 Moved Permanently
Location: /v1/kv/service/someservice/routes/v9/
Date: Thu, 12 Nov 2015 17:13:16 GMT
Content-Length: 76
Content-Type: text/html; charset=utf-8

<a href="/v1/kv/service/someservice/routes/v9/">Moved Permanently</a>.

The key redirected to does not exist:

$ curl -i -s http://testhost.example.com:8500/v1/kv/service/someservice/routes/v9/
HTTP/1.1 404 Not Found
X-Consul-Index: 297596
X-Consul-Knownleader: true
X-Consul-Lastcontact: 0
Date: Thu, 12 Nov 2015 17:15:25 GMT
Content-Length: 0
Content-Type: text/plain; charset=utf-8

Requesting that key using "service/someservice/routes/%252Fv9%252F" actually works.

$ curl -s http://testhost.example.com:8500/v1/kv/service/someservice/routes/%252Fv9%252F | json_pp 
[
   {
      "Value" : "dGVzdHZhbHVl",
      "ModifyIndex" : 297596,
      "LockIndex" : 0,
      "Flags" : 0,
      "Key" : "service/someservice/routes/%2Fv9%2F",
      "CreateIndex" : 297596
   }
]

So, I guess, key components should be URL-escaped before returning them in the API.

@highlyunavailable
Copy link
Contributor

Historically there have been a bunch of slash problems with the KV store, mostly by people trying to use RabbitMQ: #1277 #889

#889 (comment) is the best explanation of the problem.

@slackpad slackpad added the thinking More time is needed to research by the Consul Contributors label Jan 8, 2016
@slackpad slackpad added type/bug Feature does not function as expected and removed thinking More time is needed to research by the Consul Contributors labels May 5, 2017
@slackpad slackpad added the theme/api Relating to the HTTP API interface label May 25, 2017
@hanshasselberg
Copy link
Member

This is now working as described in here: #1277 (comment).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
theme/api Relating to the HTTP API interface type/bug Feature does not function as expected
Projects
None yet
Development

No branches or pull requests

4 participants