Skip to content

fix(java): resolve critical code review findings and hardening suggestions - #43

Merged
syniol merged 9 commits into
mainfrom
fix/java-sdk-hardening
Aug 30, 2026
Merged

fix(java): resolve critical code review findings and hardening suggestions#43
syniol merged 9 commits into
mainfrom
fix/java-sdk-hardening

Conversation

@syniol

@syniol syniol commented Aug 30, 2026

Copy link
Copy Markdown
Collaborator

Summary of Fixes

🔴 Critical Issues Addressed

  1. ClientConfig Thread-Safety & Immutability:

    • Made ClientConfig final and converted all state fields to private final.
    • Removed public mutable setters (setApiKey, setApiBaseUrl, setConnectTimeoutMs, setRequestTimeoutMs, setMaxResponseBytes, setAllowInsecureHttp, setHttpClient).
    • Added ClientConfig.builder(), ClientConfig.builder(apiKey), ClientConfig.builder(apiKeySupplier), and toBuilder() for thread-safe instantiation and copying.
    • PII-redacted API key in ClientConfig.toString().
  2. Resource Cleanup in XyoClient.close():

    • Implemented dynamic AutoCloseable inspection on HttpClient in XyoClient.close() to release selector threads, executors, and connection pools when running on Java 21+.
  3. API Key Supplier Exception Wrapping:

    • Wrapped apiKeySupplier.get() in try-catch across XyoClient constructor, request interceptors, and binary download routes, converting unchecked supplier errors into XyoException with ErrorCategory.VALIDATION to prevent vault/secret credential leakage.
  4. EnrichmentRequest.validate() Consistency & ISO 3166-1 Alpha-2:

    • Trimmed content before evaluating length limits (codePointCount <= 128).
    • Added strict isAlpha2 validation enforcing ISO 3166-1 alpha-2 format.
    • PII-redacted content=[REDACTED] in EnrichmentRequest.toString().
    • Guaranteed wire normalization (content.trim(), countryCode.trim().toUpperCase(Locale.ROOT)).

🟡 Hardening Suggestions Addressed

  • Extracted duplicated CRLF injection checks to validateApiUser(String apiUser).
  • Canonicalized overloaded client methods through RequestOptions.
  • Added @Nullable annotations from JSpecify to XyoException, ClientConfig, and DTO getters.
  • Added static factory methods to XyoException (validation, http, transport, parsing, rateLimit).
  • Added toString() implementations to EnrichmentResponse and EnrichTransactionCollectionResponse.
  • Enforced strict HTTPS for AWS S3 archive downloads even when allowInsecureHttp is enabled.
  • Added comprehensive unit tests covering all fixes (49 tests passing).

@syniol syniol self-assigned this Aug 30, 2026
syniol added 8 commits August 30, 2026 20:49
…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
@syniol
syniol merged commit 201a8ef into main Aug 30, 2026
6 checks passed
@syniol
syniol deleted the fix/java-sdk-hardening branch August 30, 2026 20:19
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant