본문 바로가기
Q&A2023년 8월 11일1분 읽기

IDOR 취약점이 뭔가요?

배
배준호
조회 749댓글 1

IDOR(Insecure Direct Object Reference) 취약점이 뭔가요? 어떻게 방어하나요?

댓글 1

김김영삼3년 전

IDOR은 URL이나 파라미터의 ID를 변경하여 다른 사용자의 데이터에 접근하는 취약점입니다.

# 취약한 예시
GET /api/users/123/profile ← 내 프로필
GET /api/users/124/profile ← 다른 사람 프로필도 보임!

GET /api/orders/1001 ← 내 주문
GET /api/orders/1002 ← 남의 주문도 보임!

방어:

// 나쁜 코드
app.get("/api/orders/:id", async (req, res) => {
const order = await db.order.findById(req.params.id);
res.json(order); // 누구 것이든 반환
});

// 좋은 코드
app.get("/api/orders/:id", async (req, res) => {
const order = await db.order.findFirst({
where: { id: req.params.id, userId: req.user.id } // 본인 것만
});
if (!order) return res.status(404).json({ error: "Not found" });
res.json(order);
});

OWASP Top 10에서 1위인 Broken Access Control의 대표적인 예입니다.

Ctrl+Enter로 등록