Pulsar auth parameters don't properly encode JSON values#40493
Closed
onobc wants to merge 1 commit intospring-projects:mainfrom
Closed
Pulsar auth parameters don't properly encode JSON values#40493onobc wants to merge 1 commit intospring-projects:mainfrom
onobc wants to merge 1 commit intospring-projects:mainfrom
Conversation
The values in the `spring.pulsar.client.authentication.param` config props map are not currently JSON encoded. For simple values this is fine. However, some custom auth modules may require more complex parameter values that may contain special characters that results in invalid JSON. This commmit encodes the parameter values using a very simple hand-rolled escape function. Fixes spring-projects#40492
onobc
commented
Apr 23, 2024
| } | ||
| } | ||
|
|
||
| private String escapeJson(String raw) { |
Contributor
Author
There was a problem hiding this comment.
Because we do not directly bring in a JSON library (e.g. Gson or Jackson) we can not use the simple facilities that these libs have to "encode a JSON string".
Here were the options:
Use JSON lib
Add required dependency on Jackson or Gson and use their built-in methods
- ✅ solid encode impl maintained by JSON lib
- ❌ ❌ ❌ have to bring in direct dep on JSON lib and this forces it upon our users (not an option)
Add feature to Spring Boot JsonParser
Add "encode a JSON string" to our JsonParser abstraction
- ✅ can be used in other areas of Spring Boot codebase
- ❌ created and maintained by us (more work)
- ❌ impl no more solid than if it were a private impl inside the mapper
- ❌ nowhere else in the Boot codebase needs this AFAIK
Hand-roll basic encoder
Inline a simple encode JSON facility in the mapper.
- ❌ basic impl maintained by us
- ❌ ✅ not a perfect solution but will solve the majority of the cases
- ✅ ✅ no direct dep on JSON lib
- ✅ private impl localized to the mapper
onobc
commented
Apr 23, 2024
| PulsarProperties properties = new PulsarProperties(); | ||
| Map<String, String> params = Map.of("param", "name"); | ||
| String authParamString = "{\"param\":\"name\"}"; | ||
| Map<String, String> params = Map.of("simpleParam", "foo", "complexParam", |
Contributor
Author
There was a problem hiding this comment.
We are not exhausting all possible replacements characters but are covering the majority.
@philwebb should we add a bit more coverage here?
Contributor
There was a problem hiding this comment.
I'm not Phil, but I think this is fine :)
mhalbritter
pushed a commit
that referenced
this pull request
May 22, 2024
The values in the `spring.pulsar.client.authentication.param` config props map are not currently JSON encoded. For simple values this is fine. However, some custom auth modules may require more complex parameter values that may contain special characters that results in invalid JSON. This commmit encodes the parameter values using a very simple hand-rolled escape function. See gh-40493
Contributor
|
Thanks Chris! |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
The values in the
spring.pulsar.client.authentication.paramconfig props map are not currently JSON encoded. For simple values this is fine. However, some custom auth modules may require more complex parameter values that may contain special characters that results in invalid JSON. This commmit encodes the parameter values using a very simple hand-rolled escape function.Fixes #40492