NestJS - AuthenticationWhy is it important to set the 'httpOnly' flag on session cookies in a NestJS app using session-based authentication?ATo make the cookie accessible only over HTTPSBTo prevent client-side scripts from accessing the cookie and reduce XSS riskCTo allow JavaScript to read the cookie for UI updatesDTo enable cookie sharing across different domainsCheck Answer
Step-by-Step SolutionSolution:Step 1: Understand httpOnly cookie flagThe httpOnly flag prevents JavaScript running in the browser from accessing the cookie.Step 2: Recognize security benefitsThis reduces the risk of cross-site scripting (XSS) attacks stealing session cookies.Final Answer:To prevent client-side scripts from accessing the cookie and reduce XSS risk -> Option BQuick Check:httpOnly protects cookies from JS = C [OK]Quick Trick: Set httpOnly to protect session cookies from JavaScript [OK]Common Mistakes:Thinking httpOnly allows JS accessConfusing httpOnly with secure flagAssuming it enables cross-domain sharing
Master "Authentication" in NestJS9 interactive learning modes - each teaches the same concept differentlyLearnWhyDeepVisualTryChallengeProjectRecallPerf
More NestJS Quizzes Authentication - Why authentication secures NestJS APIs - Quiz 15hard Authentication - Refresh token pattern - Quiz 6medium Database with Prisma - Schema definition - Quiz 11easy Database with Prisma - Schema definition - Quiz 10hard Database with Prisma - Prisma Client usage - Quiz 14medium Database with TypeORM - Repository pattern - Quiz 1easy Middleware - Why middleware processes requests before handlers - Quiz 2easy Pipes - Default value pipe - Quiz 12easy Pipes - Built-in pipes (ParseIntPipe, ParseBoolPipe) - Quiz 8hard Pipes - File validation pipe - Quiz 7medium