The Real Fullstack

The SSRF Image Proxy

It just downloads a picture from a URL. What could go wrong?

مهندس أول9 دقيقةمحاكي التدفّقتحدي الشيفرة
nodeawshttpdns

لم يُترجم هذا التحدي إلى العربية بعد. أنت تقرأ النسخة الإنجليزية.

المهمة:Choose protections that keep legitimate image imports working while making internal addresses unreachable, including via DNS tricks and redirects.السياق · أهداف التعلّم ▾

Hollow Basket lets sellers import product photos by URL; a small service downloads the image server-side. A penetration tester pointed it at the cloud metadata address and at internal hosts, and got back credentials and an internal Elasticsearch response.

المهمة: Choose protections that keep legitimate image imports working while making internal addresses unreachable, including via DNS tricks and redirects.

أهداف التعلّم

  • Understand Server-Side Request Forgery (SSRF).
  • Validate the resolved IP address, not the hostname string.
  • Re-validate redirects and pin the connection to the checked address.
المحاكاةمحاكاة
sellerimage import servicepublic webcloud metadata serviceinternal services
تشغيل المحاكاة
async function fetchImage(rawUrl) {  const url = new URL(rawUrl);  if (url.protocol !== 'https:') throw new BadRequest();  const { address } = await dns.lookup(url.hostname);          // resolve once…  if (isPrivateOrReserved(address)) throw new BadRequest();     // 10/8, 172.16/12, 192.168/16, 127/8, 169.254/16, ::1, fc00::/7 …  const res = await request(url, {    lookup: pinTo(address),        // …and connect to exactly that address (no DNS rebinding)    maxRedirections: 0,            // or re-validate every Location header the same way    timeout: 5000,  });  if (!res.headers['content-type']?.startsWith('image/')) throw new BadRequest();  return res.body;}// defence in depth: require IMDSv2 tokens and run the proxy without an instance role

تبسيط

Six URLs with fixed properties. Real defences add network egress rules and run the fetcher with no cloud credentials. نموذج تعليمي — الأرقام توضّح سلوكًا وليست قياسات أداء.

المفاهيم

تحديات ذات صلة

المراجع