Repository navigation
[patch] Reject whitespace in [IsBase64] regardless of total length - #400
Merged
Merged
Conversation
Fixes #316 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_019RYN9jT6szUiySkywFKCA1
|
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 #316
What was wrong
[IsBase64]checked two things: thatvalue.Length % 4 == 0, and thatConvert.FromBase64String(value)didn't throw.FromBase64Stringsilently skips spaces, tabs, CR and LF, but the length check counts them. So a value containing whitespace passed whenever the whitespace made the total length a multiple of 4, and it was stored verbatim. The existingIsBase64Attribute_Base64WithSpaces_ShouldThrowonly passed because its sample happened to be 19 characters long.Change (
Semantics.Strings/Validation/Attributes/Text/IsBase64Attribute.cs)A-Z,a-z,0-9,+,/), followed by at most two=at the end. Anything else fails with the same "must be a valid Base64 string" message.Convert.FromBase64Stringstill runs after that to confirm the padding.Tests (
TextValidationAttributesTests)IsBase64Attribute_MisplacedPadding_ShouldThrow:=mid-value, a non-=after=, and three=.IsBase64Attribute_PlusAndSlash_ShouldPass: confirms+and/are still accepted.With the fix reverted, 4 of the whitespace cases fail. With the fix, the full
Semantics.Testsuite passes: 1489 passed, 0 failed, 8 skipped.Semantics.Stringsbuilds for every target framework.🤖 Generated with Claude Code
https://claude.ai/code/session_019RYN9jT6szUiySkywFKCA1
Generated by Claude Code