Skip to content

fix: resolve cs/dereferenced-value-may-be-null in ListCredentialsAsync - #34

Merged
StuartMeeks merged 1 commit into
mainfrom
fix/codeql-null-deref-listcredentials
Aug 22, 2026
Merged

fix: resolve cs/dereferenced-value-may-be-null in ListCredentialsAsync#34
StuartMeeks merged 1 commit into
mainfrom
fix/codeql-null-deref-listcredentials

Conversation

@StuartMeeks

Copy link
Copy Markdown
Owner

What

Resolves the one open code-scanning alert on main (cs/dereferenced-value-may-be-null, FileCredentialManager.cs:79) with a genuine code fix — no dismissal.

Why it appeared now

The corrected buildless CodeQL analysis (#33) reads this file properly for the first time — the old compiled-build config had paths-ignore silently inert and analysed the wrong scope. The finding is real in the sense that CodeQL now sees it; the code itself was already safe.

The fix

The provider-match guard was:

if (credential?.ProviderName.Equals(providerName, StringComparison.OrdinalIgnoreCase) == true)

CodeQL's flow analysis doesn't narrow credential to non-null through the ?.… == true idiom, so every dereference in the block body (credential.ProviderName, .AccountId, .CredentialData, …) reads as a potential null access. Rewritten to:

if (credential is not null &&
    credential.ProviderName.Equals(providerName, StringComparison.OrdinalIgnoreCase))

Behavior is identical (a null credential still makes the guard false and skips the row), but the null state now flows into the block, so both the compiler and CodeQL can prove the accesses safe.

Verification

  • Build clean: 0 warnings (TreatWarningsAsErrors on).
  • 334 tests pass on net8.0 and net10.0.

🤖 Generated with Claude Code

The corrected buildless CodeQL analysis (adopted in #33) surfaced a
cs/dereferenced-value-may-be-null alert on FileCredentialManager.cs: the
provider-match guard was written `credential?.ProviderName.Equals(…) == true`,
and CodeQL's flow analysis does not narrow `credential` to non-null through the
`?.… == true` idiom, so the dereferences in the block body read as potential
null accesses.

The code was already safe (a null credential makes the guard false), but the
guard is rewritten to `credential is not null && …` so the null state flows
into the block — the whole body dereferences `credential` — letting both the
compiler and CodeQL prove it safe. Behavior is unchanged.

Build clean (0 warnings, TreatWarningsAsErrors on); 334 tests pass on net8.0
and net10.0.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
@StuartMeeks
StuartMeeks merged commit 5556856 into main Aug 22, 2026
9 checks passed
@StuartMeeks
StuartMeeks deleted the fix/codeql-null-deref-listcredentials branch August 22, 2026 01:30
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