IConfiguration vs IOptions NET
Synchronous and Asynchronous in .NET Core
Model Binding and Validation in ASP.NET Core
ControllerBase vs Controller in ASP.NET Core
ConfigureServices and Configure methods
IHostedService interface in .NET Core
ASP.NET Core request processing
| Amdahls Law | Session vs Token-Based Authentication | |
CORS and CSRF |
CORS is a browser security mechanism that controls how web pages can request resources from a different origin (domain, protocol, or port) than the one that served the page. It builds on the Same-Origin Policy (SOP), which by default blocks cross-origin requests for security reasons.
Without CORS, a malicious site could freely make requests to another site where you’re logged in and read sensitive data. CORS allows servers to explicitly declare which origins are allowed to access their resources.
Access-Control-Allow-Origin: https://example.comAccess-Control-Allow-Methods: GET, POSTAccess-Control-Allow-Headers: Content-Typeapplication/x-www-form-urlencoded), HEAD.OPTIONS request first to check if the actual request is allowed.If your React app runs on http://localhost:3000 and your API is on http://localhost:5000, without CORS enabled on the API, the browser will block the request.
[Browser] -- Request --> [Server] [Server] -- Access-Control-Allow-* headers --> [Browser] [Browser] -- Allows or blocks response based on headers
Access-Control-Allow-Origin: * for sensitive endpoints.CSRF is an attack where a malicious site tricks a logged-in user’s browser into sending unwanted requests to a trusted site where the user is authenticated.
Browsers automatically include cookies (session IDs) with requests to the target site, so the malicious request is executed with the victim’s privileges — potentially changing passwords, transferring funds, or deleting data.
bank.com and gets a session cookie.evil.com.evil.com contains hidden code that sends a request to bank.com.[User] -- Login --> [Trusted Site] -- Set Cookie --> [Browser] [User] -- Visit --> [Malicious Site] [Malicious Site] -- Hidden Request --> [Trusted Site] [Trusted Site] -- Executes action using user's session
<img src="https://bank.com/transfer?amount=5000&to=attacker" />
SameSite=Strict or Lax to prevent cross-site sending.Origin or Referer headers for trusted domains.| Aspect | CORS | CSRF |
|---|---|---|
| Type | Browser security feature | Security vulnerability/attack |
| Purpose | Controls cross-origin resource access | Exploits authenticated user’s session |
| Who Configures | Server sets allowed origins | Developer implements protections |
| Focus | Protects data from being read by unauthorized origins | Prevents unauthorized actions on behalf of a user |
| Amdahls Law | Session vs Token-Based Authentication | |