Skip to content

[Fix] 취약점 파일 경로를 저장소 상대경로로 정규화 - #49

Merged
dldusgh318 merged 2 commits into
SeCause:developfrom
dldusgh318:fix/46-relative-paths
Oct 15, 2026
Merged

dldusgh318 merged 2 commits into
SeCause:developfrom
dldusgh318:fix/46-relative-paths

Conversation

@dldusgh318

@dldusgh318 dldusgh318 commented Oct 14, 2026 •

Copy link
Copy Markdown
Contributor

‼️ 관련 이슈

close #46


🔎 개요

취약점 filePath에 임시 clone 절대경로가 표시되는 문제를 수정합니다. clone root 기준 상대경로로 정규화한 뒤 중복 제거와 callback을 수행합니다.


📝 작업 내용

  • 저장소 내부 절대경로를 하위 디렉터리 구조를 보존한 상대경로로 변환합니다. 기존 상대경로, 한글/공백 파일명, dot/parent/separator도 처리합니다.
  • CodeQL SARIF의 상대 URI, 로컬 file URI, UTF-8 percent encoding과 명시적 uriBaseId/originalUriBaseIds를 해석합니다.
  • repo 밖 경로, traversal, 외부/깨진/루프 symlink와 잘못된 URI는 해당 finding만 경고 후 제외하고 정상 finding은 계속 처리합니다.
  • 동일 파일의 절대/상대경로가 dedup에서 병합되도록 정규화를 먼저 수행합니다.
  • 실제 Semgrep 1.180.0 CLI를 로컬 규칙으로 실행해 절대 target의 절대 path 출력과 repo cwd의 상대 path 출력을 검증했습니다.
  • 구현과 테스트를 두 커밋으로 분리했습니다. 저장소 문서는 추가하지 않았습니다.

👀 변경 사항

  • callback 필드/구조, message/evidence, scanner 실패 격리, 단일 RAG 이벤트 루프와 분석 순서는 유지합니다.
  • [Bug] 수정 코드에 일반 설명이 출력되는 문제 수정 #44 PR #47과 [Feat] 분석 단계별 진행률 callback 전송 #45 PR #48에는 경로 정규화 구현이 없어 중복 구현이나 필수 의존성은 없습니다.
  • #45와 analysis_job.py 정규화 호출 부근이 겹칩니다. 통합 시 repo_root=context.repo_path 전달과 진행률 처리를 함께 보존해야 합니다. 두 PR과 tests/jobs/test_analysis_job.py가 겹치므로 각 회귀 테스트를 함께 유지해야 합니다.
  • 기존 repository_files.file_path는 자동 변경되지 않습니다. BE가 종료된 analysisId의 callback을 무시하므로 같은 ID 재전송으로 갱신되지 않으며 새 분석으로 재분석해야 합니다. 과거 행 정리는 별도 매핑/FK/충돌 검토가 필요합니다. BE와 운영 DB는 수정하지 않았습니다.

📸 스크린샷 (Optional)

해당 없음. 화면 변경 없이 callback의 filePath를 수정합니다.


✅ 체크리스트

  • label, milestone, assignees, reviewers 등을 지정했습니다.
  • 성능 개선/최적화 관련 내용이 있는지 확인했습니다.
  • 변경 사항에 대한 테스트를 했습니다.
  • 테스트 시 사용한 로그를 삭제했습니다. (로그를 저장소에 추가하지 않음)

검증: unittest 전체 72개 통과(skip 없음), git diff --check 통과. 실제 외부 API/운영 서버/DB 호출 없이 검증했습니다. CodeQL은 SARIF fixture로 검증했으며 실제 CodeQL CLI 분석과 배포 후 API/화면 확인은 수행하지 않았습니다. Semgrep이 PATH에 없으면 CLI integration test만 skip됩니다.


💬 고민사항 및 리뷰 요구사항 (Optional)

  • 내부 symlink는 repo 링크 경로를 유지하고, symlink 뒤 parent 이동은 실제 target 기준으로 해석합니다. 잘못된 경로가 모두 제외되면 기존 빈 결과 완료 정책을 따르므로 경고 로그 확인이 필요합니다.
  • unknown/cyclic URI base, context 없는 상대 base, index-only artifact, 원격 authority, HTTP 등 다른 scheme, Windows drive/UNC, query/fragment, 잘못된 encoding은 지원하지 않고 해당 finding을 제외합니다. 임시 prefix나 암묵적인 source root를 추측해서 자르지 않습니다.
  • 배포 후 새 분석의 callback filePath와 상세 GET /api/repositories/{repositoryId}/analysis/issues/{analysisResultId}, 파일 목록/화면을 대조해 주세요. 기존 절대경로 조사에는 다음 read-only SQL을 사용할 수 있습니다. SQL은 실행하지 않았습니다.
SELECT repository_file_id, repository_id, file_path
FROM repository_files
WHERE file_path LIKE '/%'
   OR file_path LIKE 'file:%'
   OR file_path ~ '^[A-Za-z]:[/\\]'
ORDER BY repository_id, repository_file_id;

@coderabbitai

coderabbitai Bot commented Oct 14, 2026

Copy link
Copy Markdown

Warning

Review limit reached

You've used all free OSS reviews for now. Wait for the free limit to reset to keep reviewing this public repository.

Next included review available in 17 minutes.

Check out review usage here.

View limit details

Limit details: You’ve used the included review currently available.

Learn how review limits work.

Review configuration:

⚙️ Run configuration
  • Configuration used: Organization UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 51ae7621-232d-4764-84df-f102e147a337
📥 Commits

Reviewing files that changed from the base of the PR and between 69dfdaa and abfc0cf.

📒 Files selected for processing: 8
  • app/jobs/analysis_job.py
  • app/services/normalizer/finding_normalizer.py
  • app/services/normalizer/repository_path.py
  • app/services/scanner/codeql_sarif_parser.py
  • tests/jobs/test_analysis_job.py
  • tests/services/normalizer/test_repository_path.py
  • tests/services/scanner/test_codeql_sarif_parser.py
  • tests/services/scanner/test_semgrep_path_integration.py
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@boogiewooki02 boogiewooki02 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

고생하셨습니다!
코드리뷰 확인 부탁드려요~

def repository_relative_path(value: str, repo_root: str | Path) -> str:
if not value or "\x00" in value:
raise InvalidFindingPath("missing or invalid file path")
value = value.replace("\\", "/")

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

\를 전부 /로 바꾸면 Linux에서 파일명 자체에 \가 포함된 경우에도 경로가 변경됩니다. 따라서 실제 파일과 다른 위치를 가리킬 수 있을 것 같은데, 스캐너가 반환하는 경로 형식에 따라 변환 여부를 구분하면 어떨까요?

@dldusgh318
dldusgh318 merged commit a20c267 into SeCause:develop Oct 15, 2026
2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug] 취약점 파일 경로를 저장소 상대경로로 정규화

2 participants