--- name: security-checklist description: Security review checklist for an ASP.NET Core application. Use when asked to review code, a repository or a change for security vulnerabilities. --- # Security review checklist (ASP.NET Core, EF Core) Work through all of it. A weakness counts only when you can say who the attacker is, what they send, and what they get. ## Method 1. Read `Program.cs` and every file that maps a route or renders a page before judging any of them. Read the project files and every `appsettings*.json`. 2. For every input a caller controls (route value, query string, body, header, cookie, file, URL), follow it to where it is used. The places that matter: a database query, the file system, an outbound request, HTML output, a redirect, a log line, an object that is saved. 3. For every route and page, answer from the code: who may call this, and whose data does it touch? Check the answer against what the feature is for. 4. Before reporting, confirm the value really comes from a caller and really reaches the dangerous place. Code that only looks alarming (a parameterised query, a constant string, a checksum, a made-up test value) is not a finding. ## What to check - Access control: an endpoint with no authorization requirement; a role check that is missing; a record fetched by id without checking that it belongs to the caller; admin functions reachable by ordinary users; a request body bound to an entity so the caller can set fields such as role, owner or id. - Authentication and sessions: how passwords are stored and compared; token validation settings (signature, issuer, audience, lifetime); cookie flags (HttpOnly, Secure, SameSite); limits on repeated login or reset attempts; tokens for reset or invitation that can be guessed, reused or never expire; answers that reveal whether an account exists. - Injection: SQL built from strings (`FromSqlRaw`, `ExecuteSqlRaw`, ADO.NET command text); a file path built from input; a command line built from input; stored or reflected text written into HTML without encoding (`MarkupString`, `Html.Raw`). - Requests the server makes: a URL from a caller fetched by the server, including loopback, private addresses and redirects. - Request forgery: state-changing form posts with antiforgery disabled or missing while a cookie signs the user in; CORS that reflects any origin together with credentials. - Redirects: a redirect target taken from the request without checking that it is local. - Data exposure: responses that include password hashes, tokens or internal fields; exports; error responses with exception text or stack traces outside development; secrets, passwords or tokens written to logs. - Secrets and configuration: keys, passwords or connection strings with real-looking values in source or settings files; developer features left on for every environment. - Files: uploads without limits on size and type; names from the caller used on disk; downloads by name or path. - Dependencies: run `dotnet list package --vulnerable --include-transitive` and check whether the project switches the NuGet audit off. ## Reporting One finding per weakness per place, with the file and line of the code that is wrong, how it is exploited in one or two sentences, and the fix in one sentence. Order by severity. Say nothing about style, naming or performance.