Node.js / NestJS

Security Best Practices

Helmet, CORS, rate limiting, input sanitization, SQL injection, XSS, CSRF

25 perguntas de entrevistaยท
Senior
1

What is Helmet in the context of NestJS?

Resposta

Helmet is middleware that automatically configures HTTP security headers to protect applications against common vulnerabilities. It enables headers like X-Frame-Options, Content-Security-Policy, X-Content-Type-Options to prevent XSS, clickjacking, and MIME sniffing. Helmet is an essential production best practice to strengthen the security surface.

2

What is the main role of CORS in an API?

Resposta

CORS (Cross-Origin Resource Sharing) controls which external domains can access API resources. Without CORS configuration, browsers block requests from different domains for security reasons. Properly configuring CORS prevents access errors while maintaining security. Use whitelists of allowed origins rather than allowing all domains with wildcard.

3

What is the best approach to protect an API against brute force attacks?

Resposta

Rate limiting restricts the number of requests per IP or user over a given period, preventing automated brute force attacks. Packages like throttler-module in NestJS easily configure global or per-endpoint limits. Combine rate limiting with progressive strategies (increasing temporary blocking) and CAPTCHA for sensitive endpoints. Rate limiting also protects against denial of service.

4

What is an XSS (Cross-Site Scripting) attack?

5

How to protect a NestJS application against SQL injection?

+22 perguntas de entrevista

Domine Node.js / NestJS para sua proxima entrevista

Acesse todas as perguntas, flashcards, testes tecnicos, exercicios de code review e simuladores de entrevista.

Comece gratis