Back
Web Fundamentals

Authorization Best Practices

Web Fundamentals
Build & Deployment: Monorepo, CI/CD, Strategies & Release SafetyState Management: Choosing the Right SolutionRedux: Predictable State Container (RTK + RTK Query)React Query (TanStack Query): Server State CachingData Fetching Patterns: REST, GraphQL, tRPC & Real-timeGraphQL Fundamentals for Frontend: Shape, Caching, and TradeoffsgRPC-Web Fundamentals: Browser Constraints and Proxy ModelCaching Strategies: Client, Server & EdgeData Normalization: Organizing State for PerformanceAPI Design Best Practices: Pagination, Errors, Versioning & Type SafetyAPI Versioning Strategies for Frontend CompatibilityPagination: Offset vs Cursor-BasedRate Limiting & API Resilience: Retries, Backoff, Jitter, IdempotencyHow Frontend Developers Can Handle Millions of API Requests Without Crashing EverythingBrowser Storage: Cookies, SessionStorage, LocalStorage, IndexedDBReal-time Communication: WebSockets, SSE & PollingWebRTC: Real-Time Communication in the BrowserCore Web Vitals: LCP, INP & CLSPerformance Optimization Trade-offsCritical Resource Prioritization: Optimize Loading OrderCode Splitting: Optimize Bundle Size with Dynamic ImportsTree Shaking: Eliminate Dead Code from Your BundleLazy Loading: Load Resources On-DemandResource Hints: Preload, Prefetch & PreconnectText Compression: Gzip and BrotliImage & Video Optimization: Modern Formats & TechniquesAdaptive Loading: Optimize for Device & NetworkList Virtualization: Render Large Lists EfficientlyWeb Workers vs Main Thread: Offloading Heavy WorkMemory Leaks in Frontend Apps: Detection & PreventionManaging Third-Party Scripts: Optimization StrategiesHow CDNs Work: Edge Delivery, Caching & PerformanceHTTP Caching Deep Dive: Cache-Control, ETag & RevalidationService Workers & Offline Strategy: Cache First, Network First & Update LifecyclePWA Fundamentals: Manifest, Installability & Offline UXCritical Rendering PathScript Loading: async vs deferEvent Loop: Understanding JavaScript Execution ModelJavaScript Module Systems: CJS vs ESM vs UMDDynamic Module Loading: import() FunctionImport on Interaction: Load When User InteractsImport on Visibility: Lazy Loading with IntersectionObserverBrowser Rendering Pipeline & Layout ThrashingRendering Strategies: CSR vs SSR vs SSG vs ISRStreaming SSR: Progressive HTML StreamingIslands Architecture: Independent Component HydrationReact Server Components: Zero-JS Server RenderingFramework Reactivity: React, Vue, Svelte & SolidHTTP/1.1 vs HTTP/2 vs HTTP/3 (QUIC) for Frontend PerformanceDNS Resolution: Path, TTL, Caching & Frontend ImpactCross-Site Scripting (XSS) AttacksCross-Site Request Forgery (CSRF) AttacksCORS Explained: Cross-Origin Resource SharingCORS Preflight in Practice: Credentials, Simple Requests & MisconfigurationsContent Security Policy (CSP)Why is HTTPS Secure? Understanding TLS/SSLAuthorization Best PracticesCookie Security & Session Hardening: SameSite, HttpOnly, Secure
easySecurity

Authorization Best Practices

TL;DRAuthenticated ≠ Authorized. Always enforce permissions on the server using RBAC + resource ownership checks.
High Signal
Google
Meta
Netflix
Agoda
30-Second Answerstart every interview with this

Authorization controls what authenticated users are allowed to do. Proper authorization prevents privilege escalation and data leaks. Key principles: least privilege, server-side enforcement, and combining role-based access with resource ownership checks.

Authentication is showing your ID to get in. Authorization is the bouncer checking whether you have a VIP wristband for the VIP area. Even if you're in the club (authenticated), you shouldn't access areas you're not allowed (unauthorized).

User is Authenticated (has valid session)
Request reaches protected endpoint
Server checks permissions (role + ownership)
Allowed → Process | Denied → 403 Forbidden

1Principle of Least Privilege

Users and systems should have the minimum permissions necessary to perform their tasks. This limits damage if credentials are compromised.

2Role-Based Access Control (RBAC)

Map users to roles, and roles to permissions. Simple and effective for most applications.

auth.jsjs
const roles = {
  admin: ['read', 'write', 'delete'],
  editor: ['read', 'write'],
  viewer: ['read']
};

function can(user, action) {
  return roles[user.role]?.includes(action);
}

3Resource Ownership Checks

For user-owned resources (posts, profiles, orders), always verify the requesting user owns the resource in addition to role checks.

PropertyAuthenticationAuthorization
CheckSession / JWT validationRole + ownership verification
ExampleLogin with email/passwordCan this user delete this post?
PurposeWho are you?What are you allowed to do?

Authentication

Check

Session / JWT validation

Example

Login with email/password

Purpose

Who are you?

Authorization

Check

Role + ownership verification

Example

Can this user delete this post?

Purpose

What are you allowed to do?

Common questions

  • ›“What is the difference between authentication and authorization?”
  • ›“How do you implement authorization in a web app?”
  • ›“Explain the principle of least privilege.”
  • ›“How do you protect against unauthorized access to user resources?”

What interviewers look for

  • Clear distinction between authn and authz
  • Server-side enforcement mindset
  • Understanding of RBAC and ownership checks
  • Defense-in-depth thinking (middleware, validation)

Short answer (60 sec)

Authentication verifies identity. Authorization verifies permissions. Always enforce authorization server-side using role checks and resource ownership validation. Follow the principle of least privilege.

Detailed answer (senior level)

Authorization is separate from authentication. Use RBAC for role-based permissions and always check resource ownership for user-specific data. Implement checks in middleware or route handlers. Never trust client-side permission logic. Default to deny (fail securely) and log authorization failures.

  • Assuming authentication is enough (authenticated ≠ authorized)
  • Performing authorization checks only on the client side
  • Missing ownership checks on user resources
  • Using overly broad permissions (admin everywhere)
  • Forgetting to protect all state-changing endpoints
Key Takeaways
  • ✓Authentication = Who are you? Authorization = What can you do?
  • ✓Always enforce authorization on the server
  • ✓Follow principle of least privilege
  • ✓Combine RBAC with resource ownership checks
  • ✓Default to deny access
  • ✓Protect ALL state-changing operations
  • ✓Centralize authorization logic for maintainability
Previous TopicWhy is HTTPS Secure? Understanding TLS/SSLNext Topic Cookie Security & Session Hardening: SameSite, HttpOnly, Secure

On this page