fix(java): resolve critical code review findings and hardening suggestions - #43
Merged
Conversation
…er wrapping, and request validation
…domain fail-fast normalization, CRLF key checks, close error wrapping, and builder exclusivity
…h switching, add JsonIgnoreProperties, and expose static builders
…ingleton recommendation, and log close warning
…entials in ClientConfig.equals(), and use System.Logger in close()
…downloads, fast header loops, and builder bounds checks
…+ on custom builders, validate RequestOptions eagerly, and cache apiHost
…ssify payload size limits under VALIDATION category
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.
Summary of Fixes
🔴 Critical Issues Addressed
ClientConfigThread-Safety & Immutability:ClientConfigfinal and converted all state fields toprivate final.setApiKey,setApiBaseUrl,setConnectTimeoutMs,setRequestTimeoutMs,setMaxResponseBytes,setAllowInsecureHttp,setHttpClient).ClientConfig.builder(),ClientConfig.builder(apiKey),ClientConfig.builder(apiKeySupplier), andtoBuilder()for thread-safe instantiation and copying.ClientConfig.toString().Resource Cleanup in
XyoClient.close():AutoCloseableinspection onHttpClientinXyoClient.close()to release selector threads, executors, and connection pools when running on Java 21+.API Key Supplier Exception Wrapping:
apiKeySupplier.get()in try-catch acrossXyoClientconstructor, request interceptors, and binary download routes, converting unchecked supplier errors intoXyoExceptionwithErrorCategory.VALIDATIONto prevent vault/secret credential leakage.EnrichmentRequest.validate()Consistency & ISO 3166-1 Alpha-2:contentbefore evaluating length limits (codePointCount <= 128).isAlpha2validation enforcing ISO 3166-1 alpha-2 format.content=[REDACTED]inEnrichmentRequest.toString().content.trim(),countryCode.trim().toUpperCase(Locale.ROOT)).🟡 Hardening Suggestions Addressed
validateApiUser(String apiUser).RequestOptions.@Nullableannotations from JSpecify toXyoException,ClientConfig, and DTO getters.XyoException(validation,http,transport,parsing,rateLimit).toString()implementations toEnrichmentResponseandEnrichTransactionCollectionResponse.allowInsecureHttpis enabled.