Skip to content

fix: prevent null crash on empty JWT private key (#1703)#1706

Open
deepak0x wants to merge 1 commit into
foss42:mainfrom
deepak0x:fix/jwt-private-key-null-crash
Open

fix: prevent null crash on empty JWT private key (#1703)#1706
deepak0x wants to merge 1 commit into
foss42:mainfrom
deepak0x:fix/jwt-private-key-null-crash

Conversation

@deepak0x

@deepak0x deepak0x commented Jun 25, 2026

Copy link
Copy Markdown

PR Description

AuthJwtModel.privateKey is nullable (String?), but substituteAuthModel() in lib/utils/envvar_utils.dart force-unwraps the result of substituteVariables(jwt.privateKey, envVarMap)!. Since substituteVariables() returns null for null input, using JWT auth without a private key crashes with "Null check operator used on a null value."

This restores the safe ?? jwt.privateKey fallback for privateKey. secret and payload keep ! since they are required String (non-nullable) and cannot be null.

privateKey: substituteVariables(jwt.privateKey, envVarMap) ?? jwt.privateKey,

Related Issues

Checklist

  • I have gone through the contributing guide
  • I have updated my branch and synced it with project main branch before making this PR
  • I am using the latest Flutter stable branch (run flutter upgrade and verify)
  • I have run the tests (flutter test) and all tests are passing

Added/updated tests?

  • Yes — added "jwt auth with null private key does not crash" regression test in test/utils/envvar_utils_test.dart. Verified locally on Flutter 3.44.4 / Dart 3.12.2 — all tests in test/utils/envvar_utils_test.dart pass.

OS on which you have developed and tested the feature?

  • Windows
  • macOS
  • Linux

privateKey is nullable in AuthJwtModel; restore `?? jwt.privateKey`
fallback instead of force-unwrapping substituteVariables() result.
Add regression test for null privateKey.

Closes foss42#1703
@deepak0x deepak0x force-pushed the fix/jwt-private-key-null-crash branch from 8c3966a to 7da78a6 Compare June 26, 2026 04:22
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.

bug: Null crash in substituteAuthModel for JWT privateKey

1 participant