[Update] nonce 파라미터 감지 범위 늘림 및 nonce 파라미터 재사용에대한 검증 로직 추가
This commit is contained in:
parent
c722adbe9d
commit
efb89c668c
3 changed files with 315 additions and 93 deletions
|
|
@ -1,3 +1,6 @@
|
|||
import type { SDK } from "caido:plugin";
|
||||
import { Body, RequestSpec, type Request, type Response } from "caido:utils";
|
||||
|
||||
let instance: HttpUtils | null = null;
|
||||
export class HttpUtils {
|
||||
/**
|
||||
|
|
@ -11,6 +14,14 @@ export class HttpUtils {
|
|||
return instance;
|
||||
}
|
||||
|
||||
encodeAndLower(value: string): string {
|
||||
try {
|
||||
return encodeURIComponent(value).toLowerCase();
|
||||
} catch {
|
||||
return value.toLowerCase();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* URI 디코딩 후 소문자로 변환하는 헬퍼 함수
|
||||
* @param value - 디코딩하고 소문자로 변환할 문자열
|
||||
|
|
@ -47,12 +58,35 @@ export class HttpUtils {
|
|||
return result;
|
||||
}
|
||||
|
||||
getPathFromURI(uri: string): string | null {
|
||||
uri = uri.toLowerCase();
|
||||
try {
|
||||
const urlObj = new URL(uri);
|
||||
const path = urlObj.pathname;
|
||||
return path ? decodeURIComponent(path) : null; // 경로가 없으면 null 반환
|
||||
} catch (e) {
|
||||
return null; // URL 파싱 실패 시 null 반환
|
||||
}
|
||||
}
|
||||
|
||||
getQueryFromURI(uri: string): string | null {
|
||||
uri = uri.toLowerCase();
|
||||
try {
|
||||
const urlObj = new URL(uri);
|
||||
const query = urlObj.search;
|
||||
return query ? decodeURIComponent(query.slice(1)) : null; // 쿼리 문자열에서 ? 제거
|
||||
} catch (e) {
|
||||
return null; // URL 파싱 실패 시 null 반환
|
||||
}
|
||||
}
|
||||
|
||||
getQueryParamFromURI(uri: string, key: string): string | null {
|
||||
uri = this.decodeAndLower(uri);
|
||||
uri = uri.toLowerCase();
|
||||
key = this.decodeAndLower(key);
|
||||
try {
|
||||
const urlObj = new URL(uri);
|
||||
return urlObj.searchParams.get(key);
|
||||
const param = urlObj.searchParams.get(key);
|
||||
return param ? decodeURIComponent(param) : null;
|
||||
} catch (e) {
|
||||
return null;
|
||||
}
|
||||
|
|
@ -66,11 +100,12 @@ export class HttpUtils {
|
|||
* @returns - 해당 파라미터 값, 없으면 null
|
||||
*/
|
||||
getQueryParam(query: string, key: string): string | null {
|
||||
query = this.decodeAndLower(query);
|
||||
query = query.toLowerCase();
|
||||
key = this.decodeAndLower(key);
|
||||
|
||||
const params = new URLSearchParams(query);
|
||||
return params.get(key);
|
||||
const targetParam = params.get(key);
|
||||
return targetParam ? decodeURIComponent(targetParam) : null;
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -82,12 +117,12 @@ export class HttpUtils {
|
|||
* @returns - "a=1&b=2&c=3..." 형태의 새로운 쿼리 문자열
|
||||
*/
|
||||
setQueryParam(query: string, key: string, value: string): string {
|
||||
query = this.decodeAndLower(query);
|
||||
query = query.toLowerCase();
|
||||
key = this.decodeAndLower(key);
|
||||
value = this.decodeAndLower(value);
|
||||
|
||||
const params = new URLSearchParams(query);
|
||||
params.set(key, value);
|
||||
params.set(key, this.encodeAndLower(value));
|
||||
return params.toString();
|
||||
}
|
||||
|
||||
|
|
@ -99,7 +134,7 @@ export class HttpUtils {
|
|||
* @returns - 삭제된 상태의 새로운 쿼리 문자열
|
||||
*/
|
||||
removeQueryParam(query: string, key: string): string {
|
||||
query = this.decodeAndLower(query);
|
||||
query = query.toLowerCase();
|
||||
key = this.decodeAndLower(key);
|
||||
|
||||
const params = new URLSearchParams(query);
|
||||
|
|
@ -109,6 +144,7 @@ export class HttpUtils {
|
|||
|
||||
// Headers
|
||||
/**
|
||||
* !! 만약 request.getHeader(`${key}`)을 사용할 수 있다면 이 함수를 사용하지 마세요.
|
||||
* 주어진 헤더 맵에서 name에 해당하는 첫 번째 헤더 값을 반환합니다.
|
||||
* @param headers - Response.getHeaders() 가 반환하는 객체
|
||||
* @param name - 꺼내고 싶은 헤더 이름 (예: "location", "Content-Type")
|
||||
|
|
@ -207,4 +243,89 @@ export class HttpUtils {
|
|||
}
|
||||
return filtered;
|
||||
}
|
||||
|
||||
async resend(
|
||||
sdk: SDK,
|
||||
request: Request,
|
||||
options?: {
|
||||
headers?: Record<string, string | string[]>;
|
||||
body?: Body;
|
||||
method?: string;
|
||||
query?: string;
|
||||
}
|
||||
): Promise<Response | null> {
|
||||
try {
|
||||
const spec = new RequestSpec(request.getUrl());
|
||||
spec.setMethod(options?.method || request.getMethod() || "GET");
|
||||
if (options?.query) {
|
||||
spec.setQuery(options.query);
|
||||
} else {
|
||||
spec.setQuery(request.getQuery() || "");
|
||||
}
|
||||
|
||||
const originBody = request.getBody();
|
||||
if (options?.body) {
|
||||
spec.setBody(options.body);
|
||||
} else if (originBody) {
|
||||
spec.setBody(originBody);
|
||||
}
|
||||
|
||||
const headers = request.getHeaders();
|
||||
if (options?.headers) {
|
||||
// 기존 헤더에서 options.headers로 덮어쓰기
|
||||
const newHeaders = this.lowerCaseAllHeaders({
|
||||
...headers,
|
||||
...options.headers,
|
||||
});
|
||||
for (const [key, value] of Object.entries(newHeaders)) {
|
||||
spec.setHeader(key, Array.isArray(value) ? value.join(", ") : value);
|
||||
}
|
||||
} else {
|
||||
// 기존 헤더 그대로 사용
|
||||
for (const [key, value] of Object.entries(headers)) {
|
||||
spec.setHeader(key, Array.isArray(value) ? value.join(", ") : value);
|
||||
}
|
||||
}
|
||||
|
||||
const result = await sdk.requests.send(spec);
|
||||
return result.response ?? null;
|
||||
} catch (error) {
|
||||
sdk.console.error(
|
||||
`Error resending request to ${request.getUrl()}: ${String(error)}`
|
||||
);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
async customFetch(
|
||||
sdk: SDK,
|
||||
url: string,
|
||||
method?: string,
|
||||
query?: string,
|
||||
headers?: Record<string, string | string[]>,
|
||||
body?: Body
|
||||
): Promise<Response | null> {
|
||||
try {
|
||||
const spec = new RequestSpec(url);
|
||||
spec.setMethod(method || "GET");
|
||||
if (query) {
|
||||
spec.setQuery(query);
|
||||
}
|
||||
if (body) {
|
||||
spec.setBody(body);
|
||||
}
|
||||
|
||||
for (const [key, value] of Object.entries(headers || {})) {
|
||||
spec.setHeader(key, Array.isArray(value) ? value.join(", ") : value);
|
||||
}
|
||||
|
||||
const result = await sdk.requests.send(spec);
|
||||
return result.response ?? null;
|
||||
} catch {
|
||||
sdk.console.error(
|
||||
`Error during custom fetch to ${url}: ${String(error)}`
|
||||
);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue