dotnet-security

dotnet-security is a cursor rule for coding agents from adonai-labs/agent-runway. It costs 1,352 tokens per session, scanned A, original, MIT.

A set of security rules for ASP.NET Core applications, which are web applications built with Microsoft's .NET platform. It covers input checks, database queries, identity, tokens, secrets, and browser security settings.

In plain words
What is it for?
It is for reviewing or writing C# and .NET project files with validated input, safe EF Core database access, secure login and JWT handling, Key Vault integration, and HTTP security headers.
Why use it?
It gives .NET code specific safeguards against common problems such as database injection, unsafe input, weak token checks, and exposed secrets.

Cursor rule

Install

Getting it into your agent

One page per mod, every tool's command on it. A separate URL per tool would split the same page into five that compete with each other.

agentmods
npx agentmods add rules/adonai-labs/agent-runway/dotnet-security
Clone the repo
git clone --depth 1 https://github.com/adonai-labs/agent-runway

Wrote this? Show the measurements

A badge with what this costs and how it scanned, read live from this page, so it follows the numbers instead of freezing them. Markdown for a README, HTML for a documentation site or a project page.

agentmods badge for dotnet-security

README.md
[![agentmods](https://agentmods.dev/badge/rules/adonai-labs/agent-runway/dotnet-security.svg)](https://agentmods.dev/rules/adonai-labs/agent-runway/dotnet-security)
Your own site
<a href="https://agentmods.dev/rules/adonai-labs/agent-runway/dotnet-security"><img src="https://agentmods.dev/badge/rules/adonai-labs/agent-runway/dotnet-security.svg" alt="Measured on agentmods" height="20"></a>
Per session 1,352 This file is loaded in full into every session.
When invoked 1,352 The same file — it is already loaded in full.
Security scan A 0 findings. Scan, not verified.
Origin original No closer match found in the catalogue.
Token cost

What it costs to keep this loaded

Counted locally with the o200k_base tokenizer, which is exact for GPT models; Claude uses its own tokenizer and its counts differ. Treat this as one consistent yardstick across the catalogue rather than a bill. Prices are per million input tokens.

ModelPer sessionOnce invoked
Fable 5 $0.01352 $0.01352
Opus 5 $0.00676 $0.00676
Sonnet 5 $0.00270 $0.00270
Haiku 4.5 $0.00135 $0.00135

Measured 4d ago against content hash 5a850ab60274, method: parsed. Prices are Anthropic first-party input rates as of 2026-08-30, from the pricing page.

Security

Grade A, and why

dotnet-security scanned grade A with 0 findings against 26 rules in 11 categories — prompt injection, anti-refusal, data exfiltration, privilege escalation, supply chain, agent snooping, system-prompt leakage, SSRF and excessive agency — measured 4d ago.

A static scan of the body, not an audit. Every finding is printed with the line that produced it so you can judge whether it matters here. A mod is markdown that instructs an agent; that is exactly why what it instructs is worth reading.

Nothing flagged

None of the 26 patterns this scan looks for appear in this file: no shell pipes, no recursive deletes, no credential paths, no hidden text, no instruction-override or anti-refusal phrasing, no agent-config snooping. That is not a guarantee, it is the absence of the things that are checkable.

src/stacks/dotnet/dotnet-security.mdc · 196 lines

How it starts

The opening of the file, as written. The whole thing — 196 lines — stays where its author put it; the contents beside it link to each section on GitHub.

.NET Security Standards

.NET-specific security practices. For universal security principles, see engineering-security.mdc.

Conflict resolution: Where this file provides .NET-specific guidance that differs from engineering-security.mdc, this file takes precedence for .cs, .csproj, .json, .yaml, and .yml files. The universal rule provides the default; this rule provides the override.


Input validation in .NET

Use FluentValidation in the MediatR pipeline; do not rely on manual inline checks:

public class PlaceOrderCommandValidator : AbstractValidator<PlaceOrderCommand>
{
    public PlaceOrderCommandValidator()
    {
        RuleFor(x => x.CustomerId).NotEmpty();
        RuleFor(x => x.Lines).NotEmpty().WithMessage("At least one line is required");
        RuleFor(x => x.Email).EmailAddress().MaximumLength(254);
    }
}

EF Core — injection prevention

  • Use EF Core LINQ queries or FromSqlRaw with parameters exclusively; never concatenate user input
// Correct
dbContext.Users.FirstOrDefaultAsync(u => u.Email == email, ct);

// Also correct (parameterised raw)
dbContext.Products.FromSqlRaw("SELECT * FROM Products WHERE Category = {0}", category);

// Incorrect — do not do this
var sql = $"SELECT * FROM Products WHERE Category = '{category}'";

Authentication in ASP.NET Core

builder.Services
    .AddAuthentication(JwtBearerDefaults.AuthenticationScheme)
    .AddJwtBearer(options =>
    {
        options.Authority = configuration["Auth:Authority"];
        options.Audience = configuration["Auth:Audience"];
        options.TokenValidationParameters = new TokenValidationParameters
        {
            ValidateIssuer = true,
            ValidateAudience = true,
            ValidateLifetime = true,
            ClockSkew = TimeSpan.Zero
        };
    });
  • Use ASP.NET Core Identity or a delegated identity provider (Entra ID, Okta, Auth0); do not implement custom auth
  • Validate iss, aud, exp, and nbf on every JWT; reject tokens that fail any check
  • Set ClockSkew = TimeSpan.Zero to prevent tokens being valid after expiry

Read the full file on GitHub · 196 lines

Changes

What this file has done since we first saw it

Hashed on every crawl. A supply-chain change to an agent config is a question of when, not whether, so the history is kept rather than the latest state alone.

  1. 4d ago First seen · 196 lines · 1,352 tokens per session scan A 5a850ab60274

Subscribe to this mod's changes

dotnet-security is a cursor rule published in the GitHub repository adonai-labs/agent-runway (2 stars, last pushed 14d ago), licensed MIT. It adds 1,352 tokens to every session, about $0.0068 per session on Opus 5. A static security scan graded it A with 0 findings. No closer match exists in the catalogue, so it is treated as the original; first seen 2026-08-31.