opentelemetry-java icon indicating copy to clipboard operation
opentelemetry-java copied to clipboard

ImmutableBaggage.isKeyValid allows non-zero-length strings that contain nothing but spaces and/or tabs

Open jimshowalter opened this issue 4 years ago • 15 comments

It currently is:

private static boolean isKeyValid(String name) { return name != null && !name.isEmpty() && StringUtils.isPrintableString(name); }

It needs to be: private static boolean isKeyValid(String name) { return name != null && !name.trim().isEmpty() && StringUtils.isPrintableString(name); }

Or it needs to use something like apache StringUtils isBlank.

jimshowalter avatar Feb 26 '21 18:02 jimshowalter

@jimshowalter @jkwatson

May I start working on this?

akhatami avatar Feb 26 '21 22:02 akhatami

@jkwatson I think this should be clarified in the specification because we want to have a consistent behavior across libraries

bogdandrutu avatar Feb 27 '21 00:02 bogdandrutu

@jkwatson I think this should be clarified in the specification because we want to have a consistent behavior across libraries

Isn't key validity defined by the w3c spec already?

jkwatson avatar Feb 27 '21 04:02 jkwatson

https://www.w3.org/TR/baggage/#key

"Leading and trailing whitespaces (OWS) are allowed but MUST be trimmed when converting the header into a data structure."

If you trim leading and trailing whitespace on a string consisting of nothing but whitespace, you get an empty string.

So !name.trim().isEmpty() is correct, and the current code is not correct.

jimshowalter avatar Feb 27 '21 16:02 jimshowalter

If we apply the w3c rules then we need to trim the keys always, for example " too" should overwrite "too". I want to clarify in the specs that we follow w3c rules which I think we don't say at the moment

bogdandrutu avatar Feb 28 '21 16:02 bogdandrutu

The proposed change in my first post in this bug report was to change !name.isEmpty() to !name.trim().isEmpty(), which always trims the keys.

jimshowalter avatar Feb 28 '21 18:02 jimshowalter

@bogdandrutu Can you shepherd a tweak to the specs so we can get #2950 merged?

jkwatson avatar Mar 10 '21 18:03 jkwatson

Has this issue been resolved? If not I would like to take a stab at it.

andresbeckruiz avatar Jun 18 '21 19:06 andresbeckruiz

Has this issue been resolved? If not I would like to take a stab at it.

cc: @alolita

I think we're still waiting on the specification issue to get resolved.

jkwatson avatar Jun 18 '21 20:06 jkwatson

any updates on the spec. ?

aniketrb-github avatar Sep 30 '22 19:09 aniketrb-github

Is it still open? If yes, we can try this way.

private static boolean isKeyValid(String name) { // Trim leading and trailing whitespace name = name.trim();

// Check if the name is valid (non-empty after trimming) return !name.isEmpty(); }

MounikaNandyala avatar Aug 03 '23 23:08 MounikaNandyala

Is it still open?

hakunamatata-git avatar Oct 10 '23 00:10 hakunamatata-git

Someone will need to validate what the specification currently says about baggage keys and create a PR if we're not currently in compliance.

jkwatson avatar Oct 10 '23 15:10 jkwatson

As per this excerpt, the specification does not say anything about requirements for a key except for it being a string.

REQUIRED parameters:

Name The name for which to set the value, of type string.

AdamBalski avatar Nov 14 '23 15:11 AdamBalski

I created this PR. #6431 Please review it.

tkmsaaaam avatar May 04 '24 05:05 tkmsaaaam