ترويسات الأمان وHTTPS
اضبط ترويسات تمنع الهجمات الشائعة.
ترويسات الأمان وHTTPS درس مجاني في Flask Academy على CoddyKit. هذا هو الدرس 3 من أصل 4. يمكنك قراءة الدرس كاملاً أدناه مجاناً — ثم تمرن عليه مباشرة في المتصفح باستخدام محرر أكواد مدمج ومدرس ذكاء اصطناعي متاح 24/7. هذا الدرس جزء من مسار التعلم في Flask Academy، وتقدمك يتزامن عبر الويب وتطبيق CoddyKit. تتضمن دورة Flask Academy 4 دروس في المجموع.
بعض أجزاء هذا الدرس لم تُترجم بعد وتظهر باللغة الإنجليزية.
Headers as a First Defense
A few response headers tell the browser how to behave safely. They are cheap to add and block whole classes of attacks.
Why HTTPS Is Non-Negotiable
Over plain HTTP, anyone on the path can read or change traffic. HTTPS encrypts it so passwords and tokens stay private.
Force HTTPS with HSTS
The Strict-Transport-Security header tells browsers to always use HTTPS for your domain, even if a user types http.
resp.headers["Strict-Transport-Security"] = "max-age=31536000"Stop MIME Sniffing
Browsers sometimes guess a file type and run it. X-Content-Type-Options: nosniff tells them to trust your declared type instead.
resp.headers["X-Content-Type-Options"] = "nosniff"Block Clickjacking
Attackers can hide your site in an invisible frame. X-Frame-Options: DENY stops your pages from being framed at all.
resp.headers["X-Frame-Options"] = "DENY"Content Security Policy
A Content-Security-Policy limits where scripts and styles may load from. It is the strongest single guard against injected scripts.
resp.headers["Content-Security-Policy"] = "default-src 'self'"Add Headers Everywhere
You set these on every response in one place. An after_request hook stamps the headers so you never forget a route.
@app.after_request
def secure(resp):
resp.headers["X-Frame-Options"] = "DENY"
return respLet a Library Help
Doing it by hand is error prone, so many teams reach for Flask-Talisman. It sets sensible security headers for you.
from flask_talisman import Talisman
Talisman(app)Mark Cookies Secure
Tell the browser to send cookies only over HTTPS with the Secure flag, and hide them from scripts with HttpOnly.
app.config["SESSION_COOKIE_SECURE"] = TrueHide Your Server Banner
Default error pages can leak versions. Trimming the Server header gives attackers one less hint about your stack.
Terminate TLS at the Edge
In production a proxy like Nginx usually handles the certificate. Flask trusts it via ProxyFix to read the real scheme and IP.
Quick Check
Identify the header that forces secure transport.
Recap
You enabled HTTPS, added HSTS, nosniff, frame, and CSP headers, secured cookies, and let Talisman help. You hardened the edge nicely!
الأسئلة الشائعة
هل درس «ترويسات الأمان وHTTPS» مجاني؟
نعم — نص درس «ترويسات الأمان وHTTPS» كامل متاح مجاناً هنا على الويب. لتمرينه بشكل تفاعلي (محرر أكواد مدمج ومدرس ذكاء اصطناعي متاح 24/7) وفتح باقي دورة Flask Academy، انتقل إلى CoddyKit PRO. تتضمن دورة Flask Academy 4 دروس في المجموع.
ماذا ستتعلم في «ترويسات الأمان وHTTPS»؟
اضبط ترويسات تمنع الهجمات الشائعة. تتمرن على Flask Academy مع أكواد عملية تشغلها مباشرة في المتصفح، ومدرس ذكاء اصطناعي متاح 24/7 يجيب على أسئلتك أثناء عملك.
هل أحتاج إلى خبرة سابقة لأبدأ Flask Academy؟
لا تُشترط خبرة سابقة. Flask Academy على CoddyKit منظم للمبتدئين حتى المتقدمين، لذا يمكنك البدء من هنا أو من البداية والتقدم بسرعتك الخاصة. هذا هو الدرس 3 من أصل 4.
كم من الوقت يستغرق درس «ترويسات الأمان وHTTPS»؟
معظم دروس CoddyKit تستغرق حوالي 5–10 دقائق. كل منها موجز وتفاعلي، لذا تحرز تقدماً مستمراً وتستأنف من حيث توقفت عبر الويب والتطبيق.
هل يمكنني كتابة وتشغيل أكواد في درس Flask Academy هذا؟
نعم. كل درس في Flask Academy يتضمن محرر أكواد مدمج، لذا تكتب وتشغل أكواداً حقيقية مباشرة في متصفحك وتحصل على تعليقات فورية من الذكاء الاصطناعي — بدون إعداد محلي.
جميع الدروس في هذه الدورة
- تقييد الطلبات باستخدام Flask-Limiter
- ضبط CORS لعملاء المتصفح
- ترويسات الأمان وHTTPS
- التحقق من الإدخال لمنع الحقن