Validate reflective class names for connection properties - #3004
Conversation
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #3004 +/- ##
============================================
+ Coverage 60.18% 60.23% +0.05%
- Complexity 5138 5164 +26
============================================
Files 153 153
Lines 36673 36679 +6
Branches 6733 6733
============================================
+ Hits 22073 22095 +22
- Misses 10751 10759 +8
+ Partials 3849 3825 -24 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
There was a problem hiding this comment.
Pull request overview
Adds early validation for connection-property class names that are instantiated reflectively (e.g., socket factory and access token callback), failing fast on malformed values with a dedicated error message to avoid confusing reflective-loading failures.
Changes:
- Validate
classNameinUtil.newInstanceusing a Java identifier–based binary-name check before callingClass.forName. - Introduce a new driver resource string (
R_invalidClassNameForProperty) used when rejecting invalid class names. - Add regression tests ensuring invalid reflective class-name payloads are rejected early for
socketFactoryClassandaccessTokenCallbackClass.
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
| src/main/java/com/microsoft/sqlserver/jdbc/Util.java | Adds pre-reflection class-name validation and new invalid-name error path. |
| src/main/java/com/microsoft/sqlserver/jdbc/SQLServerResource.java | Adds the localized error string for invalid reflective class-name values. |
| src/test/java/com/microsoft/sqlserver/jdbc/SQLServerConnectionTest.java | Adds tests asserting Util.newInstance rejects malformed class-name inputs. |
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
Use whole-name regex validation, restore the defining class loader, and expand regression coverage for invalid names, trust managers, and assignability.
|
|
Restore invalid socket factory and access token callback class-name regressions in UtilTest, and add positive coverage for loadable class names.
Description:
This change adds early validation for reflective class-name values supplied through connection properties such as socketFactoryClass and accessTokenCallbackClass. Malformed values are now rejected before reflective loading, which prevents confusing downstream failures and improves security posture.
What changed
Added validation in Util.newInstance to ensure the supplied value is a valid Java binary class name.
Added a dedicated driver error message for invalid reflective class names.
Added regression tests covering malformed socketFactoryClass and accessTokenCallbackClass values.
Why
Previously, malformed class-name values could reach reflective loading and fail later with less informative errors. This patch fails fast and makes the behavior explicit.
Validation
Verified with Maven compile
Verified with targeted regression tests: 2 tests run