Thuta Learning
How the Web Works
IntermediateWeb Developmentbeginner

Web Security အခြေခံများ

ဒီခန်းပြီးရင် ဘာတတ်သွားမလဲ

  • Web Security အခြေခံများ concept ကို နားလည်ရှင်းပြနိုင်ရန်
  • Diagram ကို ဖတ်ပြီး request/data/event ဘယ်လိုစီးဆင်းသလဲ ခြေရာခံနိုင်ရန်
  • ဒီ piece က web architecture တစ်ခုလုံးထဲမှာ ဘယ်လို ဆက်စပ်နေသလဲ ရှင်းပြနိုင်ရန်

နားလည်ထားရမယ့် အချက်

browser သည် same-origin policy ကို ကျင့်သုံးသည် - origin ဆိုသည်မှာ scheme + host + port ဖြစ်ပြီး ဤ နယ်နိမိတ်သည် CORS ၏ အခြေခံ ဖြစ်သည်။

CORS သည် server က cross-origin request ကို ခွင့်ပြုစေသည့် mechanism ဖြစ်သည်။ CORS ≠ authentication, CORS ≠ authorization - browser access ကိုသာ ထိန်းချုပ်သည်။

XSS (ကာကွယ်ရေးအဆင့်): untrusted input ကို executable code ဘယ်တော့မှ မဖြစ်စေပါနှင့်၊ framework output escaping နှင့် CSP ကို အားကိုးပါ။

CSRF (ကာကွယ်ရေးအဆင့်): browser သည် cookie ကို အလိုအလျောက် ပူးတွဲနိုင်သောကြောင့် SameSite, CSRF token, origin စစ်ဆေးခြင်းတို့ ကာကွယ်ပေးသည်။

  • HTTPS
  • Authentication
  • Authorization (action အလိုက်)
  • Input validation / Output safety
  • Secure cookies / Server-side secrets
  • CORS configuration
  • Dependency hygiene / Monitoring
text
WEB SECURITY: LAYERS THAT WORK TOGETHER
---------------------------------------
WEB SECURITY: LAYERS THAT WORK TOGETHER
------------------------------------------

  +---------------------------------------+
  |   HTTPS (encrypts the transport)       |
  +---------------------------------------+
  |   Authentication (who are you)         |
  +---------------------------------------+
  |   Authorization (what can you do)      |
  +---------------------------------------+
  |   Input Validation / Output Safety     |
  +---------------------------------------+
  |   Secure Cookies / Server-Side Secrets |
  +---------------------------------------+
  |   CORS Configuration                   |
  +---------------------------------------+
  |   Dependency Hygiene / Monitoring      |
  +---------------------------------------+

  Removing any one layer weakens the whole stack.

လက်တွေ့ scenario နဲ့ ချိတ်ကြည့်မယ်

server သည် ယုံကြည်ရသော origin allow-list ထိန်းသိမ်းပြီး request တိုင်း၏ origin ကို ၎င်းနှင့် နှိုင်းယှဉ်ပြီးမှ allow/deny ဆုံးဖြတ်သည်။

ဤသည်ကို production CORS အဖြစ် မယူဘဲ mental model စတင်ချက်အဖြစ်သာ ယူပါ - CORS အစစ်တွင် preflight, credential, header များစွာ ပါဝင်သည်။

Web Security Foundations Checklist

အတူတူ စမ်းရေးကြည့်မယ်

javascript
function checkCors(requestOrigin, allowedOrigins) {
  const allowed = allowedOrigins.includes(requestOrigin);
  return {
    origin: requestOrigin,
    decision: allowed ? "allow" : "deny",
  };
}

const allowedOrigins = ["https://app.example.com", "https://admin.example.com"];

console.log(checkCors("https://app.example.com", allowedOrigins));
console.log(checkCors("https://evil-site.com", allowedOrigins));
You should see
{ origin: 'https://app.example.com', decision: 'allow' } နှင့် { origin: 'https://evil-site.com', decision: 'deny' } ကို log ထုတ်သည်။

၅ မိနစ် စမ်းကြည့်

code ထဲရှိ allowedOrigins list ထဲသို့ သင့်ကိုယ်ပိုင် site ၏ origin ကို ထပ်ထည့်ပြီး checkCors က ၎င်းအတွက် 'allow' ပြန်ပေးကြောင်း အတည်ပြုပါ။

သတိလေးတစ်ချက်

CORS configure ထားခြင်းသည် request များ authenticate/authorize ဖြစ်ကြောင်းဟု ယူဆခြင်း - ၎င်းသည် cross-origin browser access ကိုသာ ထိန်းချုပ်သည်။

တိတိကျကျ allow-list ထိန်းသိမ်းမည့်အစား CORS ကို origin မည်သည့်ဆိုက်ကိုမဆို ခွင့်ပြုအောင် ဖွင့်ထားခြင်း။

OWASP - Top Ten Web Application Security RisksHow the Web Works

ဒီနေရာမှာ လူအများမှားတတ်တယ်

  • CORS configure ထားခြင်းသည် request များ authenticate/authorize ဖြစ်ကြောင်းဟု ယူဆခြင်း - ၎င်းသည် cross-origin browser access ကိုသာ ထိန်းချုပ်သည်။
  • တိတိကျကျ allow-list ထိန်းသိမ်းမည့်အစား CORS ကို origin မည်သည့်ဆိုက်ကိုမဆို ခွင့်ပြုအောင် ဖွင့်ထားခြင်း။
  • ဒီ course က system map တစ်ခုပါ — REST/DNS/Database/Security ကို နက်နက်ရှိုင်းရှိုင်း လေ့လာချင်ရင် API Tutorial, Cloud & Deployment, SQL, Cybersecurity tutorial တွေဆီ ဆက်သွားပါ။

လေ့ကျင့်ခန်း

code ထဲရှိ allowedOrigins list ထဲသို့ သင့်ကိုယ်ပိုင် site ၏ origin ကို ထပ်ထည့်ပြီး checkCors က ၎င်းအတွက် 'allow' ပြန်ပေးကြောင်း အတည်ပြုပါ။

You'll know it worked when: { origin: 'https://app.example.com', decision: 'allow' } နှင့် { origin: 'https://evil-site.com', decision: 'deny' } ကို log ထုတ်သည်။