Skip to content
Open
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
32 changes: 32 additions & 0 deletions INjectionTest.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
using Microsoft.AspNetCore.Mvc;
using Microsoft.EntityFrameworkCore;
using WebApplication1.Controllers;

namespace WebApplicationDotNetCore.Controllers
{
public class RSPEC3649SQLiNoncompliant : Controller
{
private readonly UserAccountContext _context;

public RSPEC3649SQLiNoncompliant(UserAccountContext context)
{
_context = context;
}

public IActionResult Authenticate(string user)
{
string query = "SELECT * FROM Users WHERE Username = '" + user + "'";

// an attacker can bypass authentication by setting user to this special value
// user = "' or 1=1 or ''='";

var userExists = false;
if (_context.Database.ExecuteSqlCommand(query) > 0) // Noncompliant
{
userExists = true;
}

return Content(userExists ? "success" : "fail");
}
}
}