Skip to content
Guest
Cybersecurity · Course Syllabus Show lessons
Infrastructure & Ops · 8 min read · Intermediate

CORS Policies & Safe Error Handling

Configure Cross-Origin Resource Sharing safely and stop leaking stack traces to attackers.

What you'll learn

  • Understand how browser CORS preflight (`OPTIONS`) checks work
  • Prevent user enumeration on login and password-reset endpoints
  • Hide internal stack traces and SQL errors in production responses

Overview

Configure Cross-Origin Resource Sharing safely and stop leaking stack traces to attackers.

Code Example

Safe API Error Handling:
- Return generic client messages: { "error": "Invalid email or password." }
- Log full stack traces ONLY to private server logs (journald / Sentry)
- Never combine Access-Control-Allow-Origin: * with Access-Control-Allow-Credentials: true

Key Takeaways

  • Understand how browser CORS preflight (OPTIONS) checks work
  • Prevent user enumeration on login and password-reset endpoints
  • Hide internal stack traces and SQL errors in production responses

Quick Check

Check Your Understanding

Score: 0 / 1

1. Why should a login endpoint return `Invalid email or password` instead of `Email not found`?

Study Workspace

Finished this lesson?

Your progress is saved locally in your browser, no account needed.

Search courses, lessons, and references

Type to search across all courses, lessons, and quick references.

Press Esc to close Powered by Pagefind