-
Notifications
You must be signed in to change notification settings - Fork 37
fix: validate endpointOverride URI scheme (#626) #1758
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
base: master
Are you sure you want to change the base?
Conversation
|
About the edge case discussion in #626
All real-world cases I could find use http:// or https://. Makes sense since AWS SDK communicates over HTTP(S). |
Add httpUri config descriptor that validates the URI scheme is http or https. This prevents runtime NullPointerExceptions when invalid URIs (e.g., 'minio:9000' without scheme) are passed to AWS SDK. Changes: - Add httpUri descriptor with scheme validation in descriptors/package.scala - Update commonAwsConfig to use httpUri for endpointOverride - Add tests for valid (http/https) and invalid (missing scheme) endpoints Fixes zio#626 Co-Authored-By: Claude Opus 4.5 <[email protected]>
8404bce to
40c9dbb
Compare
| val httpUri: Config[URI] = Config.uri.mapAttempt { uri => | ||
| val scheme = uri.getScheme | ||
| if (scheme == null || (!scheme.equalsIgnoreCase("http") && !scheme.equalsIgnoreCase("https"))) { | ||
| throw new IllegalArgumentException( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What's the type signature of mapAttempt. please?
I'm pretty sure it take a function URI => Either[String, A] and I'm pretty sure you're not supposed to throw
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the quick review! You're right — I've updated it to use mapOrFail with explicit Either instead.
Address review feedback - use explicit Either return instead of throwing
guizmaii
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM! Thanks @darkenpeng :)
Summary
Add
httpUriconfig descriptor that validates the URI scheme ishttporhttps. This prevents runtimeNullPointerExceptionwhen invalid URIs (e.g.,minio:9000without scheme) are passed to AWS SDK.Problem
When configuring
endpointOverridewith an invalid URI likeminio:9000(missing scheme), the config parsing succeeds but AWS SDK throws NPE at runtime.Solution
httpUridescriptor that validates scheme ishttporhttpsChanges
descriptors/package.scala: AddhttpUridescriptor with scheme validationCommonAwsConfigSpec.scala: Add tests for valid/invalid endpointsFixes #626