Skip to content

Add securing-aspnetcore-apis skill (+7.0% eval, near-miss) - #92

Closed
mrsharm wants to merge 2 commits into
dotnet:mainfrom
mrsharm:musharm/securing-aspnetcore-apis-skill
Closed

Add securing-aspnetcore-apis skill (+7.0% eval, near-miss)#92
mrsharm wants to merge 2 commits into
dotnet:mainfrom
mrsharm:musharm/securing-aspnetcore-apis-skill

Conversation

@mrsharm

@mrsharm mrsharm commented Feb 23, 2026

Copy link
Copy Markdown
Member

Summary

Adds the securing-aspnetcore-apis skill for securing ASP.NET Core APIs with auth, CORS, and rate limiting.

Eval Results

Metric Score
Overall Improvement +7.0%
Threshold 10%
Result Near-miss (3.0% below threshold)

What the Skill Teaches

  • JWT bearer auth with proper TokenValidationParameters (don't disable validation!)
  • CORS configuration with specific origins (not AllowAnyOrigin with credentials)
  • Critical middleware ordering: UseCors -> UseAuthentication -> UseAuthorization -> UseRateLimiter
  • Rate limiting with fixed/sliding window policies
  • Common security misconfigurations that compile but silently bypass auth

Files

  • src/dotnet/skills/securing-aspnetcore-apis/SKILL.md
  • src/dotnet/tests/securing-aspnetcore-apis/eval.yaml

Teaches ASP.NET Core API security: JWT bearer auth with proper
TokenValidationParameters, CORS configuration (avoiding AllowAnyOrigin),
critical middleware ordering, and rate limiting setup.

Eval results: +7.0% improvement (threshold: 10%, near-miss)
Includes eval.yaml with security setup scenario + negative test.
Copilot AI review requested due to automatic review settings February 23, 2026 14:55

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot encountered an error and was unable to review this pull request. You can try again by re-requesting a review.

app.MapPost("/api/auth/login", Login).AllowAnonymous();
```

### Step 4: Configure CORS correctly

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

- Implementing rate limiting to prevent abuse
- Fixing security misconfigurations

## When Not to Use

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The skill is about multiple different security related concepts, some of which likely still apply to the items in this 'Not' section.

**NEVER do this in production:**
```csharp
// INSECURE — allows any origin to call your API
policy.AllowAnyOrigin().AllowAnyMethod().AllowAnyHeader();

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Another insecure pattern is policy.SetIsOriginAllowed(origin => return true)

// Global limiter
options.GlobalLimiter = PartitionedRateLimiter.Create<HttpContext, string>(
context => RateLimitPartition.GetFixedWindowLimiter(
partitionKey: context.User?.Identity?.Name ?? context.Connection.RemoteIpAddress?.ToString() ?? "anonymous",

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Consider different partitions for anonymous vs. authenticated users.

@@ -0,0 +1,47 @@
scenarios:

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I assume there will be more scenarios in the future, this is just a good first start?


### Step 2: Configure middleware in the CORRECT order

**Middleware order is critical. Wrong order = auth bypassed silently.**

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we refer to https://learn.microsoft.com/aspnet/core/fundamentals/middleware/?view=aspnetcore-10.0#middleware-order so we don't need to maintain an explicit list here? Or add it as an extra resource to check if needed?

@mrsharm

mrsharm commented Feb 25, 2026

Copy link
Copy Markdown
Member Author

Skill Validation Results — securing-aspnetcore-apis

Skill Test Baseline With Skill Δ Verdict
securing-aspnetcore-apis Fix CORS preflight 401 with JWT auth middleware ordering 5.0/5 5.0/5 0.0
securing-aspnetcore-apis Security skill should not activate for internal service question 5.0/5 5.0/5 0.0

Overall improvement: -19.8% (1 run)

The model already scores 5/5 on the baseline across all scenarios — the skill provides no marginal quality improvement and adds token/time overhead that the pairwise judge penalizes. Recommend closing this PR as the model's existing knowledge is sufficient for these security scenarios.

Model: claude-opus-4.6 | Judge: claude-opus-4.6

1 similar comment
@mrsharm

mrsharm commented Feb 25, 2026

Copy link
Copy Markdown
Member Author

Skill Validation Results — securing-aspnetcore-apis

Skill Test Baseline With Skill Δ Verdict
securing-aspnetcore-apis Fix CORS preflight 401 with JWT auth middleware ordering 5.0/5 5.0/5 0.0
securing-aspnetcore-apis Security skill should not activate for internal service question 5.0/5 5.0/5 0.0

Overall improvement: -19.8% (1 run)

The model already scores 5/5 on the baseline across all scenarios — the skill provides no marginal quality improvement and adds token/time overhead that the pairwise judge penalizes. Recommend closing this PR as the model's existing knowledge is sufficient for these security scenarios.

Model: claude-opus-4.6 | Judge: claude-opus-4.6

@mrsharm

mrsharm commented Feb 25, 2026

Copy link
Copy Markdown
Member Author

Closing since this is a futile experiment with a low score on the evals. CC: @BrennanConroy et al., please feel free to take the contents here and reuse for a new skill but the skill as it is isn't scoring as well as I hoped.

@mrsharm mrsharm closed this Feb 25, 2026
moesac0970 pushed a commit to moesac0970/skills that referenced this pull request Jul 4, 2026
… - VSTest-preserving path confirmed, Workforce status noted
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants