ရိုးရိုးလေး ရှင်းပြမယ်
HTTP security ကို ရိုးရိုးလေး ပြောရရင်
သင့် API ကို ခေါ်တဲ့သူတိုင်းက သင့် frontend မဟုတ်နိုင်ပါဘူး။ curl သုံးတဲ့သူ၊ script ရေးတဲ့ attacker ဒါမှမဟုတ် bug ရှိတဲ့ client တစ်ခုက ဘယ် header၊ ဘယ် field၊ ဘယ်လောက်ကြီးတဲ့ body မဆို ပို့နိုင်ပါတယ်။ HTTP security ဆိုတာ ဒီ input တွေကို တံခါးဝမှာ စစ်ပြီး ခွင့်ပြုထားတာကိုပဲ အထဲ ဝင်ခွင့်ပေးတာပါ။
အဆောက်အအုံ လုံခြုံရေးလိုပါပဲ: ဧည့်ကြိုက ID ကို စစ်ပါတယ် (authentication)၊ ပြီးတော့ အဲဒီလူ ဘယ်အထပ်ကို သွားခွင့်ရှိလဲ စစ်ပါတယ် (authorization)၊ အိတ်ကြီးကြီးတွေကိုလည်း တံခါးဝမှာပဲ ပြန်လွှတ်ပါတယ် (body limit)။
Problem → Why → Solution
ပြဿနာ: client ပို့တာကို ယုံကြည်ခြင်း
Profile update route တစ်ခုက request body တစ်ခုလုံးကို user object ထဲ ပေါင်းထည့်လိုက်ပါတယ်။ Frontend က name နဲ့ bio ကိုပဲ ပို့ပေမဲ့ attacker က { "role": "admin" } ကို ထပ်ထည့်ပို့ပြီး admin ဖြစ်သွားပါတယ်။ အဲဒီ route ကပဲ URL ထဲက id ကို စစ်မထားလို့ /users/43 လို့ ပြောင်းရုံနဲ့ တခြားလူရဲ့ profile ကို ပြင်နိုင်ပါတယ်၊ 50 MB JSON ပို့လိုက်ရင်လည်း server ရဲ့ memory ကို ပြည့်စေပါတယ်။
app.put('/users/:id', async (req, res) => {
const user = await db.users.find(req.params.id); // whose user? never checked
Object.assign(user, req.body); // role, isAdmin, balance... all writable
await db.users.save(user);
res.json(user); // may also leak passwordHash back to the client
});ဘာကြောင့် bug တစ်ခုက data ပေါက်ကြားမှု ဖြစ်သွားလဲ
ဒီ route က check သုံးခုကို ကျော်သွားပါတယ်: ဘယ် field တွေကို ခွင့်ပြုလဲ (allowlist)၊ ခေါ်တဲ့သူက ဒီ record ကို ပိုင်လား (authorization)၊ body ဘယ်လောက်ကြီးနိုင်လဲ (limit)။ Default က 'ခွင့်ပြု' ဖြစ်နေတဲ့အတွက် developer တွေ မေ့ကျန်ခဲ့တဲ့ အရာတိုင်းက security hole ဖြစ်လာပါတယ်။ Default ကို 'ငြင်း' လို့ ပြောင်းလိုက်ရင် မေ့ကျန်တာက error ဖြစ်ရုံပဲ ရှိပါတော့တယ်။
Core concept: deny by default တံခါးဝ check များ
Request တစ်ခုကို business logic မရောက်ခင် အစဉ်လိုက် စစ်ပါ။ ပထမ ဈေးအပေါဆုံး check တွေ: method နဲ့ path မှန်လား၊ Content-Type က application/json လား (မဟုတ်ရင် 415)၊ body က limit ထက် ကျော်လား (ကျော်ရင် 413)။ Body ကို stream အနေနဲ့ ဖတ်ရင်း byte ရေတွက်ပါ၊ Content-Length header ကို မယုံကြည်ရလို့ပါ — chunked upload မှာ အဲဒီ header မပါပါဘူး။
ပြီးရင် shape ကို allowlist နဲ့ စစ်ပါ: ခွင့်ပြုထားတဲ့ field စာရင်း ရှိပြီး မသိတဲ့ field ကို reject လုပ်ပါ၊ field တစ်ခုစီရဲ့ type နဲ့ အရှည်ကို စစ်ပါ (မှားရင် 400)။ ပြီးမှ validate လုပ်ထားတဲ့ field တွေကနေ object အသစ် တည်ဆောက်ပါ — req.body ကို database ထဲ တိုက်ရိုက် မထည့်ပါနဲ့။
Identity ကို နှစ်ဆင့် ခွဲစစ်ပါ။ Authentication က 'မင်း ဘယ်သူလဲ' ကို ဖြေပါတယ် — token မရှိ ဒါမှမဟုတ် မမှန်ရင် 401။ Authorization က 'ဒါကို လုပ်ခွင့် ရှိလား' ကို ဖြေပါတယ် — role မလုံလောက် ဒါမှမဟုတ် record ကို မပိုင်ရင် 403 (record ရှိမှန်း မပြချင်ရင် 404)။ Record ပိုင်ဆိုင်မှုကို မစစ်တဲ့ bug ကို IDOR (insecure direct object reference) လို့ ခေါ်ပါတယ်။ Secret token ကို === နဲ့ နှိုင်းယှဉ်ရင် မတူတဲ့ ပထမ character မှာ ရပ်တဲ့အတွက် အချိန်ကွာခြားမှုက အချက်အလက် ပေါက်ကြားစေနိုင်ပါတယ်၊ ဒါကြောင့် crypto.timingSafeEqual ကို သုံးပါ။
Response ဘက်မှာလည်း ကာကွယ်ရပါတယ်။ X-Content-Type-Options: nosniff နဲ့ Content-Security-Policy လို header တွေက browser ကို response ကို ဘယ်လို ဆက်ဆံရမလဲ ပြောပြပါတယ်၊ Express မှာ helmet package က ဒီ header တွေကို တစ်ခါတည်း သတ်မှတ်ပေးပါတယ်။ Error response မှာ client ပြင်လို့ရတဲ့ message ကိုပဲ ပြန်ပြီး stack trace၊ SQL error၊ file path လို internal detail တွေကို log ထဲမှာပဲ ထားပါ။
| Status | အဓိပ္ပာယ် | ဥပမာ |
|---|---|---|
| 400 | Request ရဲ့ ပုံစံ မှားနေ | Malformed JSON၊ မသိတဲ့ field |
| 401 | မင်း ဘယ်သူလဲ မသိ | Token မပါ ဒါမှမဟုတ် မမှန် |
| 403 | သိတယ်၊ ဒါပေမဲ့ ခွင့်မပြု | Reader က user ဖျက်ဖို့ ကြိုးစား |
| 413 / 415 | Body ကြီးလွန်း / format မမှန် | 2 MB JSON၊ form data |
- Format နဲ့ size စစ် (415/413)
- Token စစ်: ဘယ်သူလဲ (401)
- Role/ownership စစ် (403)
- Field allowlist စစ် (400)
- စစ်ပြီးသား data နဲ့ပဲ အလုပ်လုပ်
Check တစ်ခုခု မအောင်ရင် ချက်ချင်း ပြန်ပါ၊ နောက် check တွေ ဒါမှမဟုတ် business logic ကို မရောက်စေပါနဲ့။
အထွေထွေ ပုံစံ
async function handle(req, res) {
setSecurityHeaders(res);
if (!isJson(req)) return send(res, 415, { error: '...' });
const caller = authenticate(req.headers.authorization);
if (!caller) return send(res, 401, { error: '...' });
if (!mayAccess(caller, resource)) return send(res, 403, { error: '...' });
const input = await readJsonWithLimit(req, MAX_BYTES); // 413 / 400
const problem = validateAgainstAllowlist(input);
if (problem) return send(res, 400, { error: problem });
return act(pickAllowedFields(input));
}Check တိုင်းက early return နဲ့ ငြင်းပါတယ်၊ ဒါကြောင့် နောက်ဆုံး line ကို ရောက်တဲ့ request က check အားလုံး အောင်ပြီးသားပါ။ Framework သုံးရင် ဒီ step တွေက middleware တစ်ခုစီ ဖြစ်လာပါတယ်။
Worked example: notes API ရဲ့ input boundary
ဒီ server ကို node:http နဲ့ပဲ ရေးထားပြီး package တစ်ခုမှ မသုံးပါဘူး၊ check တစ်ခုစီကို ကိုယ်တိုင် မြင်ရအောင်ပါ။ Server ကို port 0 ပေါ်မှာ ဖွင့်ပြီး request ငါးမျိုးကို အစဉ်လိုက် ပို့ပါတယ်: မှန်ကန်တဲ့ note၊ ခွင့်မပြုထားတဲ့ field ပါတာ၊ ကျိုးနေတဲ့ JSON၊ 2 MB body နဲ့ form data။ Response တိုင်းမှာ security header တွေ ပါကြောင်းလည်း နောက်ဆုံးမှာ စစ်ပါတယ်။
import { createServer } from 'node:http';
const MAX_BODY_BYTES = 1024;
const ALLOWED_FIELDS = new Set(['title', 'body']);
function setSecurityHeaders(res) {
res.setHeader('X-Content-Type-Options', 'nosniff');
res.setHeader('Content-Security-Policy', "default-src 'none'; frame-ancestors 'none'");
res.setHeader('Referrer-Policy', 'no-referrer');
}
function send(res, status, payload) {
res.writeHead(status, { 'Content-Type': 'application/json' });
res.end(JSON.stringify(payload));
}
function httpError(status, message) {
return Object.assign(new Error(message), { status });
}
async function readJson(req) {
if (Number(req.headers['content-length'] ?? 0) > MAX_BODY_BYTES) {
throw httpError(413, 'body too large'); // reject before reading a byte
}
let size = 0;
const chunks = [];
for await (const chunk of req) {
size += chunk.length; // chunked uploads have no Content-Length to trust
if (size > MAX_BODY_BYTES) throw httpError(413, 'body too large');
chunks.push(chunk);
}
try {
return JSON.parse(Buffer.concat(chunks).toString('utf8'));
} catch {
throw httpError(400, 'malformed JSON');
}
}
function validateNote(input) {
if (typeof input !== 'object' || input === null || Array.isArray(input)) {
return 'body must be a JSON object';
}
const unknown = Object.keys(input).filter((key) => !ALLOWED_FIELDS.has(key));
if (unknown.length > 0) return `unknown field: ${unknown.join(', ')}`;
if (typeof input.title !== 'string' || input.title.trim() === '') {
return 'title is required';
}
if (input.title.length > 80) return 'title is longer than 80 characters';
if (input.body !== undefined && typeof input.body !== 'string') {
return 'body must be text';
}
return null;
}
const server = createServer(async (req, res) => {
setSecurityHeaders(res);
if (req.method !== 'POST' || req.url !== '/notes') {
return send(res, 404, { error: 'not found' });
}
if (!req.headers['content-type']?.startsWith('application/json')) {
return send(res, 415, { error: 'send application/json' });
}
try {
const input = await readJson(req);
const problem = validateNote(input);
if (problem) return send(res, 400, { error: problem });
send(res, 201, { title: input.title.trim(), body: input.body ?? '' });
} catch (error) {
// Known client errors explain themselves; anything else stays generic.
const message = error.status ? error.message : 'internal error';
send(res, error.status ?? 500, { error: message });
}
});
await new Promise((resolve) => server.listen(0, '127.0.0.1', resolve));
const url = `http://127.0.0.1:${server.address().port}/notes`;
const post = (body, type = 'application/json') =>
fetch(url, { method: 'POST', headers: { 'Content-Type': type }, body });
const attempts = [
['valid note', JSON.stringify({ title: ' Hello ', body: 'first' })],
['extra field', JSON.stringify({ title: 'Hi', isAdmin: true })],
['broken JSON', '{"title":'],
['huge body', JSON.stringify({ title: 'x', body: 'y'.repeat(2_000_000) })],
['form data', 'title=Hi', 'application/x-www-form-urlencoded'],
];
for (const [label, body, type] of attempts) {
const res = await post(body, type);
console.log(label.padEnd(12), res.status, JSON.stringify(await res.json()));
}
const sample = await post(JSON.stringify({ title: 'Headers' }));
console.log('nosniff header:', sample.headers.get('x-content-type-options'));
server.close();Code ကို တစ်ပိုင်းချင်း ရှင်းပြမယ်
- Security headers
res.setHeader('X-Content-Type-Options', 'nosniff');Browser ကို Content-Type အတိုင်းပဲ ဆက်ဆံခိုင်းပြီး JSON ကို script အဖြစ် ခန့်မှန်းမလုပ်စေပါဘူး။ CSP default-src 'none' က JSON API response ထဲက ဘာကိုမှ load မလုပ်ခိုင်းပါဘူး။
- Cheap rejection first
if (Number(req.headers['content-length'] ?? 0) > MAX_BODY_BYTES) {ကြေညာထားတဲ့ size က ကြီးလွန်းရင် byte တစ်ခုမှ မဖတ်ဘဲ 413 ပြန်ပါတယ်။ ဒါပေမဲ့ header ကို လိမ်လို့ရလို့ loop ထဲမှာလည်း ထပ်စစ်ပါတယ်။
- Count while streaming
if (size > MAX_BODY_BYTES) throw httpError(413, 'body too large');Chunk တစ်ခုစီ ဝင်လာတိုင်း စုစုပေါင်းကို စစ်လို့ attacker က header မပို့ဘဲ chunked upload လုပ်လည်း memory မပြည့်နိုင်ပါဘူး။
- Allowlist, not blocklist
const unknown = Object.keys(input).filter((key) => !ALLOWED_FIELDS.has(key));isAdmin ကို ပိတ်ထားတဲ့ blocklist မဟုတ်ဘဲ ခွင့်ပြုတဲ့ field နှစ်ခုကိုပဲ လက်ခံပါတယ်။ နောင်မှာ database ထဲ column အသစ် ထပ်လာလည်း client က အလိုလို ရေးခွင့် မရပါဘူး။
- Generic 500
const message = error.status ? error.message : 'internal error';Client error တွေက ကိုယ့်ဘာသာ ရှင်းပြပေမဲ့ မမျှော်လင့်ထားတဲ့ error ရဲ့ message နဲ့ stack ကို client ဆီ မပို့ပါဘူး၊ internal detail ပေါက်ကြားနိုင်လို့ပါ။
valid note 201 {"title":"Hello","body":"first"}
extra field 400 {"error":"unknown field: isAdmin"}
broken JSON 400 {"error":"malformed JSON"}
huge body 413 {"error":"body too large"}
form data 415 {"error":"send application/json"}
nosniff header: nosniffProcess ကို လိုအပ်တဲ့ permission ပဲ ပေးခြင်း
Request တွေကို စစ်ပြီးတောင် dependency တစ်ခုထဲမှာ bug ဒါမှမဟုတ် path traversal ရှိနိုင်ပါသေးတယ်။ Node.js permission model က process တစ်ခုလုံးကို file system၊ child process၊ worker thread စတာတွေ အသုံးပြုခွင့် ကန့်သတ်ပေးပါတယ်။ --permission နဲ့ စလိုက်ရင် ခွင့်ပြုချက် flag နဲ့ ပေးထားတာကလွဲလို့ ကျန်တာ အားလုံး ပိတ်ထားပါတယ်။ Node 22 ရဲ့ နောက်ပိုင်း release တွေက --permission ကို လက်ခံပြီး အရင် release တွေမှာ --experimental-permission လို့ ရေးရပါတယ်၊ ဒါကြောင့် node --help နဲ့ စစ်ပါ။
# read config and public files only; no writes, no child processes
node --permission --allow-fs-read=./config --allow-fs-read=./public server.js
# inside the app you can ask at runtime:
# process.permission.has('fs.write') -> falseSeatbelt ပါ၊ sandbox မဟုတ်ပါဘူး
Node.js documentation ကိုယ်တိုင်က permission model ဟာ malicious code ကို ကာကွယ်ဖို့ မဟုတ်ကြောင်း ပြောထားပါတယ်။ ယုံကြည်ရတဲ့ code က မတော်တဆ မလုပ်သင့်တာ လုပ်မိတာကို ကန့်သတ်ဖို့ပါ။ Untrusted code ကို run ဖို့ဆိုရင် container ဒါမှမဟုတ် VM လို OS-level isolation လိုပါတယ်။
လက်တွေ့ project တွေမှာ
လက်တွေ့ Express project တွေမှာ
Express app တွေမှာ ဒီ check တွေကို ကိုယ်တိုင် အမြဲ မရေးပါဘူး၊ ဒါပေမဲ့ ဘာလုပ်ပေးလဲ နားလည်ထားဖို့ လိုပါတယ်။ ပုံမှန် setup တစ်ခုမှာ helmet က security header တွေကို သတ်မှတ်ပေးပြီး express.json({ limit: '100kb' }) က body size ကို ကန့်သတ်ပါတယ်၊ zod လို schema library က allowlist validation ကို လုပ်ပေးပါတယ်။
- Authentication middleware က session ဒါမှမဟုတ် JWT ကို စစ်ပြီး req.user ကို set လုပ်ပါတယ်၊ route တိုင်းက req.user ပေါ်မှာ authorization ကို ထပ်စစ်ပါတယ်။
- Ownership check ကို query ထဲမှာ ထည့်ရေးပါ: WHERE id = $1 AND owner_id = $2 လို့ ရေးရင် တခြားလူရဲ့ record ကို ဘယ်တော့မှ မရနိုင်ပါဘူး။
- Login နဲ့ password reset လို route တွေမှာ rate limiting ထည့်ပြီး server ရဲ့ requestTimeout နဲ့ headersTimeout ကို ရည်ရွယ်ချက်ရှိရှိ သတ်မှတ်ပါ။
- Dependency တွေကို npm audit နဲ့ စစ်ပြီး Node.js ကိုယ်တိုင်ကိုလည်း support ရှိနေတဲ့ LTS version ပေါ်မှာ patch ထားပါ။
အမှားများ
HTTP security မှာ ဖြစ်လေ့ရှိတဲ့ အမှားများ
401 နဲ့ 403 ကို ရောထွေးခြင်း
Token မှန်ပေမဲ့ role မလုံလောက်တဲ့ user ကို 401 ပြန်ရင် client က login ပြန်ဝင်ခိုင်းပြီး loop ဖြစ်ပါတယ်။ 401 က 'မင်း ဘယ်သူလဲ မသိဘူး' ဖြစ်ပြီး 403 က 'သိတယ်၊ ဒါပေမဲ့ ဒါကို လုပ်ခွင့်မရှိဘူး' ဖြစ်ပါတယ်။
Blocklist နဲ့ validate လုပ်ခြင်း
delete req.body.role လို field တစ်ခုချင်း ဖယ်ထုတ်တာက database မှာ isAdmin ဒါမှမဟုတ် balance လို column အသစ် ထပ်လာတဲ့နေ့မှာ ပေါက်သွားပါတယ်။ ခွင့်ပြုတဲ့ field တွေကိုပဲ ရွေးယူပြီး ကျန်တာကို reject လုပ်ပါ။
Token ကို === နဲ့ နှိုင်းယှဉ်ခြင်း ဒါမှမဟုတ် length ကို အရင်စစ်ခြင်း
=== က ပထမဆုံး မတူတဲ့ character မှာ ရပ်လို့ response time ကနေ token ကို တစ်လုံးချင်း ခန့်မှန်းနိုင်ပါတယ်။ timingSafeEqual က length မတူရင် throw လုပ်တဲ့အတွက် length ကို အရင်စစ်ရင်လည်း length ပေါက်ကြားပါတယ်။ Value နှစ်ခုလုံးကို SHA-256 နဲ့ hash လုပ်ပြီး အရှည်တူ digest တွေကို နှိုင်းယှဉ်ပါ။
Best Practices
Best practices
- Route အသစ်တိုင်းမှာ default က 'ငြင်း' ဖြစ်ပါစေ၊ authentication နဲ့ authorization ကို တမင် ဖွင့်ပေးမှ အလုပ်လုပ်ပါစေ။
- Validate လုပ်ပြီးသား field တွေကနေ object အသစ် ဆောက်ပြီး response မှာလည်း ပြချင်တဲ့ field တွေကိုပဲ ရွေးပြပါ။
- Secret တွေကို source code ထဲ မထားဘဲ secret store ကနေ ဖတ်ပြီး hash လုပ်ထားတဲ့ ပုံစံနဲ့ သိမ်းပါ။
- Security check တိုင်းအတွက် 401၊ 403၊ 413 ပြန်ကြောင်း integration test ရေးပါ။
Mini challenge
Mini challenge: token နဲ့ role middleware
DELETE /users/:id route ကို admin role ရှိတဲ့ caller တွေပဲ သုံးနိုင်အောင် ကာကွယ်ပါ။ Authorization: Bearer <token> header ကနေ caller ကို ရှာပြီး token ကို timing-safe နည်းနဲ့ နှိုင်းယှဉ်ပါ။ Server ကို port 0 မှာ ဖွင့်ပြီး token မပါ၊ token မှား၊ reader token၊ admin token လေးမျိုးနဲ့ စမ်းပါ။
- Token မပါ ဒါမှမဟုတ် မမှန်ရင် 401
- Token မှန်ပေမဲ့ role က admin မဟုတ်ရင် 403
- Token တွေကို sha256 digest + timingSafeEqual နဲ့ နှိုင်းယှဉ်ပါ
- requireRole(role, handler) ပုံစံ ပြန်သုံးလို့ရတဲ့ middleware ရေးပါ
import { createHash, timingSafeEqual } from 'node:crypto';
import { createServer } from 'node:http';
const API_KEYS = [
{ key: 'reader-key-123', user: 'mya', role: 'reader' },
{ key: 'admin-key-456', user: 'ko-aung', role: 'admin' },
];
function findCaller(header) {
// TODO: require the "Bearer " prefix
// TODO: hash the presented token and each stored key, compare safely
}
function requireRole(role, handler) {
// TODO: return (req, res) => { 401 / 403 / call handler(req, res, caller) }
}
// TODO: DELETE /users/:id protected by requireRole('admin', ...)
// TODO: listen on port 0, try four Authorization headers, print the statusesရလဒ်: Token မပါတာနဲ့ guess က 401၊ reader-key-123 က 403 နဲ့ admin-key-456 က 200 { deleted: '42', by: 'ko-aung' } ကို ပြပါတယ်။
အရိပ်အမြွက် ကြည့်ရန်
createHash('sha256').update(value).digest() က input ဘယ်လောက်ရှည်ရှည် byte 32 ပြန်ပေးတဲ့အတွက် timingSafeEqual က length error မထုတ်တော့ပါဘူး။ requireRole ထဲမှာ caller မရှိရင် 401၊ role မကိုက်ရင် 403 ကို အစဉ်လိုက် စစ်ပါ။
အဖြေ ကြည့်ရန်
import { createHash, timingSafeEqual } from 'node:crypto';
import { createServer } from 'node:http';
// In production these come from a secret store, never from source code.
const API_KEYS = [
{ key: 'reader-key-123', user: 'mya', role: 'reader' },
{ key: 'admin-key-456', user: 'ko-aung', role: 'admin' },
];
const digest = (value) => createHash('sha256').update(value).digest();
function findCaller(header) {
if (!header?.startsWith('Bearer ')) return null;
const presented = digest(header.slice('Bearer '.length));
// Equal-length digests let timingSafeEqual compare without leaking the length.
return API_KEYS.find((entry) => timingSafeEqual(presented, digest(entry.key))) ?? null;
}
function requireRole(role, handler) {
return (req, res) => {
const caller = findCaller(req.headers.authorization);
if (!caller) return reply(res, 401, { error: 'missing or invalid token' });
if (caller.role !== role) return reply(res, 403, { error: `needs role ${role}` });
handler(req, res, caller);
};
}
function reply(res, status, payload) {
res.writeHead(status, { 'Content-Type': 'application/json' });
res.end(JSON.stringify(payload));
}
const deleteUser = requireRole('admin', (req, res, caller) => {
reply(res, 200, { deleted: req.url.split('/').at(-1), by: caller.user });
});
const server = createServer((req, res) => {
if (req.method === 'DELETE' && req.url.startsWith('/users/')) {
return deleteUser(req, res);
}
reply(res, 404, { error: 'not found' });
});
await new Promise((resolve) => server.listen(0, '127.0.0.1', resolve));
const base = `http://127.0.0.1:${server.address().port}`;
for (const token of [undefined, 'guess', 'reader-key-123', 'admin-key-456']) {
const headers = token ? { Authorization: `Bearer ${token}` } : {};
const res = await fetch(`${base}/users/42`, { method: 'DELETE', headers });
console.log(String(token).padEnd(15), res.status, JSON.stringify(await res.json()));
}
server.close();Quick Quiz 1 / 3
Quick Quiz 2 / 3
Quick Quiz 3 / 3
မှတ်ထားရမယ့် အချက်များ
- Request တိုင်းကို မယုံကြည်ရသေးတဲ့ input အဖြစ် ဆက်ဆံပြီး ဈေးအပေါဆုံး check တွေကို အရင် လုပ်ပါ။
- Body ကို byte ရေတွက်ရင်း ဖတ်ပြီး limit ကျော်ရင် 413၊ format မမှန်ရင် 415၊ ပုံစံမှားရင် 400 ပြန်ပါ။
- Allowlist validation နဲ့ object အသစ် တည်ဆောက်ခြင်းက mass assignment ကို ကာကွယ်ပါတယ်။
- 401 က identity အတွက်၊ 403 က permission နဲ့ ownership အတွက်ဖြစ်ပြီး token ကို timing-safe နည်းနဲ့ နှိုင်းယှဉ်ပါ။
- Security header တွေ (သို့မဟုတ် helmet) နဲ့ --permission က ကာကွယ်ရေး အလွှာ ထပ်တိုးပေးပါတယ်။
Permissions — Node.js