Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 1 addition & 7 deletions lode/dotnet/analyzer-candidates/index.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# Analyzer Candidates: Open Register
*Updated: 2026-11-14T00:08:28Z*
*Updated: 2026-11-16T15:18:25Z*

One register for every open analyzer candidate, whichever repository noticed it.
A candidate enters at status `new`, carries a four-dimension score, and leaves
Expand Down Expand Up @@ -158,9 +158,3 @@ Nushell or Markdown capture stays in the pugworks ledger.
> **Why**: S109 wants each literal behind a named constant, S2339 forbids a public `const` member, and neither accepts the other's answer. The workaround is a private const per value behind a public static property, which doubles the type for no behavior. Either S109 should skip a member whose declaration is the name, or S2339 should allow a const on a table type.
> **Source**: `session friction 2026-11-14T18:20:00Z`, occurrence 1 of 3

### Captured: E128184 must follow a temp directory into the method that deletes it (1/3): score pending
> **Key**: `e128184-must-follow-a-temp-directory-into-the-method-that-delet`
> **Class**: `design`, **Lang**: `cs`, **File**: `src/Harvest/Commands/ReadCommand.cs`
> **Pattern**: A recursive delete of a directory built from `Path.GetTempPath()` stays sound when the deletion moves into a helper
> **Why**: E128184 matches the delete call against a path created in the same method body, so extracting the cleanup into `DeleteTempDirectory(writer, tempDir)` reports a false positive on the package-private producer of that path. The rule should accept a `DirectoryInfo` that carries the temp-root provenance, or at least a helper in the same type.
> **Source**: `session friction 2026-11-14T18:22:00Z`, occurrence 1 of 3
7 changes: 4 additions & 3 deletions lode/dotnet/analyzers/rule-details-security.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# Security Rule Detail Notes
*Updated: 2026-11-14T01:26:59Z*
*Updated: 2026-11-16T15:18:25Z*

Detection shape and exclusions for the E128 security rules that the main rule
table cannot show. The severity and the code-fix status live in
Expand All @@ -18,8 +18,9 @@ stays silent. A body bound counts when it sits in the enclosing method body or
the enclosing lambda body, and the rule resolves the bound by symbol, not by
name text:

- A resolved `HttpContent.LoadIntoBufferAsync(long)` call. The parameterless
overload does not bound anything.
- A resolved `HttpContent.LoadIntoBufferAsync` call whose first parameter is
`long`, with or without a trailing `CancellationToken`. The parameterless
overload and the `CancellationToken`-only overload do not bound anything.
- A null-safe `ContentLength` comparison on the same receiver chain. The check
must precede and dominate the read. A read inside the `then` branch needs a
condition that is false when `ContentLength` is `null`. A read outside it
Expand Down
26 changes: 13 additions & 13 deletions lode/dotnet/analyzers/rule-details.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# Rule Detail Notes
*Updated: 2026-11-13T22:43:20Z*
*Updated: 2026-11-16T15:19:01Z*

Behavior notes for individual E128 rules. The complete rule table, the
severity, and the code-fix status live in `src/E128.Analyzers/README.md`. This
Expand Down Expand Up @@ -97,18 +97,19 @@ Severity: **Info**. Flags a recursive `Directory.Delete` or
a build gate blocks work for no gain, so the severity stays low and the reported
set stays narrow.

**Reported**: a parameter, a field read, a property read, and a `Path.Combine`
whose first argument is one of those.
**Reported**: a parameter that no safe call site bounds, a field read, a property
read, a `Path.Combine` over one of those, and a rooted literal such as
`"/etc/nginx"`. A readonly field, a get-only property, and a mutable field
report, because the value is computed at run time.

**Silent**: a path under `Path.GetTempPath()`, a relative string literal, a const
field, a `Path.GetFullPath` over a safe value, a local that holds one of those, an
unknown shape, a non-recursive call, and a delete guarded by a proving
`StartsWith` test on the same path in the same block.
field, a `Path.GetFullPath` result, a `DirectoryInfo` over either, a local that
holds one of those, an unknown shape, a non-recursive call, and a delete guarded
by a proving `StartsWith` test.

**Reported literals**: a rooted literal, such as `"/etc/nginx"` or `"C:\Data"`.
The rule cannot prove such a directory is disposable. A readonly field, a
get-only property, and a mutable field report, because the value is computed at
run time.
**Parameter provenance**: the parameter of a private method takes the safety of
its call sites in the same type part. A call cycle, a non-private method, a
split type, or no visible call stays unsafe.

A guard proves the test passed in two shapes, and the comparison must use
`StringComparison.Ordinal` or `OrdinalIgnoreCase` with a root that ends at a
Expand All @@ -120,9 +121,8 @@ around the delete and an `||` condition do not count.

A local alias counts as the value it holds. A `Path.Combine` under a temp path
stays silent when a later segment comes from a variable, because the rule cannot
see a `..` or a rooted value in it.

No code fix. The safe root belongs to the caller.
see a `..` or a rooted value in it. No code fix: the safe root belongs to the
caller.

### E128191: PFX import without `EphemeralKeySet`

Expand Down
2 changes: 1 addition & 1 deletion src/E128.Analyzers/E128.Analyzers.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@

<!-- NuGet Packaging -->
<PropertyGroup>
<Version>3.1.1</Version>
<Version>3.1.2</Version>
<IsPackable>true</IsPackable>
<IncludeBuildOutput>false</IncludeBuildOutput>
<DevelopmentDependency>true</DevelopmentDependency>
Expand Down
10 changes: 5 additions & 5 deletions src/E128.Analyzers/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ Roslyn analyzers and code fixes that enforce opinionated .NET conventions at com
## Installation

```xml
<PackageReference Include="E128.Analyzers" Version="3.1.1" PrivateAssets="all" />
<PackageReference Include="E128.Analyzers" Version="3.1.2" PrivateAssets="all" />
```

> `PrivateAssets="all"` keeps the analyzers out of your consumers' dependency graph.
Expand Down Expand Up @@ -1973,9 +1973,9 @@ await winner;

### E128184: Recursive delete outside a recognized safe root

Flags a recursive `Directory.Delete` or `DirectoryInfo.Delete` when the path is a parameter, a field read, a property read, or a `Path.Combine` whose first argument is one of those. The severity is Info, because a false positive on a build gate blocks work for no gain.
Flags a recursive `Directory.Delete` or `DirectoryInfo.Delete` when the path is a parameter that no safe call site bounds, a field read, a property read, or a `Path.Combine` whose first argument is one of those. The severity is Info, because a false positive on a build gate blocks work for no gain.

A path under `Path.GetTempPath()`, a relative string literal, a const field, and a `Path.GetFullPath` over a safe value are recognized as safe. A local that holds one of those is also safe, and a local alias counts as the value it holds. A rooted literal reports, for example `"/etc/nginx"` or `"C:\Data"`, because the rule cannot prove the directory is disposable. A readonly field, a get-only property, and a mutable field report, because the value is computed at run time.
A path under `Path.GetTempPath()`, a relative string literal, a const field, and a `Path.GetFullPath` over a safe value are recognized as safe. A local that holds one of those is also safe, and a local alias counts as the value it holds. A `DirectoryInfo` created over a safe path is safe too. A parameter of a private method is safe when every call site in the same type part passes a safe path, so a cleanup helper keeps the provenance of its caller. A rooted literal reports, for example `"/etc/nginx"` or `"C:\Data"`, because the rule cannot prove the directory is disposable. A readonly field, a get-only property, and a mutable field report, because the value is computed at run time.

A guard counts only when it proves the test passed. The comparison must use `StringComparison.Ordinal` or `OrdinalIgnoreCase`, and the root must end at a separator boundary, so a prefix test cannot pass for a sibling directory. An enclosing `if` that holds the call alone or joined by `&&` counts, and so does a preceding `if` with no `else` that exits when the call is false. The guard must be the statement before the delete. A write to the guarded symbol between the guard and the delete voids the guard. A negated test around the delete and an `||` condition do not count.

Expand Down Expand Up @@ -3276,14 +3276,14 @@ HashSet<string> set = [with(StringComparer.OrdinalIgnoreCase), .. items];

Flags an `HttpContent.ReadAsStringAsync` or `HttpContent.ReadAsByteArrayAsync` call that buffers the whole body with no cap. An untrusted server can answer with a body large enough to exhaust the heap.

The rule resolves the read and the bound by symbol, not by name. A bound must precede the read. A bound is a resolved `HttpContent.LoadIntoBufferAsync` call with the `long` cap overload, or a null-safe `ContentLength` comparison on the same content chain. A plain greater-than guard does not bound the read, because `ContentLength` is `null` for a chunked response and the guard passes through. A `MaxResponseContentBufferSize` setting anywhere in the enclosing type bounds it too. An in-memory content type (`StringContent`, `ByteArrayContent`, `ReadOnlyMemoryContent`, `JsonContent`) needs no bound, because its size is already known. The rule carries no code fix, because the cap value is a caller decision.
The rule resolves the read and the bound by symbol, not by name. A bound must precede the read. A bound is a resolved `HttpContent.LoadIntoBufferAsync` call with the `long` cap overload, with or without a trailing `CancellationToken`, or a null-safe `ContentLength` comparison on the same content chain. A plain greater-than guard does not bound the read, because `ContentLength` is `null` for a chunked response and the guard passes through. A `MaxResponseContentBufferSize` setting anywhere in the enclosing type bounds it too. An in-memory content type (`StringContent`, `ByteArrayContent`, `ReadOnlyMemoryContent`, `JsonContent`) needs no bound, because its size is already known. The rule carries no code fix, because the cap value is a caller decision.

```csharp
// Before (warns)
var json = await response.Content.ReadAsStringAsync(cancellationToken);

// After option 1: cap the buffer load.
await response.Content.LoadIntoBufferAsync(MaxBodyBytes);
await response.Content.LoadIntoBufferAsync(MaxBodyBytes, cancellationToken);
var json = await response.Content.ReadAsStringAsync(cancellationToken);

// After option 2: fail closed when ContentLength is unknown.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ namespace E128.Analyzers.Security;
/// <remarks>
/// The rule resolves symbols instead of matching names. A bound must precede the read and
/// dominate it. A bound is a resolved <c lang="csharp">HttpContent.LoadIntoBufferAsync</c>
/// call with the <c lang="csharp">long</c> cap overload, or a null-safe
/// cap overload, with or without a trailing <c lang="csharp">CancellationToken</c>, or a null-safe
/// <c lang="csharp">ContentLength</c> comparison on the same content chain. A plain
/// greater-than guard does not bound the read, because <c lang="csharp">ContentLength</c> is
/// <c lang="csharp">null</c> for a chunked response and the guard passes through. A
Expand All @@ -43,8 +43,13 @@ public sealed class HttpBodyReadWithoutSizeBoundAnalyzer : DiagnosticAnalyzer

private const string CappedBufferLoadName = "LoadIntoBufferAsync";

private const string CancellationTokenTypeName = "System.Threading.CancellationToken";

private const string ContentLengthName = "ContentLength";

// A cap overload takes the long cap, optionally followed by a CancellationToken.
private const int MaxCapOverloadParameterCount = 2;

private static readonly ImmutableHashSet<string> ReadMethodNames = ImmutableHashSet.Create(
StringComparer.Ordinal,
"ReadAsStringAsync",
Expand Down Expand Up @@ -92,9 +97,10 @@ public override void Initialize(AnalysisContext context)
];

var httpContentHeaders = startContext.Compilation.GetTypeByMetadataName(HttpContentHeadersTypeName);
var cancellationToken = startContext.Compilation.GetTypeByMetadataName(CancellationTokenTypeName);

startContext.RegisterSyntaxNodeAction(
nodeContext => AnalyzeRead(nodeContext, httpContent, httpContentHeaders, inMemoryContents),
nodeContext => AnalyzeRead(nodeContext, httpContent, httpContentHeaders, cancellationToken, inMemoryContents),
SyntaxKind.InvocationExpression);
});
}
Expand All @@ -103,6 +109,7 @@ private static void AnalyzeRead(
SyntaxNodeAnalysisContext context,
INamedTypeSymbol httpContent,
INamedTypeSymbol? httpContentHeaders,
INamedTypeSymbol? cancellationTokenType,
INamedTypeSymbol?[] inMemoryContents)
{
var invocation = (InvocationExpressionSyntax)context.Node;
Expand All @@ -123,7 +130,7 @@ private static void AnalyzeRead(

var receiverType = model.GetTypeInfo(access.Expression, cancellationToken).Type;
if (IsInMemoryContent(receiverType, inMemoryContents)
|| HasSizeBound(invocation, model, httpContent, httpContentHeaders, cancellationToken))
|| HasSizeBound(invocation, model, httpContent, httpContentHeaders, cancellationTokenType, cancellationToken))
{
return;
}
Expand Down Expand Up @@ -154,6 +161,7 @@ private static bool HasSizeBound(
SemanticModel model,
INamedTypeSymbol httpContent,
INamedTypeSymbol? httpContentHeaders,
INamedTypeSymbol? cancellationTokenType,
CancellationToken cancellationToken)
{
var scope = BlockScope.GetScope(read);
Expand All @@ -164,7 +172,7 @@ private static bool HasSizeBound(
{
var contentLength = GetContentLengthProperty(httpContentHeaders);
var boundVariables = CollectBoundVariables(scope, model, contentLength, readRoot, cancellationToken);
if (HasCappedBufferLoad(scope, read, readRoot, model, httpContent, cancellationToken)
if (HasCappedBufferLoad(scope, read, readRoot, model, httpContent, cancellationTokenType, cancellationToken)
|| HasContentLengthBound(scope, read, readRoot, model, contentLength, boundVariables, cancellationToken))
{
return true;
Expand All @@ -178,7 +186,8 @@ private static bool HasSizeBound(

/// <summary>
/// True when a resolved <c lang="csharp">LoadIntoBufferAsync</c> call on the same content
/// chain uses the cap overload with a <c lang="csharp">long</c> argument. The
/// chain uses the cap overload with a <c lang="csharp">long</c> argument. The overload may
/// also take a <c lang="csharp">CancellationToken</c>, so the token-aware form counts. The
/// parameterless overload reads the whole body and does not bound anything.
/// </summary>
private static bool HasCappedBufferLoad(
Expand All @@ -187,13 +196,14 @@ private static bool HasCappedBufferLoad(
string readRoot,
SemanticModel model,
INamedTypeSymbol httpContent,
INamedTypeSymbol? cancellationTokenType,
CancellationToken cancellationToken)
{
foreach (var candidate in scope.DescendantNodes().OfType<InvocationExpressionSyntax>())
{
if (candidate != read
&& SameRoot(candidate.Expression, readRoot)
&& IsCappedBufferLoad(candidate, model, httpContent, cancellationToken)
&& IsCappedBufferLoad(candidate, model, httpContent, cancellationTokenType, cancellationToken)
&& Dominates(candidate, read, scope))
{
return true;
Expand All @@ -207,13 +217,16 @@ private static bool IsCappedBufferLoad(
InvocationExpressionSyntax invocation,
SemanticModel model,
INamedTypeSymbol httpContent,
INamedTypeSymbol? cancellationTokenType,
CancellationToken cancellationToken)
{
return model.GetSymbolInfo(invocation, cancellationToken).Symbol is IMethodSymbol method
&& string.Equals(method.Name, CappedBufferLoadName, StringComparison.Ordinal)
&& TypeSymbols.DerivesFrom(method.ContainingType, httpContent)
&& method.Parameters.Length is 1
&& method.Parameters[0].Type.SpecialType is SpecialType.System_Int64;
&& method.Parameters.Length is >= 1 and <= MaxCapOverloadParameterCount
&& method.Parameters[0].Type.SpecialType is SpecialType.System_Int64
&& (method.Parameters.Length is 1
|| TypeSymbols.Matches(method.Parameters[1].Type, cancellationTokenType));
}

/// <summary>
Expand Down
Loading