Repository navigation
Refuse a null non-nullable credential property when reading or saving [patch] - #204
Merged
Merged
Conversation
CredentialSerialization's options didn't respect nullable annotations, so a stored "Token":null or "Password":null deserialized into a found credential whose property was null, and TryGet handed it to a caller whose first read threw NullReferenceException. Save also persisted a credential built with null!, so the bad entry round-tripped. Set RespectNullableAnnotations, so such an entry reads back as not found through the existing JsonException path, and have Serialize and SerializeToString report a credential that can't be read back as an ArgumentException. Fixes #180 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_017vfJW3kaZKRNvfNtvM4CX6
This was referenced Nov 6, 2026
Resolve the conflict with #207 in Serialize and SerializeToString by keeping both checks: the unknown-type check runs first, then a JsonException from a null non-nullable property is reported as an ArgumentException. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_017vfJW3kaZKRNvfNtvM4CX6
|
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.



Fixes #180
What was wrong
CredentialSerialization.BuildOptions()did not setRespectNullableAnnotations. A stored{"$type":"CredentialWithToken","Token":null}(orUsername/Passwordset tonull) therefore deserialized into a credential with a null non-nullable property.TryGetreturnedtrueand cached it, and the caller's firstcredential.Token.…threwNullReferenceException.Savealso persisted a credential built withToken = null!, so the bad entry round-tripped.Change
BuildOptionssetsRespectNullableAnnotations = true. A null non-nullable property now throwsJsonException, whichDeserializeandDeserializeFromStringalready map tonull, soTryGetreturnsfalse. This matchesUnknownPayloadTests.SerializeandSerializeToStringnow report a credential they can't write as anArgumentExceptionthat names the type and wraps theJsonException. Before, that credential was persisted withnullin it. Every platform store goes through these helpers, soAddOrReplacethrows before the store or cache changes. Its XML docs now list the exception.Tests
New
NullPropertyTests:DeserializeandDeserializeFromStringreturnnullforToken,UsernameorPasswordset tonull.CredentialWithToken,CredentialWithUsernamePasswordandCredentialWithNothingpayloads still deserialize.TryGetreturnsfalsefor each bad entry.SerializeandSerializeToStringthrowArgumentExceptionforToken = null!.AddOrReplacethrows forPassword = null!and leaves both the store and the cache empty.Without the fix, 11 of these 14 fail. The 3 that pass are the complete-payload checks. The full suite on net10.0 (Linux): 99 tests, 94 passed, 0 failed, 5 skipped. The skips are the existing native-store tests that need libsecret or Windows.
This touches the same
BuildOptionsmethod as #203 (#175) but different lines. I checked that the two branches merge without conflict.Generated by Claude Code