코드 보안 결함 패치 및 테스트
보안 스캔에서 지적된 코드베이스의 보안 취약점을 기존 기능 훼손 없이 수정하고 검증 테스트를 작성합니다.
- 추천 툴
- 공통AI 분류
- 쓰인 기법
- 단계별 사고 · 지시문 명확화
프롬프트 원문
in order to fix security issues in my codebase which is flagged by code scanning for refrences like user input comping as part o request could be vulnerable and how can we fix it # security fixes it should identify the issue and fix it with respect to current project checking it should not break the existing functionality and a proper test case should be written for the change ## Instructions check the issue fix it test case
한국어 풀이 보기(참고용)
사용자 입력 요청 등 코드 스캔에서 보안 취약점으로 지적된 코드베이스의 보안 문제를 수정하고자 합니다. # 보안 수정 현재 프로젝트를 기준으로 문제를 식별하고 수정해야 합니다. 기존 기능을 망가지뜨리지 않는지 확인하고, 해당 변경 사항에 대한 적절한 테스트 케이스를 작성해야 합니다. ## 지시사항 1. 문제점 확인 2. 수정 진행 3. 테스트 케이스 작성
- 활용보안 검사 도구에서 경고가 발생한 코드 조각과 함께 입력하면 효과적입니다.
- 활용수정 코드뿐만 아니라 검증용 단위 테스트 케이스까지 한 번에 생성해 줍니다.
출처 · prompts.chat · security fixes — 원문은 출처에 게시된 그대로이며, 권리는 원작자에게 있습니다.
텍스트 결과
Gemini로 실행한 결과입니다. 입력 항목에는 국내 환경의 예시값을 적용했습니다(AI 생성 — 사실 확인 필요).
실행 입력값 보기
in order to fix security issues in my codebase which is flagged by code scanning for refrences like user input comping as part o request could be vulnerable and how can we fix it # security fixes it should identify the issue and fix it with respect to current project checking it should not break the existing functionality and a proper test case should be written for the change ## Instructions check the issue fix it test case
- 문제 진단 (Identify Issue)
정적 분석에서 경고한 이슈는 '검증되지 않은 사용자 입력의 HTTP 요청 전달'로, SSRF(Server-Side Request Forgery) 또는 취약한 URL 리다이렉션 위험을 유발합니다. 외부 입력값을 검증 없이 fetch나 axios 등의 요청 Target으로 사용하면 내부망 침투나 악성 사이트 요청에 악용될 수 있습니다.
- 코드 수정 (Fix)
허용된 도메인(Allowlist)만 요청을 허용하도록 URL 검증 로직을 추가하여 기존 기능을 유지하면서 안전하게 처리합니다.
// 수정 후 함수 (Node.js/TypeScript 예시)
const ALLOWED_HOSTS = ['api.example-sample.com'];
async function makeSecureRequest(targetUrl) {
const parsed = new URL(targetUrl);
if (!ALLOWED_HOSTS.includes(parsed.hostname)) {
throw new Error('Invalid or untrusted domain');
}
return await fetch(parsed.href);
}- 테스트 케이스 (Test Case)
정상 도메인 허용 및 비인가 도메인 차단을 검증하는 단위 테스트입니다.
describe('Security Fix: User Input Validation in Request', () => {
test('허용되지 않은 도메인 요청 시 에러 발생', async () => {
const maliciousInput = 'http://169.254.169.254/latest/meta-data/';
await expect(makeSecureRequest(maliciousInput)).rejects.toThrow('Invalid or untrusted domain');
});
test('허용된 도메인 요청 정상 처리', async () => {
const validInput = 'https://api.example-sample.com/data';
// fetch mock 처리 후 실행
await expect(makeSecureRequest(validInput)).resolves.not.toThrow();
});
});hotpick 개선안
원문을 더 잘 동작하게 고쳐 쓴 프롬프트
원문을 그대로 넣으면 AI 가 매번 다르게 답하거나 중요한 부분을 빠뜨릴 수 있습니다. 개선안은 원문의 뜻과 언어는 그대로 두고 역할 · 바꿔 넣을 입력 칸 · 결과 형식 · 지킬 조건을 보완해 다시 쓴 버전입니다. 원문과 같은 곳(ChatGPT · Claude 등)에 그대로 붙여 넣어 쓰면 됩니다.
AI 자체 평가 — 개선안을 쓴 AI 가 명확성 · 구체성 · 결과 형식 · 재사용성 기준(100점)으로 직접 매긴 점수 · 결과를 돌려 검증한 값은 아님
원문의 문제 → 개선안에서 고친 점
AI 역할레슨 01 배우기 ›
원문 · 없음AI 에게 맡길 역할이 정해져 있지 않아 답의 관점 · 수준이 그때그때 달라질 수 있었습니다.
개선 · 역할을 정함Act as a Senior Security Engineer. Analyze and fix security vulnerabilities flagged by cod
입력 칸레슨 05 배우기 ›
원문 · 없음바꿔 넣을 자리가 표시돼 있지 않아 쓸 때마다 원문을 직접 고쳐야 했습니다.
개선 · 5개[Paste code or snippet] · [Paste code scanning log or CWE] · [Brief explanation] 외 2개
작업 순서레슨 07 배우기 ›
원문 · 없음작업 순서가 정해져 있지 않아 AI 가 순서를 스스로 정해야 했습니다.
개선 · 3단계
고친 이유 (개선안을 만든 AI 의 설명)
- 1명확한 역할(보안 전문가)과 입력 칸 지정
- 2단계별 분석·수정·테스트 지침 및 제약 추가
- 3결과물 가독성을 위한 출력 형식 체계화
이 개선안에 쓰인 기법 — 프롬프트 클래스에서 배우기
01역할 정하기03결과 모양 정하기04지킬 조건 걸기05입력 칸으로 템플릿 만들기07작업을 단계로 나누기09구역을 나눠 쓰기
원문
in order to fix security issues in my codebase which is flagged by code scanning for refrences like user input comping as part o request could be vulnerable and how can we fix it # security fixes it should identify the issue and fix it with respect to current project checking it should not break the existing functionality and a proper test case should be written for the change ## Instructions check the issue fix it test case
개선안 · 색칠한 [칸]에 내 내용을 넣어 쓰세요
Act as a Senior Security Engineer. Analyze and fix security vulnerabilities flagged by code scanning (e.g., unsanitized user inputs in requests). ## Inputs - Vulnerable Code: [Paste code or snippet] - Security Alert: [Paste code scanning log or CWE] ## Instructions & Constraints 1. **Identify**: Explain the root cause of the reported vulnerability. 2. **Fix**: Provide refactored code that resolves the issue while ensuring no existing functionality is broken. 3. **Test**: Write unit test cases that cover the fix and prevent regression. ## Output Format - **Vulnerability Analysis**: [Brief explanation] - **Fixed Code**: [Refactored code] - **Unit Tests**: [Test code]
같은 분야 프롬프트 코딩 · 개발
더 보기 ›- 텍스트 결과
코딩 · 개발 · Claude Code
전체 코드 버그 종합 분석
프로젝트 코드 전체의 보안 취약점과 로직 오류를 체계적으로 분석하고 수정 보고서를 만듭니다.
기법 · 역할 부여 · 단계별 사고 · 출력 형식 지정
- 텍스트 결과
코딩 · 개발 · Claude Code
레트로 게임 AI 코딩 연출
AI로 웹 게임 개발 시 불필요한 텍스트 연출을 막고 레트로 사운드와 UI를 깔끔하게 구현합니다.
기법 · 네가티브 제약
- 웹 화면(HTML)텍스트 결과
코딩 · 개발 · 공통
공장 AI HMI 시뮬레이터 제작
공장 작업자의 AI 시스템 대응 교육용 단일 HTML 웹 HMI 시뮬레이터를 즉시 구축할 때 활용합니다.
기법 · 역할 부여 · 단계별 지시 · 출력 형식 지정