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

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

Closed
jimshowalter opened this issue Feb 26, 2021 · 15 comments · Fixed by #6431
Labels
blocked:spec blocked on open or unresolved spec Bug Something isn't working good first issue help wanted

Comments

@jimshowalter
Copy link

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 jimshowalter added the Bug Something isn't working label Feb 26, 2021
@akhatami
Copy link

@jimshowalter @jkwatson

May I start working on this?

@bogdandrutu
Copy link
Member

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

@jkwatson
Copy link
Contributor

@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?

@jimshowalter
Copy link
Author

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.

@bogdandrutu
Copy link
Member

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

@jimshowalter
Copy link
Author

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.

@jkwatson
Copy link
Contributor

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

@andresbeckruiz
Copy link

andresbeckruiz commented Jun 18, 2021

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

@jkwatson
Copy link
Contributor

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 jkwatson added the blocked:spec blocked on open or unresolved spec label Jun 18, 2021
@aniketrb-github
Copy link

any updates on the spec. ?

@akhatami akhatami removed their assignment Oct 3, 2022
@MounikaNandyala
Copy link

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();
}

@hakunamatata-git
Copy link

Is it still open?

@jkwatson
Copy link
Contributor

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

@AdamBalski
Copy link

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.

tkmsaaaam added a commit to tkmsaaaam/opentelemetry-java that referenced this issue May 4, 2024
@tkmsaaaam
Copy link
Contributor

I created this PR. #6431 Please review it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
blocked:spec blocked on open or unresolved spec Bug Something isn't working good first issue help wanted
Projects
None yet
Development

Successfully merging a pull request may close this issue.

10 participants