[Update] nonce 파라미터 감지 범위 늘림 및 nonce 파라미터 재사용에대한 검증 로직 추가

This commit is contained in:
tv0924@icloud.com 2025-06-04 16:02:42 +09:00
commit efb89c668c
3 changed files with 315 additions and 93 deletions

View file

@ -1,5 +1,6 @@
// app.js
const express = require("express");
const crypto = require("crypto");
const app = express();
const port = 8000;
@ -43,8 +44,6 @@ app.get("/authorize/mismatch-state", (req, res) => {
);
const code = "authcode-67890";
console.log(`[VULN] original state from client:`, originalState);
// 클라이언트 state와 다르게 'wrong-state'를 삽입
const wrongState = "wrong-state";
const location = `${redirectUri}?code=${code}&state=${wrongState}&client_id=${clientId}`;
@ -52,6 +51,24 @@ app.get("/authorize/mismatch-state", (req, res) => {
res.status(302).send(`Redirecting to ${location}`);
});
/**
* 3) 랜덤 state를 생성하여 리다이렉트를 발생시키는 테스트용 엔드포인트
* - /authorize/reuse-state-test 16 state
* - 최초 요청에 OAuth 파라미터가 없으므로 isOauthUri(request) == false
* - 응답에 Location 헤더로 '...?state=<랜덤값>' 포함
* -> Caido 플러그인의 checkNonceReuse 로직에서 새로운 state가 발급되었는지,
* 재사용되었는지를 검증할 있음
* - 더하여 callback uri에서 해당 nonce의 유효성을 판단하지 않고 응답 시에 vuln
*/
app.get("/authorize/reuse-state-test", (req, res) => {
const state = crypto.randomBytes(16).toString("hex");
// 고정된 콜백 URI로 리다이렉트 (OAuth 파라미터는 여기서만 주입)
const location = `http://localhost:${port}/callback?state=${state}&client_id=123`;
res.set("Location", location);
res.status(302).send(`Redirecting to ${location}`);
});
app.listen(port, () => {
console.log(
`Vulnerable OAuth test server listening at http://localhost:${port}`
@ -62,4 +79,7 @@ app.listen(port, () => {
console.log(
`2) Mismatch-State: http://localhost:${port}/authorize/mismatch-state?client_id=abc&state=xyz&redirect_uri=http://localhost:${port}/callback`
);
console.log(
`3) Reuse-State-Test: http://localhost:${port}/authorize/reuse-state-test`
);
});