Skip to content

Improve JAAS configuration handling in Kerberos authentication - #2961

Merged
Divang Sharma (divang) merged 11 commits into
mainfrom
user/divang/improve-jaas-config-handling
Jun 23, 2026
Merged

Improve JAAS configuration handling in Kerberos authentication#2961
Divang Sharma (divang) merged 11 commits into
mainfrom
user/divang/improve-jaas-config-handling

Conversation

@divang

@divang Divang Sharma (divang) commented May 26, 2026

Copy link
Copy Markdown
Contributor

Description

This PR hardens Kerberos authentication by adding defense-in-depth validation of the java.security.auth.login.config system 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.java

    • Updated initAuthInit() to use JaasConfiguration(null) for the useDefaultJaasConfig=true path
    • Added assertSafeJaasLoginConfigProperty() to block remote schemes (http, https, ldap, rmi, ftp, etc.)
    • Added failUnsafeJaasLoginConfig() helper that logs at SEVERE and throws SQLServerException
    • Uses java.net.URI parsing to detect non-file schemes, with java.nio.file.Paths.get() fallback for values that aren't valid URIs
    • Handles JAAS = prefix syntax (forces single config source) by stripping before validation
  • src/main/java/com/microsoft/sqlserver/jdbc/SQLServerResource.java

    • Added R_unsafeJaasLoginConfigProperty error message

Test Files

  • src/test/java/com/microsoft/sqlserver/jdbc/KerberosTest.java
    • testAssertSafeJaasLoginConfigProperty_allowsNullProperty() — null/empty property passes
    • testAssertSafeJaasLoginConfigProperty_rejectsRemoteUrls() — blocks http/https/ldap/ftp
    • testAssertSafeJaasLoginConfigProperty_allowsLocalPaths() — permits file paths and file: URIs
    • testMSRC117029_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 by java.net.URL

Key Behavior

  • Allowed: local file paths (/etc/jaas.conf, C:\config\jaas.conf), file: URIs, =-prefixed local paths
  • Blocked: any non-file remote scheme (http://, https://, ldap://, rmi://, ftp://, etc.)
  • Fail-closed: if SecurityManager denies reading the property, throws rather than proceeding blind
  • Fail-fast: throws SQLServerException immediately — no retries, no network activity

Benefits

  1. JNDI Injection Prevention: Remote JAAS configs can declare arbitrary LoginModules (e.g. JndiLoginModule) triggering JNDI/LDAP lookups during login, leading to RCE
  2. Defense in Depth: Path-based fallback catches malformed URLs that bypass URI parsing but may still be opened by JAAS ConfigFile (which uses java.net.URL internally)
  3. No Deprecated APIs: Uses java.net.URI + java.nio.file.Paths instead of deprecated java.net.URL(String)
  4. JAAS Syntax Aware: Handles the = prefix that forces Java to use only the specified config source

Testing

  • Unit tests validate accept/reject behavior via reflection on the package-private method
  • Tests cover exact MSRC-117029 PoC payloads to prove the vulnerability is mitigated
  • All existing Kerberos integration tests pass without modification

Backward Compatibility

  • Standard local JAAS config files remain fully supported (absolute/relative paths, UNC paths, file: URIs)
  • useDefaultJaasConfig=true continues to work with built-in JaasConfiguration
  • No changes to connection string properties or public API

Backward Compatibility

Fully backward compatible

  • Existing connection strings work without changes
  • Standard Krb5LoginModule authentication remains fully supported
  • No changes to public API or connection properties

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

codecov Bot commented May 26, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 0% with 40 lines in your changes missing coverage. Please review.
✅ Project coverage is 59.19%. Comparing base (a93baff) to head (3b43743).
⚠️ Report is 14 commits behind head on main.

Files with missing lines Patch % Lines
...m/microsoft/sqlserver/jdbc/KerbAuthentication.java 0.00% 40 Missing ⚠️
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.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 the useDefaultJaasConfig=true path and added assertSafeJaasLoginConfigProperty() 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 KerberosTest to validate accept/deny behavior for java.security.auth.login.config values.

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.

Comment thread src/main/java/com/microsoft/sqlserver/jdbc/KerbAuthentication.java Outdated
Comment thread src/test/java/com/microsoft/sqlserver/jdbc/KerberosTest.java
Comment thread src/main/java/com/microsoft/sqlserver/jdbc/KerbAuthentication.java
…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
Comment thread src/test/java/com/microsoft/sqlserver/jdbc/KerberosTest.java Outdated
@divang
Divang Sharma (divang) merged commit 574bb92 into main Jun 23, 2026
19 of 23 checks passed
@github-project-automation github-project-automation Bot moved this from In progress to Closed/Merged PRs in MSSQL JDBC Jun 23, 2026
@divang Divang Sharma (divang) added this to the 13.5.1 milestone Jul 13, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Closed/Merged PRs

Development

Successfully merging this pull request may close these issues.

5 participants