Improve JAAS configuration handling in Kerberos authentication - #2961
Merged
Divang Sharma (divang) merged 11 commits intoJun 23, 2026
Conversation
Update LoginContext initialization to use JaasConfiguration with null delegate for consistent behavior. Add configuration validation to ensure only supported login modules are used. Changes: - Use JaasConfiguration constructor with null parameter - Add validateNoJndiLoginModule method for configuration validation - Maintain compatibility with Krb5LoginModule authentication
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #2961 +/- ##
============================================
- Coverage 60.84% 59.19% -1.65%
- Complexity 4981 5034 +53
============================================
Files 151 153 +2
Lines 35223 36332 +1109
Branches 5900 6644 +744
============================================
+ Hits 21430 21507 +77
- Misses 10935 11086 +151
- Partials 2858 3739 +881 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
…unit tests for the new assertSafeJaasLoginConfigProperty guard.
Mahendra Chavan (machavan)
requested review from
Copilot and
Mahendra Chavan (machavan)
June 2, 2026 18:03
Mahendra Chavan (machavan)
previously approved these changes
Jun 2, 2026
Contributor
There was a problem hiding this comment.
Pull request overview
This PR hardens Kerberos (JAAS-based) integrated authentication by reducing reliance on the JVM-wide JAAS configuration and adding a guard that rejects potentially remote java.security.auth.login.config values, preventing unsafe JAAS config loading during LoginContext.login().
Changes:
- Updated Kerberos login initialization to use
JaasConfiguration(null)for theuseDefaultJaasConfig=truepath and addedassertSafeJaasLoginConfigProperty()for defense-in-depth against remote JAAS config sources. - Added a new localized error string (
R_unsafeJaasLoginConfigProperty) to provide actionable guidance when unsafe config is detected. - Added tests in
KerberosTestto validate accept/deny behavior forjava.security.auth.login.configvalues.
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 3 comments.
| File | Description |
|---|---|
src/main/java/com/microsoft/sqlserver/jdbc/KerbAuthentication.java |
Adds property validation to block remote JAAS config sources and adjusts default JAAS configuration usage. |
src/main/java/com/microsoft/sqlserver/jdbc/SQLServerResource.java |
Adds a new driver error message for unsafe JAAS login config property values. |
src/test/java/com/microsoft/sqlserver/jdbc/KerberosTest.java |
Adds tests for the new JAAS config property validation behavior. |
…ection The URISyntaxException catch block previously used the deprecated java.net.URL(String) constructor (deprecated since JDK 20) as a fallback to detect remote schemes. Replace with a simpler string-based approach: extract the scheme from 'scheme://' pattern and validate it against RFC 3986 syntax. Benefits: - No deprecated API usage - Catches all remote schemes (ldap, rmi, ldaps) not just those with registered URL stream handlers - Simpler code with no nested try/catch
… name - Set driverErrorCode to DRIVER_ERROR_UNSUPPORTED_CONFIG on both throw paths so connection retry logic correctly treats this as fatal - Rename testJaasConfigurationSecureDefaults to testAssertSafeJaasLoginConfigProperty_allowsNullProperty to accurately reflect what it tests
Block remote URI schemes (http, https, ldap, ftp, rmi, ldaps) in the java.security.auth.login.config system property before Kerberos login. Only local filesystem paths and file: URIs are permitted. - Add assertSafeJaasLoginConfigProperty() allow-list validation - Handle '=' prefix (JAAS exclusive-config syntax) - Use URI scheme check + Paths.get() as path validity gate - Add failUnsafeJaasLoginConfig() helper with SEVERE logging - Update R_unsafeJaasLoginConfigProperty error message - Add 5 unit tests covering null, remote URLs, local paths, PoC payloads, and malformed remote URIs
Mahendra Chavan (machavan)
requested review from
Ananya Garg (Ananya2) and
Muskan Gupta (muskan124947)
June 18, 2026 09:05
Mahendra Chavan (machavan)
previously approved these changes
Jun 18, 2026
Mahendra Chavan (machavan)
approved these changes
Jun 19, 2026
Ananya Garg (Ananya2)
approved these changes
Jun 19, 2026
Muskan Gupta (muskan124947)
approved these changes
Jun 19, 2026
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.
Description
This PR hardens Kerberos authentication by adding defense-in-depth validation of the
java.security.auth.login.configsystem property. It blocks remote JAAS config sources (JNDI injection vector, MSRC-117029) while preserving local file path behavior.Changes
Modified Files
src/main/java/com/microsoft/sqlserver/jdbc/KerbAuthentication.javainitAuthInit()to useJaasConfiguration(null)for theuseDefaultJaasConfig=truepathassertSafeJaasLoginConfigProperty()to block remote schemes (http, https, ldap, rmi, ftp, etc.)failUnsafeJaasLoginConfig()helper that logs at SEVERE and throwsSQLServerExceptionjava.net.URIparsing to detect non-file schemes, withjava.nio.file.Paths.get()fallback for values that aren't valid URIs=prefix syntax (forces single config source) by stripping before validationsrc/main/java/com/microsoft/sqlserver/jdbc/SQLServerResource.javaR_unsafeJaasLoginConfigPropertyerror messageTest Files
src/test/java/com/microsoft/sqlserver/jdbc/KerberosTest.javatestAssertSafeJaasLoginConfigProperty_allowsNullProperty()— null/empty property passestestAssertSafeJaasLoginConfigProperty_rejectsRemoteUrls()— blocks http/https/ldap/ftptestAssertSafeJaasLoginConfigProperty_allowsLocalPaths()— permits file paths and file: URIstestMSRC117029_pocPayloadsBlocked()— proves exact PoC payloads from the vulnerability report are blocked (including=-prefixed variants)testAssertSafeJaasLoginConfigProperty_rejectsMalformedRemoteUrls()— catches malformed remote URLs that bypass URI parsing but would still be fetched byjava.net.URLKey Behavior
/etc/jaas.conf,C:\config\jaas.conf),file:URIs,=-prefixed local pathshttp://,https://,ldap://,rmi://,ftp://, etc.)SecurityManagerdenies reading the property, throws rather than proceeding blindSQLServerExceptionimmediately — no retries, no network activityBenefits
ConfigFile(which usesjava.net.URLinternally)java.net.URI+java.nio.file.Pathsinstead of deprecatedjava.net.URL(String)=prefix that forces Java to use only the specified config sourceTesting
Backward Compatibility
useDefaultJaasConfig=truecontinues to work with built-inJaasConfigurationBackward Compatibility
Fully backward compatible