ui, 외부커넥션에서 쿼리 조회만 가능하도록

This commit is contained in:
leeheejin
2025-09-30 10:30:05 +09:00
parent 9168ab9a41
commit 8c19d57ced
24 changed files with 452 additions and 225 deletions

View File

@@ -699,6 +699,30 @@ export class ExternalDbConnectionService {
params: any[] = []
): Promise<ApiResponse<any[]>> {
try {
// 보안 검증: SELECT 쿼리만 허용
const trimmedQuery = query.trim().toUpperCase();
if (!trimmedQuery.startsWith('SELECT')) {
console.log("보안 오류: SELECT가 아닌 쿼리 시도:", { id, query: query.substring(0, 100) });
return {
success: false,
message: "외부 데이터베이스에서는 SELECT 쿼리만 실행할 수 있습니다.",
};
}
// 위험한 키워드 검사
const dangerousKeywords = ['INSERT', 'UPDATE', 'DELETE', 'DROP', 'CREATE', 'ALTER', 'TRUNCATE', 'EXEC', 'EXECUTE', 'CALL', 'MERGE'];
const hasDangerousKeyword = dangerousKeywords.some(keyword =>
trimmedQuery.includes(keyword)
);
if (hasDangerousKeyword) {
console.log("보안 오류: 위험한 키워드 포함 쿼리 시도:", { id, query: query.substring(0, 100) });
return {
success: false,
message: "데이터를 변경하거나 삭제하는 쿼리는 허용되지 않습니다. SELECT 쿼리만 사용해주세요.",
};
}
// 연결 정보 조회
console.log("연결 정보 조회 시작:", { id });
const connection = await prisma.external_db_connections.findUnique({