Cookie

الكوكي (Cookie)

GLS-000103

Beginnerauth-security1 min read
http cookiebrowser cookiesession cookiesecure cookiehttponly cookie

Definition

A small piece of data stored in the browser that is automatically sent to the server with every request.

قطعة صغيرة من البيانات مخزّنة في المتصفح تُرسَل تلقائيًا إلى الخادم مع كل طلب.

Why It Matters

Firebase Admin SDK in Next.js Middleware reads a session cookie to verify the user on every server-rendered page request.

Firebase Admin SDK في Next.js Middleware يقرأ كوكي الجلسة للتحقق من المستخدم في كل طلب صفحة مُصيَّرة من الخادم.

Full Definition

Cookies are key-value pairs stored by the browser and attached to every HTTP request to the matching domain. They're used for sessions, authentication tokens, and user preferences. Security flags: HttpOnly (JavaScript can't read it), Secure (HTTPS only), SameSite (controls cross-site sending). Server-side cookies are safer than localStorage for auth tokens.
الكوكيز هي أزواج مفتاح-قيمة يخزّنها المتصفح وتُرفق بكل طلب HTTP للنطاق المطابق. تُستخدم للجلسات ورموز المصادقة وتفضيلات المستخدم. علامات الأمان: HttpOnly (JavaScript لا يمكنه قراءتها) وSecure (HTTPS فقط) وSameSite (يتحكم في الإرسال عبر المواقع). الكوكيز من جانب الخادم أكثر أمانًا من localStorage لرموز المصادقة.

Example Usage

After login, 404Fault sets a secure HttpOnly cookie containing the Firebase ID token. Middleware reads this cookie to check auth on every request.

بعد تسجيل الدخول، يضع 404Fault كوكي آمنًا HttpOnly يحتوي على رمز Firebase ID. Middleware يقرأ هذا الكوكي للتحقق من المصادقة في كل طلب.

Knowledge Graph

Avoid these mistakes when using Cookie:

1

Storing auth tokens in localStorage (vulnerable to XSS)

2

Missing SameSite=Strict or Lax on auth cookies (enables CSRF)

Sign in to unlock guided AI explanations from AI Teacher.

Generate a Prompt

Copy this prompt and use it directly with any AI model — no setup needed.

Ready-to-Use Prompt
Help me build a project using Cookie.

Explain:
1. What is Cookie and why it matters
2. The core architecture and required tools
3. Step-by-step implementation plan
4. Common mistakes to avoid: Storing auth tokens in localStorage (vulnerable to XSS), Missing SameSite=Strict or Lax on auth cookies (enables CSRF)
5. Best practices and production tips

Official Resources