Role-based, claims-based, policy-based and resource-based authorisation, custom authorisation handlers and permission-based authorisation in ASP.NET Core.
-
How would you return a ProblemDetails response with a safe reason when authorisation fails, instead of a bare 403?
Mid-Level
Coding
Authorization
-
How does role-based authorisation work in ASP.NET Core? Explain [Authorize(Roles = ...)] and RequireRole, how ASP.NET Core decides which claim is a role, how you combine roles with AND and OR, and where role-based authorisation stops scaling.
Role-based authorisation in ASP.NET Core: [Authorize(Roles)], RequireRole on policies and Minimal APIs, the role claim type and Entra app roles, AND vs OR semantics, and the role explosion problem.
Junior
Theory
Authorization
Β· π 2 follow-ups
-
What are claims-based and policy-based authorisation in ASP.NET Core? Explain policies, requirements and handlers, how RequireAuthorization works on Minimal API endpoints and route groups, and the difference between the default policy and the fallback policy.
Policy-based authorisation in ASP.NET Core: AuthorizationPolicy, requirements and handlers, RequireClaim and RequireAssertion, AND/OR evaluation, RequireAuthorization on Minimal APIs and groups, AllowAnonymous, and DefaultPolicy vs FallbackPolicy.
Intermediate
Theory
Authorization
Β· π 2 follow-ups
-
Write a custom authorisation handler in ASP.NET Core. Show a requirement and an AuthorizationHandler that uses a DI service, explain how multiple handlers for the same requirement combine, when to call Succeed versus Fail, and how you register and test the handler.
Custom authorisation in ASP.NET Core: IAuthorizationRequirement, AuthorizationHandler<T> with injected services, handler lifetimes, OR semantics across handlers and Fail as a veto, IAuthorizationRequirementData attributes, failure reasons and unit testing.
Mid-Level
Coding
Authorization
Β· π 2 follow-ups Β· π 1 real-world
-
Show how you implement resource-based authorisation in ASP.NET Core, for example 'only the document's owner or an editor in the same team may edit it'. Why can't a policy on the endpoint do this alone, and how do you use IAuthorizationService.AuthorizeAsync with the loaded resource?
Resource-based authorisation: why endpoint policies can't see the record, AuthorizationHandler<TRequirement, TResource>, OperationAuthorizationRequirement, calling IAuthorizationService.AuthorizeAsync after loading, 403 vs 404, and filtering lists in the query.
Mid-Level
Coding
Authorization
Β· π 2 follow-ups Β· π 1 real-world
-
Your ASP.NET Core API seems to ignore [Authorize]: some endpoints return data to anonymous callers, others return 401 when you expect 403, and a policy on a Minimal API route group doesn't seem to apply. How do you diagnose and fix it?
Diagnosing authorisation that seems ignored: middleware order (UseRouting, UseAuthentication, UseAuthorization), endpoint metadata, AllowAnonymous precedence, missing default scheme, 401 vs 403 and cookie redirects, group metadata and authorisation debug logs.
Mid-Level
Debugging
Authorization
Β· π 3 follow-ups Β· π 1 real-world
-
A penetration test finds broken object-level authorisation (IDOR) in your API: changing the order id in GET /api/orders/{id} returns another customer's order. How do you fix this one endpoint, and how do you make sure the same flaw doesn't exist anywhere else in the codebase?
Broken object-level authorisation (OWASP API1:2023, IDOR): vulnerable code and exploit, ownership in the query, resource-based authorisation, tenant query filters and RLS, opaque ids, finding every affected endpoint, cross-user tests, logging enumeration, and NDB assessment.
Senior
Security
Authorization
Β· π 2 follow-ups Β· π 1 real-world
-
Design permission-based authorisation for a large multi-tenant SaaS product where customers define their own roles. Would you put permissions in the access token or look them up per request? How do you cache them, keep them fresh when an admin changes a role, and express them as ASP.NET Core policies without registering hundreds of them?
Permission-based authorisation architecture: permissions vs roles, tenant-defined roles, token size and staleness vs per-request lookup, caching and invalidation, a dynamic IAuthorizationPolicyProvider with one generic handler, auditing and when to adopt an external engine (Zanzibar-style, OPA).
Senior
Architecture
Authorization
Β· π 3 follow-ups Β· π 1 real-world
-
Code review: an ASP.NET Core controller for invoices has authorisation enforced only by hiding buttons in the React UI, role strings like "Admin" and "FinanceManager" repeated in attributes, [AllowAnonymous] on the controller 'for the health check', and an Approve action that takes the approver's user id from the request body. What do you flag, in what order, and what does the fixed version look like?
Code review of authorisation: controller-level AllowAnonymous, UI-only checks, missing resource and tenant checks, user id from the request body, scattered role strings, and the rewrite with policies, resource-based authorisation, claims-derived identity, fallback policy and tests.
Senior
CodeReview
Authorization
Β· π 3 follow-ups Β· π 1 real-world