Node.js / NestJS

Security Best Practices

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

25 питань зі співбесід·
Senior
1

What is Helmet in the context of NestJS?

Відповідь

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?

Відповідь

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?

Відповідь

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 питань зі співбесід

Опануй Node.js / NestJS для наступної співбесіди

Отримай доступ до всіх питань, flashcards, технічних тестів, вправ code review та симуляторів співбесід.

Почни безкоштовно