Latihan 1 dari materi CORS Deep Dive di Security — praktek dengan editor kode interaktif, test case otomatis, dan hint terpandu. Langsung jalan di browser.
Buat fungsi setCORSHeaders(res, origin, allowedOrigins) yang mengatur CORS headers pada response object.
origin ada di dalam array allowedOrigins, set headers:
Access-Control-Allow-Origin → origin yang di-requestAccess-Control-Allow-Methods → GET, POST, PUT, DELETEAccess-Control-Allow-Headers → Content-Type, AuthorizationAccess-Control-Allow-OriginGunakan res.setHeader(name, value) untuk mengatur header.
Output yang diharapkan:
Allowed: https://myapp.com
Blocked: undefined