-
Notifications
You must be signed in to change notification settings - Fork 651
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
Incorrect validation of baggage values #2934
Comments
@srikanthccv @ocelotl what do you think? |
This looks like a legitimate bug. I haven't gotten time to triage this. I will check. |
Checking... |
Ok, I think this is what's happening here: The definition for the baggage
That is why our regex
That regex does not allow space characters, the reported string has one in
I think that means we should first strip any leading and trailing whitespace characters from the The space character in What do you think, @srikanthccv? |
@ocelotl in the same spec you are citing you are missing the important part
|
We are running into a similar issue. FWIW, The OTEL client for NodeJS handles values with spaces so long as they are percent-encoded. |
I'm not sure
I think from opentelemetry.baggage.propagation import W3CBaggagePropagator
from opentelemetry.context import get_current
from opentelemetry.baggage import set_baggage
carrier = {}
w3c_baggage_propagator = W3CBaggagePropagator()
context = set_baggage(
"baggage",
"sentry-transaction=GET%20%2Fapi%2Freport",
context=get_current()
)
w3c_baggage_propagator.inject(carrier, context)
print(carrier)
context = w3c_baggage_propagator.extract(carrier)
print(context)
It is impossible for I don't think this is a bug, WDYT @srikanthccv? |
@ocelotl I see your point, you are saying that the spec is ambiguos because given that the baggage-octet range includes the '%' symbol and the language around when to encode string, then there's no way to distinguish whether Note however, that in Java, the value is always percent encoded, so the case above would not be ambiguous, as in the first case it would be encoded as In Java, it also seems there's no validation happening for the value, and the value is always being decoded. See https://cs.github.com/open-telemetry/opentelemetry-java/blob/0e41b1469d1fbc20c4fc5e7b59df0f4ac54330b6/api/all/src/main/java/io/opentelemetry/api/baggage/propagation/Parser.java#L128 and the function that calls it. Note though, that your example should be: from opentelemetry.baggage.propagation import W3CBaggagePropagator
from opentelemetry.context import get_current
from opentelemetry.baggage import set_baggage
carrier = {}
w3c_baggage_propagator = W3CBaggagePropagator()
context = set_baggage(
"sentry-transaction",
"GET /api/report",
context=get_current()
)
print(context)
w3c_baggage_propagator.inject(carrier, context)
print(carrier)
context = w3c_baggage_propagator.extract(carrier)
print(context) which unfortunately does not work, because you are restricting the values that can be used in the baggage, which is no correct. |
What I am saying is that for a baggage value to be parseable by from opentelemetry.baggage.propagation import W3CBaggagePropagator
W3CBaggagePropagator().extract({"baggage": "sentry-transaction=GET%20%2Fapi%2Freport"})
# Returns empty and raises warning Invalid baggage entry: `sentry-transaction=GET%20%2Fapi%2Freport` That string
Sorry, how are we restricting the values? 🤔 |
@ocelotl that value is percent encoded correctly, and corresponds to the value The problem with your example is that you are misunderstanding how percent encoding works. Please refer to the code used in the java package. As I mentioned originally, the problem is that the validation of the value is happening after decoding it. But, you should first validate the encoded value conforms to the character range and then decode its value. You are restricting the values, because the spec, which I have cited many times already, says
So you are allowed to have any string as a value, but the function Pleas also note that there are at least 2 other open-telemetry implementations that handle this. @srikanthccv could you please take a look |
Ah, ok, now I can understand what you mean, fixing... |
@ocelotl Would you like to assign this yourself? |
Related, decoding resource attributes from otlpresourcedetector: #3046 |
I did already. |
What is the status of this? Major issue for production release if we cant contain spaces |
There is a PR open pending reviews for this issue. Once that is merged, it should go into the next release. |
* Fix validation of baggage values Fixes #2934 * Remove test case
Describe your environment
python: 3.10.6
opentelemetry-api: 1.12.0
opentelemetry-sdk: 1.12.0
Steps to reproduce
What is the expected behavior?
Opentelemetry should be able to parse baggage values which are percent encoded, as that's indicated by the W3C spec
What is the actual behavior?
No baggage values were extracted and the following warning was raised:
Additional context
The problem is happening here:
opentelemetry-python/opentelemetry-api/src/opentelemetry/baggage/propagation/__init__.py
Line 92 in 75313b6
Note also that the indicated code path seems to be not be too optimized, as the call to
set_baggage
will validate both the key and values again. And additionally, for each baggage value a new context will be created. Maybe it'd be better to first collect all baggage values and set them only once in the context.The text was updated successfully, but these errors were encountered: