Skip to content

C#: Add EF Core interpolated SQL methods as SQL injection sanitizers#21

Open
mrigankpawagi wants to merge 1 commit into
mainfrom
improve-csharp-sql-ef-interpolated
Open

C#: Add EF Core interpolated SQL methods as SQL injection sanitizers#21
mrigankpawagi wants to merge 1 commit into
mainfrom
improve-csharp-sql-ef-interpolated

Conversation

@mrigankpawagi

Copy link
Copy Markdown
Owner

Fix

Adds Entity Framework Core's FromSqlInterpolated, ExecuteSqlInterpolated, and ExecuteSqlInterpolatedAsync methods as sanitizers for the cs/sql-injection query.

Problem

EF Core's interpolated SQL methods (FromSqlInterpolated, etc.) accept FormattableString parameters and automatically parameterize interpolated values. Despite using C# string interpolation syntax ($"SELECT * FROM Users WHERE Id = {id}"), these methods are NOT vulnerable to SQL injection because EF Core extracts interpolated values as SQL parameters. The query incorrectly flags these as injection vulnerabilities.

Validation

This is documented EF Core behavior: https://learn.microsoft.com/en-us/ef/core/querying/sql-queries#passing-parameters. The FormattableString overload ensures values are parameterized.

Entity Framework Core's FromSqlInterpolated, ExecuteSqlInterpolated,
and ExecuteSqlInterpolatedAsync methods properly parameterize
interpolated string values. Arguments to these methods should not be
flagged as SQL injection sinks since EF Core handles parameterization
automatically.
@github-actions github-actions Bot added the C# label Jun 23, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants