Repository navigation
fix: resolve CodeQL code quality findings - #70
Merged
Merged
Conversation
- AssemblyExtensions: reject a filename with a directory part. A rooted filename made Path.Combine drop targetDirectory, and ".." escaped it. Path.Join is used from there on. - NumericRangeTools: drop the unreachable zero-step guard inside the range iterators and validate step with IsFinite plus an epsilon check. - Replace "HasValue == false" with a negation in TaskExtensions and SemaphoreSlimExtensions. - UriExtensions, StringExtensions: filter with OfType/Where instead of a foreach whose body is a single if. - Tests: dispose CancellationTokenSource, use Path.Join, stop swallowing exceptions with a bare catch, avoid dereferencing a null-initialised local, and cover the new filename validation.
Contributor
There was a problem hiding this comment.
🟡 Changes recommended
The filename check accepts "." and "..", allowing extraction to create directories before failing with IOException instead of the expected ArgumentException.
1 open issue
What changed in this PR
This PR addresses CodeQL quality findings in the .NET extension library, focusing on resource-extraction filename validation and targeted cleanup without changing public signatures.
Changes:
- Validate extraction filenames, use
Path.Join, and document the new exception behavior. - Simplify numeric step validation, nullable checks, and filtered loops.
- Add filename-validation tests and improve test resource disposal and exception assertions.
| File | Description |
|---|---|
| Plugin.BaseTypeExtensions/UriExtensions.cs | Filter null query keys with OfType. |
| Plugin.BaseTypeExtensions/TaskExtensions.cs | Simplify nullable timeout checks. |
| Plugin.BaseTypeExtensions/StringExtensions.cs | Extract and apply the character-filter predicate. |
| Plugin.BaseTypeExtensions/SemaphoreSlimExtensions.cs | Simplify nullable timeout checks. |
| Plugin.BaseTypeExtensions/NumericRangeTools.cs | Consolidate floating-point step validation and remove redundant guards. |
| Plugin.BaseTypeExtensions/AssemblyExtensions.cs | Validate extraction filenames, use Path.Join, and update exception documentation. |
| Plugin.BaseTypeExtensions.Tests/TaskExtensionsTests.cs | Dispose cancellation sources and assert expected exceptions explicitly. |
| Plugin.BaseTypeExtensions.Tests/SemaphoreSlimExtensionsTests.cs | Dispose cancellation sources. |
| Plugin.BaseTypeExtensions.Tests/ListExtensionsTests.cs | Dispose the cancellation source. |
| Plugin.BaseTypeExtensions.Tests/ExceptionExtensionsTests.cs | Catch the specific expected exception. |
| Plugin.BaseTypeExtensions.Tests/EnumerableExtensionsTests.cs | Dispose the cancellation source. |
| Plugin.BaseTypeExtensions.Tests/DictionaryExtensionsTests.cs | Dispose the cancellation source. |
| Plugin.BaseTypeExtensions.Tests/ConcurrentDictioneryExtensionsTests.cs | Dispose cancellation sources and adjust null-test declarations. |
| Plugin.BaseTypeExtensions.Tests/CancellationTokenExtensionsTests.cs | Retain and dispose cancellation sources explicitly. |
| Plugin.BaseTypeExtensions.Tests/AssemblyExtensionsTests.cs | Add filename-rejection tests and switch path construction to Path.Join. |
Review effort: Balanced
| /// </summary> | ||
| private static void ThrowIfNotPlainFileName(string filename) | ||
| { | ||
| if (string.IsNullOrWhiteSpace(filename) || Path.GetFileName(filename) != filename) |
8 of 23 tasks
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.

Summary
Triage of the open CodeQL code quality findings (65 across 8 rules). Six rules are addressed. Two are left as they are on purpose (see Why).
MoveManifestResourceToDirectory[Async]and the cache variants now reject afilenamethat has a directory part, and usePath.Join.NumericRangeTools.GetRange(float/double): removed an unreachable zero-step guard,stepis validated withIsFiniteplus an epsilon check.!x.HasValueinstead ofx.HasValue == false,OfType/Whereinstead of aforeachwrapping a singleif.CancellationTokenSource,Path.Join, no barecatch, no!on a null-initialised local.Why
Path.Combine(21 findings): the 4 production calls were a real bug. A rootedfilenamemadePath.CombinedroptargetDirectory, and..escaped it, so a caller-supplied name could write outside the target directory. The 17 test calls were noise and are switched for consistency.TaskExtensionsare intentional (they forward every exception to the caller's callback orTaskCompletionSource) and are unchanged. The 4 in tests are fixed.Constant conditionfinding could not be located from source alone, so it is still open.Change Type
Affected Areas
Behavior And Compatibility
MoveManifestResourceToDirectory,MoveManifestResourceToDirectoryAsync,MoveManifestResourceToCacheandMoveManifestResourceToCacheAsyncnow throwArgumentException(parameterfilename) whenfilenameis empty, rooted, or contains a directory part such assub/file.txtor../x. Before, a rooted name wrote outside the target directory, and a name with a subfolder only worked if that subfolder already existed. Worth a line in the release notes. Signatures are unchanged.Tests
482 tests pass locally (476 before, plus 6 covering the filename validation in the sync and async paths, including that nothing is written outside the target directory for a rooted name).
Documentation
Checklist
type(scope): subject)