Latihan 1: Prototype Pollution — Security

Latihan 1 dari materi Prototype Pollution di Security — praktek dengan editor kode interaktif, test case otomatis, dan hint terpandu. Langsung jalan di browser.

Buat fungsi safeMerge(target, source) yang melakukan shallow merge tapi menolak key berbahaya prototype pollution.

Fungsi tidak boleh mencemari Object.prototype. Setelah memanggil safeMerge({}, {"__proto__": {polluted: true}}), object baru {} tidak boleh memiliki property polluted.

Contoh:

const t = safeMerge({a: 1}, {b: 2}); // { a: 1, b: 2 }
safeMerge({}, JSON.parse('{"__proto__":{"polluted":true}}'));
({}).polluted // undefined (tidak tercemar)

Hint