Closed c1784497 closed 7 years ago
Thank you for reporting!
@c1784497 when you say Add meta data key:value pair
, exactly what do you mean? How did you add it?
Could you share your API definition?
Please note that there are two issues here - I'm not convinced that the regex error and the interface panic are directly related.
In any case, I've found the cause of the panic.
The good news is that this is fixed in master, in a way. In stable, MetaData
is a map[string]interface{}
, but in master it's a map[string]string
.
@c1784497 I assume you put in there something like "meta_data": {"contact": 0}
. Is that correct?
That would explain why it was float64
instead of string
- that's what encoding/json
decodes a number to interface{}
as.
@buger this leads to a question - should we support just strings, or any type? In other words, should we support "contact": 0
too, or just "contact": "0"
?
In favor of doing it is that nothing other than a string ever worked. So we do know for a fact that noone relies on it.
Another thing in favor of it is that these are used in strings, like headers. Not all JSON types can be stringified easily. What about objects? Not even numbers are safe - if they're floating point, which all JSON numbers are, the string might be different (e.g. missing zeros, rounding, etc).
One point against only supporting strings is that the docs seem to say otherwise: This field is a string key/value map that can store any kind of information about the underlying identity of a session
https://tyk.io/docs/concepts/session-meta-data/
When I read that, any kind of information
says any type to me. We should clarify that values can only be strings, if we want to enforce this.
I forgot to add - I clearly think we should only support strings here. It makes the JSON config easier, it makes the docs simpler and it makes the code less tricky. And I see no reason to support other types like numbers and objects.
As to the regex error, this is a regex compiled directly from your API definition. So I can't help you further unless you provide your entire API definition. But it seems like the issue is there, unless there's a bug in the code that I'm missing.
Friendly ping @c1784497 - could you confirm what meta_data
JSON object were you using?
And also see my comment above about the regex error, which I believe is unrelated and due to an issue in your API definition.
In my view, if we can not restrict user on value types, this will be the best option.
In theory, it can be fixed with smth like fmt.Sprintf("%v", tempVal)
instead of direct type conversion.
After some discussion, we've agreed to just make the code work as the docs describe - at least, for 2.3.8. The docs say string key/value map, so only strings are allowed.
In other words, use "0"
instead of 0
.
These values are only to be used in headers, and headers are strings, so any other type makes little sense.
I'll submit a patch for 2.3.8 to avoid the panic, though.
Merged.
Do you want to request a feature or report a bug? bug What is the current behavior?
What is the expected behavior? No error. If the current behavior is a bug, please provide the steps to reproduce and if possible a minimal demo of the problem Add meta data key:value pair:
contact:0
Add header:value pair:X-Contact: $tyk_meta.contact
Which versions of Tyk affected by this issue? Did this work in previous versions of Tyk? 2.3.5 / 1.3.5Problem does not exist with value 1 instead of 0.