서버가 공격자가 제어하는 URL로 요청을 보내도록 유도해, 내부 네트워크나 클라우드 메타데이터에 접근하는 취약점입니다.
// ❌ 취약: URL 검증 없는 외부 요청
router.post('/price-fetch', async (req, res) => {
const { url } = req.body;
const response = await axios.get(url); // 어떤 URL이든 요청
res.json(response.data);
// http://169.254.169.254/ → AWS 메타데이터 접근
});
// ✅ 안전: 허용 도메인 화이트리스트
const ALLOWED = ['api.coindesk.com', 'api.bithumb.com'];
const { hostname } = new URL(url);
if (!ALLOWED.includes(hostname)) {
return res.status(403).json({ error: '허용되지 않는 도메인' });
}
// ✅ Private IP 차단
const ip = await dns.resolve(hostname);
if (isPrivateIP(ip)) {
return res.status(403).json({ error: '내부 IP 접근 차단' });
}